-
Notifications
You must be signed in to change notification settings - Fork 0
/
female-jarvis.py
294 lines (240 loc) · 9.05 KB
/
female-jarvis.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
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import smtplib
import webbrowser as wb
import psutil
import pyjokes
import os
import pyautogui
import random
import wolframalpha
import json
import requests
from urllib.request import urlopen
import time
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
wolframalpha_app_id = 'WP95H3-XG95L64J93'
def speak(audio):
engine.say(audio)
engine.runAndWait()
def time_():
Time = datetime.datetime.now().strftime("%I:%M:%S") #For 12 hour clock
print(Time)
speak("The Current Time is")
speak(Time)
def date_():
year = datetime.datetime.now().year
month = datetime.datetime.now().month
day = datetime.datetime.now().day
print(datetime.date.today())
speak("Today's date is")
speak(day)
speak(month)
speak(year)
def wishme():
#Greetings
hour = datetime.datetime.now().hour
if hour>=6 and hour<12:
speak("Good morning Neel")
elif hour>=12 and hour<18:
speak("Good Afternoon Neel")
elif hour>=18 and hour<24:
speak("Good evening Neel")
else:
speak("Good Night Neel")
speak("Welcome back")
#time_()
#date_()
speak("Jarvis at your sevice. Please tell me how can I help you today!")
def TakeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening.....")
r.pause_threshold = 0.5
audio = r.listen(source)
try:
print("Recognizing.....")
query = r.recognize_google(audio,language = "en-US")
print(query)
except Exception as e:
print(e)
print("Say that again please.....")
return "None"
return query
def sendEmail(to,content):
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
#for this function, we must enable low security in our gmail.
server.login('username@gmail.com','password')
server.sendmail('username@gail.com',to,content)
server.close()
def cpu():
usage = str(psutil.cpu_percent())
speak('CPU is at'+usage)
battery = psutil.sensors_battery()
speak('Battery is at')
speak(battery.percent)
def joke():
speak(pyjokes.get_joke())
def screenshot():
img = pyautogui.screenshot()
img.save('C:/Users/NMR/Pictures/Jarvis_SS/screenshot.png')
if __name__ == "__main__":
print("JARVIS AT YOUR SERVICE.......")
print(datetime.datetime.now())
wishme()
while True:
query = TakeCommand().lower()
"""
All command will be stored in lower case in query
for easy recognition
"""
if 'time' in query: #tell us about time
time_()
elif 'date' in query: #tell us about date
date_()
elif 'how are you' in query:
speak('I am Fine, How are you.')
ans = TakeCommand().lower()
if 'fine' in ans:
speak('Glad to here it')
elif 'not' in ans:
speak('feel sorry to hear it')
elif 'wikipedia' in query:
speak("Searching.....")
query = query.replace('wikipedia', '')
result = wikipedia.summary(query,sentences = 3)
speak('According to Wikipedia')
print(result)
speak(result)
elif 'send email' in query:
try:
speak("What should I say ?")
content = TakeCommand()
#provide receiver mail
speak("Who is the Receiver?")
reciever = input(("Enter the Receiver Email ID: "))
to = reciever
sendEmail(to, content)
speak(content)
speak("Email has been sent.")
except Exception as e:
print(e)
speak("Unable to send Email")
elif 'search in chrome' in query:
speak("What should I search?")
chromepath = 'C:/Program Files/Google/Chrome/Application/chrome.exe %s'
search = TakeCommand().lower()
wb.get(chromepath).open_new_tab(search+'.com') #only the website with .com will open
elif 'search youtube' in query:
speak('What should I serach in Youtube?')
search_term = TakeCommand().lower()
speak('Here we go to YOUTUBE!')
wb.open('https://www.youtube.com/results?search_query='+search_term)
elif 'search google' in query:
speak('What should I search?')
search_term = TakeCommand().lower()
speak('Searching...')
wb.open('https://www.google.com/search?q='+search_term)
elif 'cpu' in query:
cpu()
elif 'joke' in query:
joke()
elif 'go offline' in query:
speak('Going Offline Sir!')
quit()
elif 'open' in query:
speak('Opening please wait...')
fxn = r'D:/Movies\WEBSERIES/fairy tail'
os.startfile(fxn)
elif 'write a note' in query:
speak('What should I write, Sir!')
notes = TakeCommand()
file = open('notes.txt','w')
speak('Sir should I include Date and Time also?')
ans = TakeCommand()
if 'yes' in ans or 'sure' in ans:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
file.write(strTime)
file.write(':-')
file.write(notes)
speak('Done Taking Notes, Sir!')
else:
file.write(notes)
elif 'show notes' in query:
speak('Showing Notes')
file = open('notes.txt','r')
print(file.read())
speak(file.read())
elif 'screenshot' in query:
screenshot()
elif 'play music' in query:
song_dir = 'C:/Users/NMR/Music/music'
music = os.listdir(song_dir)
speak('What should I play?')
ans = TakeCommand().lower()
no = int(ans.replace('number', ''))
os.startfile(os.path.join(song_dir,music[no]))
elif 'remember that' in query:
speak('What should I remember?')
memory = TakeCommand()
speak('You asked me to remember that'+memory)
remember = open('memory.txt','w')
remember.write(memory)
remember.close()
elif 'do you remember anything' in query:
remember = open('memory.txt','r')
speak('You asked me to remember that'+remember.read())
elif 'where is' in query:
query = query.replace('where is', '')
location = query
speak('User asked to locate'+location)
wb.open_new_tab('https://www.google.com/maps/place/'+location)
elif 'news' in query:
try:
jsonobj = urlopen("https://newsapi.org/v2/everything?q=tesla&from=2021-05-22&sortBy=publishedAt&apiKey=8b520920c0a64d1b9bab9aee04ca6227")
data = json.load(jsonobj)
i = 1
speak("Here are some top headlines from the Tesla Company")
print("===========TOP HEADLINES==========="+"\n")
for item in data['articles']:
print(str(i)+'. '+item['title']+'\n')
print(item['description']+'\n')
speak(item['title'])
i +=1
except Exception as e:
print(str(e))
elif 'calculate' in query:
client = wolframalpha.Client(wolframalpha_app_id)
indx = query.lower().split().index('calculate')
query = query.split()[indx +1:]
res= client.query(''.join(query))
answer= next(res.results).text
print('The Answer is : '+answer)
speak('The Answer is '+answer)
elif 'what is ' in query or 'who is ' in query:
speak('Please wait Sir Let me check...')
client = wolframalpha.Client(wolframalpha_app_id)
res = client.query(query)
res = client.query(query)
try:
print(next(res.results).text)
speak(next(res.results).text)
except StopIteration:
print('No Results')
elif 'stop listening' in query:
speak('For how much time you want me to stop listening to your commands?')
ans = int(TakeCommand())
time.sleep(ans)
print(ans)
elif 'log out' in query:
os.system("shutdown -l")
elif 'restart' in query:
os.system("shutdown /r /t l")
elif 'shutdown' in query:
os.system("shutdown /s /t l")