-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassistant.py
178 lines (168 loc) · 6.22 KB
/
assistant.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import pyttsx3
import datetime
import wikipedia as wiki
import speech_recognition as sr
import smtplib
import os
import webbrowser
import time
import pyjokes as pj
engine=pyttsx3.init()
voices=engine.getProperty('voices')
def audio(audio):
engine.say(audio,voices[1].id)
engine.runAndWait()
def _time():
now=datetime.datetime.now().strftime("%H:%M:%S")
audio("Hey the time is ")
audio(now)
def _date():
year=datetime.datetime.now().year
month=datetime.datetime.now().month
date=datetime.datetime.now().day
audio("Hey there today is")
audio(date)
audio(month)
audio(year)
def _welcomeFunction():
audio("Welcome Back Priyadarshan")
hour=datetime.datetime.now().hour
if hour<12:
audio("Good Morning Sir!")
elif hour>=12 and hour<16:
audio("Good afternoon Sir!")
elif hour>=16 and hour<21:
audio("Good evening Sir!")
else:
audio("Good night sir!")
def _takeCommand():
r=sr.Recognizer()
with sr.Microphone() as source:
print("Listning....")
r.pause_threshold=2
audio=r.listen(source)
try:
print("Recognizing...")
query=r.recognize_google(audio,language='en-In')
print(query)
except Exception as e:
print(e)
print("Did't understand you...\nPlease say again...")
return "NONE"
return query
def _sendEmail(to,context):
server=smtplib.SMTP("smtp.gmail.com",587)
server.ehlo()#server request
server.starttls()#server establishment
server.login("EnterYourEmailId","EnterYourPassWord")
server.sendmail("priyadarshanghosh26@gmail.com",to,context)
server.close()
def _jokes():
print(pj.get_joke())
audio(pj.get_joke())
if __name__ == '__main__':
_welcomeFunction()
while True:
spech=_takeCommand().lower()
if 'time' in spech:
_time()
elif 'date' in spech:
_date()
elif 'wikipedia'in spech:
# audio("Searching...")
print("Searching...")
filter=spech.replace("wikipedia"," ")
try:
mainQuery= wiki.summary(filter,sentences=5)
audio("According to wikipedia")
print(mainQuery)
audio(mainQuery)
except:
audio("Your search is not aviable in wikipedia.Please say again")
_takeCommand()
elif 'send email' in spech:
try:
audio("What you want to say speak ")
#print("What you want to say speak ")
content=_takeCommand()
audio("Are you sure what you what to say")
condirmation =_takeCommand()
if (condirmation=='yes'):
pass
else:
_sendEmail(to,content)
audio("Who is the receiver of the email")
receiver=input("Enter receiver emailId: ")
to=receiver
_sendEmail(to,content)
audio("Priyadarshan your email to email address %s whose content was"%receiver)
audio(content)
audio("Email has been sent")
print("Done")
except Exception as e:
audio("Unable to send your email")
print(e)
elif 'search websites' in spech:
audio("What should I search for")
#print("What to search for?")
webdriver = "C:/Program Files/Google/Chrome/Application/chrome.exe %s"
search = _takeCommand().lower()
webbrowser.get(webdriver).open_new_tab(search+'.com')
elif 'search on youtube' in spech:
audio("What do you want to watch")
yout=_takeCommand().lower()
audio("Opening %s on youtube"%yout)
webbrowser.open("https://www.youtube.com/results?search_query=%s"%yout)
elif 'search' in spech:
audio("What do you want to search")
google=_takeCommand().lower()
try:
audio("Opening Google for %s"%google)
webbrowser.open("https://www.google.com/search?q=%s"%google)
except:
audio("There was an unexpected error in google")
audio("Opening Bing for %s" % google)
webbrowser.open("https://https://www.bing.com/search?q=%s"%google)
elif 'joke' in spech:
_jokes()
elif 'word' in spech:
audio("opening word.Please wait")
word=r'C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE'
os.startfile(word)
elif 'powerpoint' in spech:
audio("opening Microsoft Powerpoint. Please wait")
powerpoint=r'C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE'
os.startfile(powerpoint)
elif 'excel' in spech:
audio("opening Microsoft Excel. Please wait")
powerpoint = r'C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE'
os.startfile(powerpoint)
elif 'take a note' in spech:
audio("What should I note Priyadarshan?")
print("What should I note Priyadarshan?")
note=_takeCommand()
ffile=open("new.txt",'w')
audio("Should I add date and time with it")
time=_takeCommand()
if "yes" in time or "yup" in time or "yo" in time:
startTime=datetime.datetime.now().strftime("%H:%M:%S")
ffile.write(startTime)
ffile.write(" :- ")
ffile.write(note)
audio("Done")
else:
ffile.write(note)
audio("Done")
elif "read the note" in spech:
audio("Sure Priyadarshan;")
ffile=open("new.txt",'r')
print(ffile.read())
audio(ffile.read())
elif "pause" in spech or "hault" in spech or "sleep" in spech:
audio("you want to pause the program for how many second?")
pause=int(input("Enter time in seconds"))
audio("Proagramming puasing for %d seconds"%pause)
time.sleep(pause)
elif 'shutdown' in spech or 'exit' in spech or 'quit' in spech:
audio("Program shutting down")
quit()