-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassistant.py
298 lines (273 loc) · 10.7 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import pyttsx3
import speech_recognition as sr
import datetime
from datetime import date
import calendar
import time
import math
import wikipedia
import webbrowser
import os
import smtplib
# import winsound
import pyautogui
from tkinter import *
from playsound import playsound
import subprocess
import pywhatkit
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Catching your words....")
r.pause_threshold = 0.5
audio = r.listen(source)
try:
print("Got it...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print("sorry can you repeat...")
return "None"
return query
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
speak("Good Morning!")
elif hour >= 12 and hour < 18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("Hello den this side, how can i help you")
def brightness():
try:
query = takeCommand().lower()
if '25' in query:
pyautogui.moveTo(1880, 1050)
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(1610, 960)
pyautogui.click()
pyautogui.moveTo(1880, 1050)
pyautogui.click()
speak('If you again want to change brihtness, say, change brightness')
elif '50' in query:
pyautogui.moveTo(1880, 1050)
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(1684, 960)
pyautogui.click()
pyautogui.moveTo(1880, 1050)
pyautogui.click()
speak('If you again want to change brihtness, say, change brightness')
elif '75' in query:
pyautogui.moveTo(1880, 1050)
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(1758, 960)
pyautogui.click()
pyautogui.moveTo(1880, 1050)
pyautogui.click()
speak('If you again want to change brihtness, say, change brightness')
elif '100' in query or 'full' in query:
pyautogui.moveTo(1880, 1050)
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(1835, 960)
pyautogui.click()
pyautogui.moveTo(1880, 1050)
pyautogui.click()
speak('If you again want to change brihtness, say, change brightness')
else:
speak('Please select 25, 50, 75 or 100....... Say again.')
brightness()
except:
speak('Something went wrong')
with open ('bright.txt','w') as f:
f.write(query+ "\n")
def assisrun():
wishMe()
while True:
query = takeCommand().lower()
if 'who is' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
elif 'open youtube' in query:
webbrowser.open("https://youtube.com")
speak("ok opening youtube")
break
elif 'open Amazon Prime' in query or 'open prime' in query:
webbrowser.open("https://primevideo.com")
speak('ok opening prime video')
break
elif 'open hotstar' in query:
webbrowser.open("https://hotstar.com")
speak('ok opening hotstar')
break
elif 'open google' in query:
webbrowser.open("https://google.com")
break
elif 'open netflix' in query:
webbrowser.open('https://www.netflix.com/in/')
speak('ok opening netflix')
break
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")
elif 'whats the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")
elif "den" in query or "hi there" in query:
wishMe()
speak("den in your service")
elif 'how are you' in query:
speak("I am fine, Thank you")
speak("How are you, Sir")
elif 'fine' in query or "good" in query:
speak("It's good to know that your fine")
elif "who made you" in query or "who created you" in query:
speak("I have been created by Universe.")
elif 'play' in query:
song = query.replace('play', '')
speak('playing' + song)
pywhatkit.playonyt(song)
break
elif 'stop' in query:
speak("thank you for using den")
break
elif 'ok stop' in query:
speak("thank you for using den")
break
elif 'terminate' in query:
speak("thank you for using den")
break
elif 'bye' in query:
speak("Bye sir")
break
elif 'calculat' in query:
os.system('calc.exe')
break
elif 'add' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open my calculator.')
elif 'ad' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open my calculator.')
elif '+' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open calculator.')
elif 'plus' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open my calculator.')
elif 'subtract' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open my calculator.')
elif 'minus' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open my calculator.')
elif 'multipl' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open my calculator.')
elif ' x ' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open calculator.')
elif 'slash' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open calculator.')
elif '/' in query:
speak(
'If you want to do any mathematical calculation then give me a command to open calculator.')
elif ('increase' in query or 'decrease' in query or 'change' in query or 'minimize' in query or 'maximize' in query) and 'brightness' in query:
speak('At what percent should I kept the brightness, 25, 50, 75 or 100?')
brightness()
elif 'open map' in query or ('let' in query and 'map' in query and 'open' in query):
speak('ok opening maps.')
webbrowser.open('https://www.google.com/maps')
break
elif 'google maps' in query or ('let' in query and 'map' in query and 'open' in query):
speak('ok opening maps.')
webbrowser.open('https://www.google.com/maps')
break
elif 'news' in query:
webbrowser.open('https://www.bbc.com/news/world/asia/india')
break
elif 'online shop' in query or (('can' in query or 'want' in query or 'do' in query or 'could' in query) and 'shop' in query) or ('let' in query and 'shop' in query):
speak(
'From which online shopping website, you want to shop? Amazon or flipkart?')
query = takeCommand().lower()
if 'amazon' in query:
speak('ok opening amazon')
webbrowser.open('https://www.amazon.in')
break
elif 'flip' in query:
webbrowser.open('https://www.flipkart.com')
break
else:
speak(
'Sorry sir, the website are you talking about is new to me.')
break
elif 'dictionary' in query:
webbrowser.open('https://www.dictionary.com')
time.sleep(3)
speak('Enter the word, in the search bar of the dictionary, whose defination or synonyms you want to know')
break
elif 'cabs' in query or (('can' in query or 'want' in query or 'do' in query or 'could' in query) and 'taxi' in query):
speak(
'From which service do you like to get a cab.')
query = takeCommand().lower()
if 'ola' in query:
speak('ok opening ola')
webbrowser.open('https://www.olacabs.com')
break
elif 'uber' in query:
speak('ok opening uber')
webbrowser.open('https://www.uber.com')
break
elif 'rapido' in query:
speak('ok opening rapido')
webbrowser.open('https://www.rapido.bike/')
break
else:
speak(
'Sorry sir, the website are you talking about is new to me.')
break
elif 'food' in query or (('can' in query or 'want' in query or 'do' in query or 'could' in query) and 'food' in query) or ('hungry' in query):
speak(
'from which platform do you like to get some food.')
query = takeCommand().lower()
if 'swiggy' in query:
speak('ok opening swiggy')
webbrowser.open('https://www.swiggy.com')
break
elif 'zomato' in query:
speak('ok opening zomato')
webbrowser.open('https://www.zomato.com')
break
else:
speak(
'Sorry sir, the website are you talking about is new to me.')
break
elif 'open facebook' in query:
webbrowser.open("https://www.facebook.com")
speak('ok opening facebook')
break
elif 'open instagram' in query:
webbrowser.open("https://www.instagram.com")
speak('ok opening instagram')
break
elif 'open twitter' in query:
webbrowser.open("https://www.twitter.com")
speak('ok opening twitter')
break
else:
with open ('extra.txt','w') as f:
f.write(query+ "\n")