-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJarvis.py
More file actions
219 lines (160 loc) · 7.14 KB
/
Jarvis.py
File metadata and controls
219 lines (160 loc) · 7.14 KB
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
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import os
import smtplib
from googlesearch import search
import Dataset
#warnings.filterwarnings("ignore")
engine = pyttsx3.init("sapi5")
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[4].id)
sender = 'chitranshsingh0522@gmail.com'
pw = 'vynx xnlf ejvv rdfx'
#basic text speech
def speak(audio):
engine.say(audio)
engine.runAndWait()
#Greeting function for start
def wishme():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour <= 12:
speak("Good morning Sir!")
elif hour >= 12 and hour <= 18:
speak('Good afternoon Sir!')
else:
speak('Good Evening Sir!')
speak('I am Allen your personal assistant, so how can I help you ?')
#function to send a mail
def sendEmail(content, to):
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login(sender, pw)
server.sendmail(sender,to,content)
#use voice recog. to take user inputs
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("\nListening....")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recoginizing...\n")
query = r.recognize_google(audio, language = "en-in")
print('User Said:',query,)
except Exception as e:
print(e)
print('Please say that again')
return 'jsdysdd'
return(query)
#ask user to open search result on web or not
def openResult(ii):
answer = takecommand().lower()
if 'yes' in answer:
print(f'Allen : ok, {ii.title} is opening..')
speak(f'ok, {ii.title} is opening..')
webbrowser.open(ii.url)
elif 'no' in answer:
print('Allen : Any other task for me sir?')
speak('Any other task for me sir?')
else:
print('Allen : Please say that again, I did not understand')
speak('please say that again, I did not understand')
openResult(ii)
#search function make a search on google
def makeSearch(value):
for i in search(value, 8, advanced = True):
speak('I Found this result on web')
print('Allen : I Found this result on web',i.description)
speak(i.description)
speak('For more info, do you want open it on web')
print('Allen : For more info, do you want open it on web')
ii = i
break
openResult(ii)
#main function
if __name__ == '__main__':
wishme()
while True:
query = takecommand().lower()
#Descrbring Response According to Query
if "wikipedia" in query:
print("Allen : searching on wikipedia...")
speak('searching on wikipedia')
query = query.replace("wikipedia", '')
result = wikipedia.summary(query, sentences = 2)
speak('According To Wikipedia')
try:
speak(result)
print("Allen : According to Wikipedia",result)
except Exception as e:
print("Allen : Sorry I did not find any result please ask me again")
speak("Sorry I did not find any result please ask me again")
elif 'open youtube' in query:
print("Allen : Ok sir, opening youtube...")
speak("ok sir, opening youtube")
webbrowser.open("www.youtube.com")
elif 'open superflicks' in query or 'open superflex' in query or 'open superflix' in query:
print("Allen : Ok sir, opening youtube...")
speak("ok sir, opening youtube")
webbrowser.open("https://www.youtube.com/@superflicksgaming")
elif 'open google' in query:
print("Allen : Ok sir, opening Google...")
speak("ok sir, opening google")
webbrowser.open("www.google.com")
elif 'watch' in query and 'movies' in query:
print("Allen : You wannna watch some movies, then this the best place! enjoy!")
speak("you wannna watch some movies, then this the best place! enjoy!")
webbrowser.open("https://mkvcinemas.fit/")
elif 'open code' in query or 'open vs code' in query:
print("Allen : Ok sir, opening VS Code, enjoy your work!")
speak("Ok Sir, Opening VS Code, enjoy your work!")
Codepath = 'C:\\Users\\ratho\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe'
os.startfile(Codepath)
elif 'open filmora' in query or 'editing software' in query:
print("Allen : Ok Sir, Opening flimora 12, enjoy your work!")
speak("Ok Sir, Opening flimora 12, enjoy your work!")
Codepath = 'C:\\Users\\ratho\\AppData\\Local\\Wondershare\\Wondershare Filmora\\Wondershare Filmora Launcher.exe'
os.startfile(Codepath)
elif query == 'jsdysdd':
pass
elif 'search' in query or 'what is' in query or 'google' in query or 'who is' in query:
makeSearch(query)
elif 'send mail' in query or 'send gmail' in query or 'send a mail' in query:
print("Allen : Ok sir please, give me the receivers email adresss without @gmail.com")
speak("ok sir please, give me the receivers email adresss without @gmail.com")
to = takecommand()
print(f'Allen : Ok now lastly, sir please tell what message do you want to send to {to}@gmail.com')
speak(f'ok now lastly, sir please tell what message do you want to send to {to}@gamil.com')
content = takecommand()
to = to.replace(" ", "")
to = to + "@gmail.com"
try:
sendEmail(content, to)
print('Allen : Email sent succesfully, any other task for me sir?')
speak("email sent succesfully, any other task for me sir?")
except Exception as e:
print(e)
print("Allen : Sorry Sir, I am not able to send this email")
speak("Sorry Sir, I am not able to send this email")
elif 'quit' in query or 'exit' in query or 'shutdown' in query:
speak("ok sir, when you need you can call me any time")
print('Allen : Ok sir, When you need me call again any time')
exit()
else:
try:
answer = Dataset.load_conversations(query)
if answer:
print(f"Allen : {answer[0]}")
speak(answer)
else:
speak('I have no answer for this but')
print('Allen : I have no answer for this but ')
makeSearch(query)
except Exception as ef:
print(ef)
print('Allen : Sorry sir I did not understand')
speak("Sorry sir I did not understand")