forked from Shokr/JARVIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
103 lines (77 loc) · 2.54 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
"""
JARVIS:
- Control Windows programs with your voice
__author__ = 'Muhammed Shokr <[email protected]>'
__version__ = 'v 1.0'
JARVIS repo <https://github.com/Shokr/JARVIS>
"""
# import modules
# subprocess module allows you to spawn new processes
import subprocess
# speech_recognition Library for performing speech recognition with support for Google Speech Recognition
import speech_recognition as sr
# importing the pyttsx3 library
import pyttsx3
import wikipedia #for wikipedia search
import smtplib #for sending mails
# initialisation
engine = pyttsx3.init()
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
engine.say("Say something")
engine.runAndWait()
audio = r.listen(source)
# recognize speech using Google Speech Recognition
Query = r.recognize_google(audio)
print(Query)
# Run Application with Voice Command Function
def get_app(query):
cmd = {
'browser': 'C:\Program Files\Internet Explorer\iexplore.exe',
'calculator': 'calc.exe',
'cmd': 'cmd.exe',
'notepad': 'Notepad.exe',
'paint': 'mspaint.exe',
'shell': 'powershell.exe',
'stikynot': 'StikyNot.exe',
}.get(query.lower())
if cmd:
subprocess.call([cmd])
else:
engine.say("Sorry Try Again")
engine.runAndWait()
def main():
# Call get_app(Query) Func.
get_app(Query)
def sendmail(to,content):
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login('[email protected]','Pass@123')
server.sendemail('[email protected]',to,content)
server.close()
if __name__ == '__main__':
main()
while True:
query = takecommand().lower()
#logic for executing programs
if 'wikipedia' in query:
speak("searching wikipedia.....")
query = query.replace("wikipedia","")
results = wikipedia.summary(query, sentences=5)
speak("according to wikipedia")
speak(results)
elif 'send email' in query:
try:
speak("what should i say")
content = takecommand()
speak("wo is receiver, sir")
receiver=input("enter receiver email sir")
to=receiver
sendEmail(to,content)
speak(content)
speak("email is sent")
elif 'go offlie' in query:
speak("going offline sir")
quit()