-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
374 lines (310 loc) · 13.3 KB
/
main.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser # inbuilt - to acces the web browser
import os # inbuilt - to acces the installed applications in your pc
import random # inbuit
import pyautogui
import time
engine = pyttsx3.init('sapi5')
voices = engine.getProperty("voices")
engine.setProperty('voice', voices[0].id)
def speak(audio): # is function se ye bolega with a parameter audio
engine.say(audio)
engine.runAndWait()
def wishkr():
hour = int(datetime.datetime.now().hour) # 0-24 tak ka ghanta mil gaayega
if hour >= 0 and hour < 12:
speak("Good Morning!")
elif hour >= 12 and hour < 18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("I am Pappu Sir. Please tell me how may i help.")
def commandlo():
# ye user se microphone input leta hai aur output string k taur p deta hai
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening . . .")
r.pause_threshold = 1
# control daba ke pause_threshold p click kr aur saare try kr
# yaha control kr skte hain ki kitna tez bolo by increasing energy_threshold
audio = r.listen(source)
try:
# print("Ruk bhai recognize kr rha hu . . . .")
# speak("recognizing")
bola = r.recognize_google(audio, language='en-in')
print("U said : {} \n".format(bola))
except Exception as e:
print(e)
speak("please say again")
return "None"
return bola
if __name__ == "__main__":
wishkr()
while True:
bola = commandlo().lower()
# ab yaha se chalu hai main logics jo bhi input doge uske hisaab se ye kaam krega
if "wikipedia" in bola:
speak("wait . . . searching wikipedia ")
bola = bola.replace("wikipedia", "")
results = wikipedia.summary(bola, sentences=2)
# sentences = n *n numbers of senteces will be printed by the wikipedia
speak("According to wikipedia")
print(results)
speak(results)
elif "open facebook" in bola:
speak("opening boss")
pyautogui.hotkey('win', "1")
time.sleep(1)
pyautogui.click(206, 62)
pyautogui.hotkey("ctrl", 't')
pyautogui.typewrite("facebook.com")
pyautogui.press("enter")
elif "open youtube" in bola:
speak("okay boss ! opening youtube")
pyautogui.hotkey('win', "1")
time.sleep(2)
pyautogui.click(206, 62)
pyautogui.hotkey("ctrl", 't')
pyautogui.typewrite("youtube.com")
pyautogui.press("enter")
pyautogui.moveTo(576, 160, duration=1.5)
pyautogui.click()
speak("okay! boss what should i search for you on youtube")
prro = sr.Recognizer()
with sr.Microphone() as soorc:
print("Listening . . .")
prro.pause_threshold = 1
gopaudio = prro.listen(soorc)
try:
gopbola = prro.recognize_google(gopaudio, language='en-in')
except Exception as e:
speak("please say again")
pyautogui.typewrite(gopbola)
pyautogui.press("enter")
elif "open google" in bola:
speak("okay boss ! redirecting google")
pyautogui.hotkey('win', "1")
time.sleep(1)
pyautogui.click(206, 62)
pyautogui.hotkey("ctrl", 't')
pyautogui.typewrite("google.com")
pyautogui.press("enter")
pyautogui.moveTo(679, 499, duration=0.5)
pyautogui.click()
speak("okay! boss what should i search for you")
prr = sr.Recognizer()
with sr.Microphone() as sorc:
print("Listening . . .")
prr.pause_threshold = 1
goaudio = prr.listen(sorc)
try:
gobola = prr.recognize_google(goaudio, language='en-in')
except Exception as e:
speak("please say again")
pyautogui.typewrite(gobola)
pyautogui.press("enter")
elif "open stack overflow" in bola:
speak("okay boss ! initializing stackoverflow")
pyautogui.hotkey('win', "1")
time.sleep(1)
pyautogui.click(206, 62)
pyautogui.hotkey("ctrl", 't')
pyautogui.typewrite("stackoverflow.com")
pyautogui.press("enter")
elif "open music" in bola:
speak("okay boss ! getting some refreshing hits for you")
music_dir = "D:\\songs"
songs = os.listdir(music_dir)
# to generate random number isi k liye random library import kiya tha
k = random.randint(0, 638)
os.startfile(os.path.join(music_dir, songs[k]))
elif "play slow songs" in bola:
speak("okay boss ! getting some refreshing hits for you")
musicdir = "F:\\Qwaali"
sng = os.listdir(musicdir)
# to generate random number isi k liye random library import kiya tha
k = random.randint(0, 17)
os.startfile(os.path.join(musicdir, sng[k]))
pyautogui.moveTo(1798, 10, duration=0.2)
pyautogui.click()
elif "the time" in bola:
tm = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"boss ! the time is {tm}")
# aise path copy kr ke you can open many programs in your pc
elif "open code" in bola:
speak("okay boss ! initializing visual studio code")
cpath = 'C:\\Users\\Dell\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe'
os.startfile(cpath)
elif "open command" in bola:
speak("okay boss ! initializing command prompt")
cpath = "C:\\Users\\Dell\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\System Tools\\Command Prompt.lnk"
os.startfile(cpath)
elif "open file" in bola:
speak("okay boss ! initializing my pc")
pyautogui.hotkey('win', 'e')
elif "open settings" in bola:
speak("okay boss ! you are setting up")
pyautogui.hotkey('win', 'i')
elif "open control panel" in bola:
speak("okay boss ! initializing control panel")
cpath = "C:\\Users\\Dell\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\System Tools\\Control Panel.lnk"
os.startfile(cpath)
elif "take screenshot" in bola:
speak("okay boss ! snapping ")
pyautogui.hotkey('win', 'w')
elif "open chrome" in bola:
speak("okay boss ! initializing google chrome")
cpath = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome.lnk"
os.startfile(cpath)
pyautogui.moveTo(192, 64, duration=1)
pyautogui.click()
speak("Boss, what should i search for?")
rrr = sr.Recognizer()
with sr.Microphone() as srco:
print("Listening . . .")
rrr.pause_threshold = 1
gcsearch = rrr.listen(srco)
try:
gcbola = rrr.recognize_google(gcsearch, language='en-in')
except Exception as e:
speak("please say again")
pyautogui.typewrite(gcbola)
pyautogui.press("enter")
elif "open firefox" in bola:
speak("okay boss ! initializing mozzila firefox")
cpath = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Firefox.lnk"
os.startfile(cpath)
elif "open anydesk" in bola:
speak("okay boss ! initializing anydesk")
cpath = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\AnyDesk\\AnyDesk.lnk"
os.startfile(cpath)
elif "open downloads" in bola:
speak("okay boss ! opening downloads")
cpath = "C:\\Users\\Dell\\Downloads"
os.startfile(cpath)
elif "open start" in bola:
pyautogui.press('win')
elif "open recents" in bola:
pyautogui.hotkey('win', 'tab')
elif "open run" in bola:
pyautogui.hotkey('win', 'r')
elif "play music" in bola:
speak("revising some hits for you")
speak("boss from starting or just random")
rr = sr.Recognizer()
with sr.Microphone() as src:
print("Listening . . .")
rr.pause_threshold = 1
musicaudio = rr.listen(src)
try:
mbola = rr.recognize_google(musicaudio, language='en-in')
except Exception as e:
speak("please say again")
if "random" in mbola:
pyautogui.press('win')
pyautogui.moveTo(1734, 714, duration=0.5)
pyautogui.click(1734, 714)
pyautogui.moveTo(448, 173, duration=1.0)
pyautogui.click(448, 173)
pyautogui.moveTo(1798, 10, duration=0.2)
pyautogui.click()
elif "starting" in mbola:
pyautogui.press('win')
pyautogui.moveTo(1734, 714, duration=0.5)
pyautogui.click(1734, 714)
pyautogui.moveTo(621, 227, duration=1.5)
pyautogui.click(621, 227)
pyautogui.moveTo(1798, 10, duration=0.2)
pyautogui.click()
elif "pause music" in bola:
pyautogui.press('win')
pyautogui.moveTo(1734, 714, duration=0.5)
pyautogui.click(1734, 714)
pyautogui.moveTo(959, 1015, duration=1)
pyautogui.click(959, 1015)
pyautogui.moveTo(1798, 10, duration=0.2)
pyautogui.click()
elif "next music" in bola:
pyautogui.press('win')
pyautogui.moveTo(1734, 714, duration=0.5)
pyautogui.click(1734, 714)
pyautogui.moveTo(1014, 1012, duration=1)
pyautogui.click(1014, 1012)
pyautogui.moveTo(1798, 10, duration=0.2)
pyautogui.click()
elif "last music" in bola:
pyautogui.press('win')
pyautogui.moveTo(1734, 714, duration=0.5)
pyautogui.click(1734, 714)
pyautogui.moveTo(906, 1016, duration=1)
pyautogui.click(906, 1016)
pyautogui.moveTo(1798, 10, duration=0.2)
for i in range(2):
pyautogui.click()
elif "open notifications" in bola:
pyautogui.hotkey('win', 'a')
elif "minimise all" in bola:
pyautogui.hotkey('win', "d")
elif "how are you" in bola:
speak("Im fine as always, what about you boss.")
elif "you have girlfriend" in bola:
speak("no no no no bro im single, ha ha ha ")
elif "refresh" in bola:
pyautogui.hotkey('win', 'd')
for i in range(4):
pyautogui.rightClick()
pyautogui.move(10, 60)
pyautogui.click()
elif "close" in bola:
pyautogui.hotkey("alt", "F4")
elif "open twitter" in bola:
pyautogui.hotkey('win', "1")
time.sleep(1)
pyautogui.click(206, 62)
pyautogui.hotkey("ctrl", 't')
pyautogui.typewrite("twitter.com")
pyautogui.press("enter")
elif "open paint" in bola:
pyautogui.press('win')
time.sleep(1)
r = pyautogui.locateOnScreen(
"F:\\python coursera\\images to locate\\Untitled.png")
pyautogui.click(r)
elif "open new tab" in bola:
pyautogui.hotkey('ctrl', 't')
elif "open whatsapp" in bola:
pyautogui.hotkey('win', '2')
time.sleep(2)
speak(
"open whats app in your phone and scan the whats app web provided on the screen")
time.sleep(3)
speak("tell me now what to do next")
wrr = sr.Recognizer()
with sr.Microphone() as srwco:
print("Listening . . .")
wrr.pause_threshold = 1
ws = wrr.listen(srwco)
try:
wbola = wrr.recognize_google(ws, language='en-in')
except Exception as e:
speak("please say again")
if "show status" in wbola:
speak("opening status")
r = pyautogui.locateOnScreen(
"F:\\python coursera\\images to locate\\status.png")
pyautogui.click(r)
elif "logout WhatsApp" in wbola:
r = pyautogui.locateOnScreen(
"F:\\python coursera\\images to locate\\optionwhats.png")
pyautogui.click(r)
time.sleep(0.5)
r = pyautogui.locateOnScreen(
"F:\\python coursera\\images to locate\\logout whats.png")
pyautogui.click(r)
speak("logging out of the whatsapp")
elif "shutdown" in bola:
speak("okay! boss im logging out")
quit()