1+ import pyttsx3
2+ import webbrowser
3+ import smtplib
4+ import random
5+ import speech_recognition as sr
6+ import wikipedia
7+ import datetime
8+ import os
9+ import sys
10+
11+
12+
13+ engine = pyttsx3 .init ('sapi5' )
14+ voices = engine .getProperty ('voices' )
15+ engine .setProperty ('voices' ,voices [0 ].id )
16+
17+ def speak (audio ):
18+ engine .say (audio )
19+ engine .runAndWait ()
20+
21+
22+ def wishme ():
23+ time = int (datetime .datetime .now ().hour )
24+ if time >= 0 and time < 12 :
25+ speak ("good morning sir" )
26+ elif time >= 12 and time < 18 :
27+ speak ("good afternoon sir" )
28+ else :
29+ speak ("good evening sir" )
30+ speak ( "I am your virtual assistant jarvis . please tell me how may i help you" )
31+
32+
33+ def takeCommand ():
34+ r = sr .Recognizer ()
35+ with sr .Microphone () as source :
36+ print ("listening....." )
37+ r .pause_threshold = 1
38+ r .adjust_for_ambient_noise (source , duration = 5 )
39+ audio = r .listen (source )
40+
41+ try :
42+ print ("Recognizing....." )
43+ stat = r .recognize_google (audio , language = "en-in" )
44+ print (f"User said:> { stat } \n " )
45+
46+ except Exception as e :
47+ #print(e)
48+
49+ print ("Say that again please!!" )
50+ return "None"
51+ return stat
52+ def sendemail (to ,content ):
53+ e_mail = lib .smtplib .SMTP ('smtp.gmail.com' ,587 )
54+ e_mail .ehlo ()
55+ e_mail .starttls ()
56+ e_mail .login ('tggv9986@gmail.com' , 'mypass' )
57+ e_mail .sendemail ('tggv9986@gmail.com' ,to ,content )
58+ e_mail .close ()
59+ if __name__ == "__main__" :
60+ wishme ()
61+ while True :
62+ stat = takeCommand ().lower ()
63+
64+ if 'wikipedia' in stat :
65+ speak ('searching wikipedia' )
66+ stat = stat .replace ('wikipedia' , "" )
67+ results = wikipedia .summary (stat , sentences = 3 )
68+ speak ('According to wikipedia' )
69+ print (results )
70+ speak (results )
71+
72+ elif 'open youtube' in stat :
73+ speak ('okay' )
74+ webbrowser .open ('youtube.com' )
75+
76+ elif 'my youtube channel' in stat :
77+ speak ("okay" )
78+ webbrowser .open ('youtube.com/c/thegreatgrandvideos' )
79+
80+ elif 'google classroom' in stat :
81+ speak ("okay" )
82+ webbrowser .open ('https://classroom.google.com/c/NjQzNTUyODU0MTFa' )
83+
84+ elif 'google' in stat :
85+ speak ("okay" )
86+ webbrowser .open ('www.google.co.in' )
87+
88+ elif 'play music' in stat :
89+ musicfile = '"E:\\ YouTube\\ NCS Music & Sound Effect'
90+ songs = os .listdir (musicfile )
91+ print (songs )
92+ os .startfile (os .path .join (musicfile ,songs [0 ]))
93+
94+ elif 'time' in stat :
95+ ntime = datetime .datetime ().strftime ('%H:%M:%S' )
96+
97+ elif "open vs code" in stat :
98+ vscode = 'C:\\ Users\\ ABHISHEK RANJAN\\ AppData\\ Roaming\\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ Visual Studio Code\\ Visual Studio Code.lnk'
99+ os .startfile (vscode )
100+
101+ elif 'open filmora' in stat :
102+ filmora = "C:\\ ProgramData\\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ Wondershare\\ Filmora9\\ Wondershare Filmora9.lnk"
103+ os .startfile (filmora )
104+
105+ elif 'open zoom' in stat :
106+ zoomm = "C:\\ Users\\ ABHISHEK RANJAN\\ AppData\\ Roaming\\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ Zoom\\ Start Zoom.lnk"
107+ os .startfile (zoomm )
108+
109+ elif 'open droidcam' in stat :
110+ d_cam = "C:\\ Users\\ ABHISHEK RANJAN\\ AppData\\ Roaming\\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ DroidCam\\ DroidCam Client.lnk"
111+ os .startfile (d_cam )
112+
113+ elif "what's up" in stat or 'how are you' in stat :
114+ stMsgs = ['Just doing my thing!' , 'I am fine!' , 'I am nice and full of energy' ]
115+ speak (random .choice (stMsgs ))
116+
117+ elif 'nothing' in stat or 'abort' in stat or 'stop' in stat :
118+ speak ('okay' )
119+ speak ('Bye Sir, have a good day.' )
120+ sys .exit ()
121+
122+ elif 'hello' in stat :
123+ speak ('Hello Sir' )
124+
125+
126+ elif 'email to ashutosh' in stat :
127+ try :
128+ speak ("what should i mail" )
129+ mes = takeCommand ()
130+ to = 'ashuranjan567@gmail.com'
131+ sendemail (to , mes )
132+ except Exception as e :
133+ #print(e)
134+ speak ("sorry sir email has not been send i committed a mistake" )
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
0 commit comments