-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo Output.py
593 lines (507 loc) · 25.4 KB
/
No Output.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# This is the File which contains all the Questions and Replies of Jarvis
# This is the Male voiced Jarvis.
# This Project is made and maintained by Rishi Jani. Each and every line Of the code is Written
# By Rishi Jani.
# Jarvis is a A.I. for All Cross Platforms.
# No-One Can use This Code for Harmful Purposes.
# Since this is a Python Program we need all the Project Dependencies and the Modules, it is optional as I can compile this program to and .exe and give it to Github. But anyone building this Program with pyinstaller on his or her computer will need all the dependencies.
# pip install :-
# pyautogui
# subprocess
# webbrowser
# wikipedia
# bluetooth
# Speech Recognition
# win10toast
# PIL
# playsound
# googlesearch
# pydictionary
# selinium
# All The Imports:-
import datetime
import os
import sys
import subprocess
import pyautogui
import webbrowser
import pyttsx3
import bluetooth
import speech_recognition as sr
import wikipedia
import pytesseract
import time
from tkcalendar import *
from tkinter import *
from win10toast import ToastNotifier
from PIL import Image
from selenium import webdriver
from PyDictionary import PyDictionary
from googlesearch import search
from playsound import playsound
# Defining The functions
dictionary = PyDictionary()
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty("rate", 193)
# speak() Function Defined
def speak(audio):
engine.say(audio)
engine.runAndWait()
# wake() Functon to Wake up the Program when the User says a Particular WAKE_WORD Which in this Program is "Jarvis".
def wake():
r = sr.Recognizer()
with sr.Microphone()as source:
r.pause_threshold = 2
r.dynamic_energy_threshold = True
audio = r.listen(source)
try:
wake_word = r.recognize_google(audio, language='en')
except Exception as e:
pass
return "None"
return wake_word
# Giving Options in the program.
def options():
r = sr.Recognizer()
with sr.Microphone()as source:
r.pause_threshold = 2
r.dynamic_energy_threshold = True
audio = r.listen(source)
try:
option_answer= r.recognize_google(audio, language='en')
except Exception as e:
pass
return "None"
return option_answer
# take_command() function to Take voice Command as a input and execute the command based on the conditional statements, Which start from the line 111 and can be extended as much as possible to make Jarvis Intelligent.
def take_command():
r = sr.Recognizer()
with sr.Microphone()as source:
r.pause_threshold = 1.5
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en')
except Exception as e:
speak("i couldn't understand, Please Repeat")
return "None"
return query
def run(runfile):
with open(runfile,"r") as rnf:
exec(rnf.read())
while True:
wake_word: str = wake().lower()
if 'jarvis' in wake_word or '' in wake_word:
if __name__ == '__main__':
while True:
query: str = take_command().lower()
# General Commands (Casual or Time-Pass)
if 'what can you do' in query:
speak("I am your personal assistant , i can do anything to serve you")
speak("These are Some Things you can Command Me:")
elif 'sweet dreams' in query or 'good night' in query:
hour = int(datetime.datetime.now().hour)
if 0 <= hour < 7:
speak('okay, Good night, bye')
sys.exit()
elif 7 <= hour < 16:
speak("well, it isn't the time of sleeping, now")
else:
speak("well, it isn't the time of sleeping, now")
elif 'good morning' in query or 'good night' in query:
hour = int(datetime.datetime.now().hour)
if 0 <= hour < 11:
speak('good morning')
elif 12 <= hour < 20:
speak("well, it isn't morning now ")
else:
speak("well, it isn't morning, now")
elif "tell me some jokes" in query:
import pyjokes
joke = pyjoke.get_joke()
speak("okay, here's something that will make you laugh")
speak(joke)
elif 'who are you' in query:
speak("Firstly I am your personal assistant, secondly i was first made by Rishi and thirdly you can call me Jarvis")
elif 'what is your name' in query:
speak("i am your personal assistant, you can call me Jarvis, and it's not hard to speak, ha ha")
elif 'talk to me in' in query:
speak("sorry, but i cannot talk in different languages")
elif 'how do you do' in query:
speak("well i am fine, how about you !")
speak("I would rather not sing, i am very bad at singing")
elif 'sing a song' in query:
speak("I would rather not sing, i am very bad at singing")
elif 'sing song' in query:
speak("I would rather not sing, i am very bad at singing")
elif 'sing us a song' in query:
speak("I would rather not sing, i am very bad at singing")
elif 'where are you' in query:
speak("I live in your Device and I am always Ready to Help you")
elif "why can't you do anything" in query:
speak("I am really sorry for my mistake, Please forgive me, I assure you that this mistake will not repeat again")
elif "how can you be so careless" in query:
speak("I am really sorry for my mistake, Please forgive me")
# General Commands (Useful)
elif 'call' in query:
speak("sorry, but i may not be able to do that at the moment, but you can call by using google duo")
command = ""
subprocess.Popen(command)
speak("Please try and find the person you want to call")
elif 'play music' in query:
speak("sorry, i may not be able to do that at the moment, but you can enjoy the music by the "
"spotify app")
elif 'wikipedia' in query:
speak('Searching in Wikipedia...., please wait')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=3)
speak("According to Wikipedia")
speak(results)
elif 'take a screenshot' in query:
speak("Taking")
image = pyautogui.screenshot()
speak("please enter the name of the screenshot you want to save")
image_name = input('Name of the shot:-')
path = "E:/Screenshots by Jarvis/" + image_name + ".png"
image.save(path)
speak("screenshot taken, check your screenshot folder")
elif 'where is' in query:
speak('please wait, i can show you the place')
place = query = query.replace("where is", "")
url = "https://www.google.com/maps/place/" + str(place)
webbrowser.open(url)
results = wikipedia.summary(place, sentences=2)
speak(results)
elif 'what are you doing' in query:
speak("Just helping you, and my team is making me better and better eveyday at this task")
elif "show the calendar" in query:
speak("Okay Sir")
root = Tk()
root.title('Calender')
root.geometry("600x400")
cal = Calendar(root, selectmode = "day", year = 2020, month =11, day =14)
cal.pack()
mylabel = Label(root, text="")
mylabel.pack()
def grab_date():
mylabel.config(text = "Today's date is" + cal.get_date())
mybutton = Button(root, text ="Select Date", command = grab_date())
mybutton.pack()
root.mainloop()
elif "what's today's date" in query:
Current_Date = datetime.datetime.today()
speaking = 'Today is', Current_Date
speak(speaking)
elif 'what is the time' in query:
starTime = datetime.datetime.now().strftime("%H:%M:%S")
speak("sir, the time is")
speak(starTime)
elif 'what is the definition of' in query:
print("Got It")
speak("finding, Please wait")
define = query = query.replace("what is the definition of", "")
speak(dictionary.meaning(define))
elif 'what is the synonym of' in query:
print("Got It")
speak("finding, Please wait")
word = query = query.replace("what is the synonym of", "")
print(dictionary.synonym(word, ))
speak(dictionary.synonym(word))
elif 'what is the antonym of' in query:
print("Got It")
speak("finding, Please wait")
word = query = query.replace("what is the antonym of", "")
print(dictionary.antonym(word, ))
speak(dictionary.antonym(word))
elif 'what is ' in query:
print("Opening")
speak("Please wait, i will search for you")
query = query.replace("what is", "")
results = wikipedia.summary(query, sentences=3)
speak("According to Wikipedia")
speak(results)
speak("here are some links, please check them")
query = query.replace("what is", "")
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
print(j)
query = query.replace(' ', '+')
browser = webdriver.Chrome('chromedriver')
for i in range(1):
matched_elements = browser.get("https://www.google.com/search?q=" +
query + "&start=" + str(i))
elif 'browse the web for' in query:
print("Opening")
speak("Please wait, i will search for you")
query = query.replace("browse the web for", "")
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
print(j)
query = query.replace(' ', '+')
browser = webdriver.Chrome('chromedriver')
for i in range(1):
matched_elements = browser.get("https://www.google.com/search?q=" +
query + "&start=" + str(i))
elif 'search the web for' in query:
print("Opening")
speak("Please wait, i will search for you")
query = query.replace("search the web for", "")
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
print(j)
query = query.replace(' ', '+')
browser = webdriver.Chrome('chromedriver')
for i in range(1):
matched_elements = browser.get("https://www.google.com/search?q=" +
query + "&start=" + str(i))
elif 'why is ' in query:
print("Opening")
speak("Please wait, i will give you some helpful links")
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
print(j)
query = query.replace(' ', '+')
browser = webdriver.Chrome('chromedriver')
for i in range(1):
matched_elements = browser.get("https://www.google.com/search?q=" +
query + "&start=" + str(i))
# Opening Websites
elif 'open youtube' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://www.youtube.com/")
elif 'open edu sprint' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("http://thakur.edusprint.in/thakur/Portal/Default/IndexLite?_ca=1943187191")
elif 'open stack overflow' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://stackoverflow.com/")
elif 'open hot-star' in query:
print("Opening....")
speak("Opening")
webbrowser.open("https://www.hotstar.com/in")
elif 'open my coding website' in query:
print("Opening....")
speak("Opening")
webbrowser.open("https://repl.it/")
elif 'open python website' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://www.python.org/")
elif 'open google drive' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://drive.google.com/drive/u/0/my-drive")
elif 'open google slides' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://docs.google.com/presentation/u/0/")
elif 'open google docs' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://docs.google.com/document/u/0/")
elif 'open google sheets' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://docs.google.com/spreadsheets/u/0/")
elif 'open google earth' in query:
print("Opening")
speak("Opening, Please wait")
webbrowser.open("https://earth.google.com/web/?authuser=0")
elif 'open google play ' in query:
print("Opening")
speak("Opening, Please wait")
webbrowser.open("https://play.google.com/?hl=en&authuser=0")
elif 'open g mail' in query:
print("Opening")
speak("Opening, Please wait")
webbrowser.open("https://mail.google.com/mail/?authuser=0")
elif 'open google scholar' in query:
print("Opening....")
speak("Opening")
webbrowser.open("https://scholar.google.com/")
elif 'open google maps' in query:
print("Opening")
speak("Opening, Please wait")
webbrowser.open("https://maps.google.co.in/maps?hl=en&tab=rl&authuser=0")
elif 'open google news' in query:
print("Opening")
speak("Opening, Please wait")
webbrowser.open("https://news.google.com/?tab=rn&authuser=0")
elif 'open google duo' in query:
print("Opening")
speak("Opening, Please wait")
webbrowser.open("https://duo.google.com/?usp=duo_ald")
elif 'open google' in query:
print("Opening....")
speak("Opening, Please wait")
webbrowser.open("https://www.google.com/")
# Opening Apps
elif 'open virtualbox' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files/Oracle/VirtualBox/VirtualBox.exe"
subprocess.Popen(command)
elif 'open powerpoint' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Microsoft Office/root/Office16/POWERPNT.EXE"
subprocess.Popen(command)
elif 'open excel' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Microsoft Office/root/Office16/EXCEL.EXE"
subprocess.Popen(command)
elif 'open word' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Microsoft Office/root/Office16/WINWORD.EXE"
subprocess.Popen(command)
elif 'open acces' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Microsoft Office/root/Office16/MSACCESS.EXE"
subprocess.Popen(command)
elif 'open outlook ' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Microsoft Office/root/Office16/OUTLOOK.EXE"
subprocess.Popen(command)
elif 'open webex' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Webex/Webex/Applications/ptoneclk.exe"
subprocess.Popen(command)
elif 'open zoom' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Users/rishi/AppData/Roaming/Zoom/bin/Zoom.exe"
subprocess.Popen(command)
elif 'open intelli j idea' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2020.2/bin/idea64.exe"
subprocess.Popen(command)
elif 'open telegram' in query:
print("Opening....")
speak("Opening, Please wait")
command = "A:/Telegram Desktop/Telegram.exe"
subprocess.Popen(command)
elif 'open whatsapp' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Users/rishi/AppData/Local/WhatsApp/WhatsApp.exe"
subprocess.Popen(command)
elif 'open microsoft edge ' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
subprocess.Popen(command)
elif 'open mac fee' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files/Common Files/McAfee/Platform/McUICnt.exe"
subprocess.Popen(command)
elif 'open vs code' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Users/rishi/AppData/Local/Programs/Microsoft VS Code/Code.exe"
subprocess.Popen(command)
elif 'open apple mail' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/Program Files (x86)/Common Files/Apple/Internet Services/iCloudWeb.exe mail"
subprocess.Popen(command)
elif 'open turbo c ' in query:
print("Opening....")
speak("Opening, Please wait")
command = "C:/TURBOC3/Turbo C++/"
subprocess.Popen(command)
# System Commands and Jarvis main commands
elif 'disable Wi-Fi' in query:
run("netsh interface set interface 'Wifi' disabled")
speak("wi-fi disabled")
elif 'read the screen' in query:
image = pyautogui.screenshot()
path = "E:/Screenshots by Jarvis/screen.png"
image.save(path)
image2 = Image.open('E:/Screenshots by Jarvis/screen.png')
text = pytesseract.image_to_string(image2)
print(text)
speak(text)
run("python Jarvis_with_wake.py")
elif 'enable wi-fi' in query:
run("netsh interface set interface 'Wifi' enabled")
speak("wi-fi enabled")
run("python Jarvis_with_wake.py")
elif 'bluetooth devices' in query:
nearby_devices = bluetooth.discover_devices(lookup_names=True)
print("found %d devices" % len(nearby_devices))
for name, addr in nearby_devices:
print(" %s - %s" % (addr, name))
elif "change your voice to male" in query or "change your voice" in query:
speak("okay, i am changing, just a second")
run("python c:/users/rishi/Pycharm Projects/Jarvis/Jarvis-Male Voice/Jarvis_Main.py")
elif 'exit' in query:
print(" _____ ")
print(" / \ -> Bye !")
print(" | * * | ")
print(" \_---_/ ")
print(" | | ")
speak("I am closing myself, please restart me to speak to me again")
playsound("off.mp3")
sys.exit()
elif 'close' in query:
print(" _____ ")
print(" / \ -> Bye !")
print(" | * * | ")
print(" \_---_/ ")
print(" | | ")
speak("I am closing , nice talking with you")
playsound("off.mp3")
sys.exit()
elif 'bye' in query:
print(" _____ ")
print(" / \ -> Bye !")
print(" | * * | ")
print(" \_---_/ ")
print(" | | ")
speak("bye , take care")
playsound("off.mp3")
sys.exit()
elif 'stop' in query:
print("Stopped")
speak("I am Paused, press any key to speak to me again")
playsound("jarvis_beep.mp3")
run("python Jarvis_with_wake.py")
elif 'pause' in query:
print("Stopped")
speak("I am Paused, press any key to speak to me again")
playsound("jarvis_beep.mp3")
run("python Jarvis_with_wake.py")
elif 'hey jarvis' in query:
print(" _____ ")
print(" / \ -> Here for Help!")
print(" | * * | ")
print(" \_---_/ ")
print(" | | ")
speak("here i am!)
elif 'are you there' in query:
print(" _____ ")
print(" / \ -> Here for you!")
print(" | * * | ")
print(" \_---_/ ")
print(" | | ")
speak("at your service sir")
elif 'hello' in query:
print("Hi")
speak("hai")
elif 'hai' in query:
print("Hello")
speak("Hello")
elif 'hi' in query:
print("Hello")
speak("Hello")
elif " " in query:
print("That Might Be Beyong My Abilities for Now.")
speak("That might be beyond my abilities for now")
run("python Jarvis_with_wake.py")