-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvoice.py
408 lines (333 loc) · 14.4 KB
/
voice.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
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import smtplib
import pywhatkit as kit
from selenium import webdriver
import time
import requests
import subprocess
from datetime import date
import calendar
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
chrome_path = 'C:/Program Files/Google/Chrome/Application/chrome.exe %s'
cdriver = 'C:\\Users\\diwakar singh\\Downloads\\chromedriver'
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) # Default voice, you can change the index to choose a different voice
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
print("Good Morning!, Sir")
speak("Good Morning!, Sir")
elif hour >= 12 and hour < 18:
print("Good Afternoon!, Sir.. ")
speak("Good Afternoon!, Sir.. ")
else:
print("Good Evening!, Sir")
speak("Good Evening!, Sir")
print("I am Jarvis, The AI Assistant of Diwakar ... How can i help you...! ")
speak("I am Jarvis, The AI Assistant of, Diwakar... How can i help you...! ")
def changeVoice():
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print("Available voices:")
for i, voice in enumerate(voices):
print(f"{i+1}. {voice.name}")
print("Choose a voice by typing the corresponding number:")
selected_voice_index = int(input())
if 1 <= selected_voice_index <= len(voices):
engine.setProperty('voice', voices[selected_voice_index - 1].id)
print("Voice changed successfully!")
else:
print("Invalid voice selection. No changes made.")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as 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()
server.login('[email protected]', sst)
server.sendmail('[email protected]', to, content)
server.close()
if __name__ == "__main__":
wishMe()
cmd = 1
while cmd:
query = takeCommand().lower()
if 'wikipedia' in query:
print('Searching Wikipedia...')
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
query = query.replace("search", "")
query = query.strip()
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
elif 'change voice' in query:
changeVoice()
elif 'quit' in query or 'exit' in query or 'keep quiet' in query or 'good night' in query:
if 'good night' in query:
hour = int(datetime.datetime.now().hour)
if (hour >= 21 and hour < 24) or (hour >= 0 and hour <= 2):
print("Ok sir, Good Night.. I am always with you sir, bye, Take care..")
speak("Ok sir, Good Night.. I am always with you sir, bye, Take care..")
cmd = 0
else:
print("No sir.. Don't make me a fool... ")
speak("No sir.. Don't make me a fool... ")
else:
print("Ok sir.. I hope, I did well, bye sir, Take care..")
speak("Ok sir.. I hope, I did well, bye sir, Take care..")
cmd = 0
elif 'good morning' in query or 'good afternoon' in query or 'good evening' in query:
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
print("Good Morning! sir...")
speak("Good Morning! sir...")
elif hour >= 12 and hour < 18:
print("Good Afternoon! sir...")
speak("Good Afternoon! sir...")
elif hour >= 18 and hour < 24:
print("Good evening sir..")
speak("Good evening sir..")
elif 'play' in query:
query = query.replace("play", "")
query = query.replace("search", "")
kit.playonyt(query)
print(f"Playing, {query}")
speak(f"Playing, {query}")
elif 'open google' in query:
print("Opening Google....")
speak("Opening Google....")
url = "google.com"
webbrowser.get(chrome_path).open(url)
elif 'google' in query:
query = query.replace("in", "")
query = query.replace("on", "")
query = query.replace("google", "")
query = query.replace("search", "")
tab = "http://google.com/?#q="
webbrowser.open(tab + query)
speak("Result on your screen")
elif 'open gmail' in query:
speak("Ok sir, opening Gmail")
webbrowser.open("www.gmail.com")
speak("Gmail on your screen, Sir...")
elif 'open facebook' in query:
print("Opening Facebook....")
speak("Opening Facebook....")
url = 'www.facebook.com'
speak("Facebook on your screen, Sir...")
webbrowser.get(chrome_path).open(url)
elif 'open whatsapp' in query:
print("Opening WhatsApp....")
speak("Opening WhatsApp....")
url = 'web.whatsapp.com'
speak("WhatsApp on your screen, Sir...")
webbrowser.get(chrome_path).open(url)
elif 'show my last' in query:
file = open("pywhatkit_dbs.txt", "r", encoding='utf-8')
content = file.read()
file.close()
if content == "--------------------":
content = None
print(content)
speak(content)
elif 'open control' in query:
print("Opening Control Panel....")
speak("Opening Control Panel....")
subprocess.call('control.exe')
speak("Control Panel on your screen, Sir...")
elif 'open file' in query:
speak("Opening File Explorer")
subprocess.call('explorer.exe')
speak("File explorer on your screen, Sir...")
elif 'music' in query or 'gana' in query:
music_dir = 'E:\\music'
songs = os.listdir(music_dir)
print("Ok Sir, Playing music....")
speak("Ok Sir, Playing music....")
print(songs)
os.startfile(os.path.join(music_dir, songs[5]))
elif "time" in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
print(f"The Time is {strTime}")
speak(f"The time is {strTime}")
elif 'open visual studio' in query or 'open vs code' in query:
codePath = "C:\\Users\\SBK\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)
elif 'about' in query:
print('Hello sir, I am Lucy, developed by Diwakar and guided by Mr. Ayaz Sir')
speak('Hello sir, I am Lucy, developed by Diwakar and guided by Mr. Ayaz Sir')
elif 'date' in query:
today = datetime.datetime.now()
today1 = today.strftime("%d, %B, ")
rr = str(today.year)
today1 = today1 + rr
print("Today's date is...")
print(today1)
speak("Today's date is...")
speak(today1)
elif 'today' in query:
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
print("Good Morning! sir...")
speak("Good Morning! sir...")
elif hour >= 12 and hour < 18:
print("Good Afternoon! sir...")
speak("Good Afternoon! sir...")
elif hour >= 18 and hour < 24:
print("Good evening sir..")
speak("Good evening sir..")
today = datetime.datetime.now()
today1 = today.strftime("%d, %B, ")
rr = str(today.year)
today1 = today1 + rr
print("Today's date is...", today1)
speak("Today's date is..." + today1)
date = date.today()
st = calendar.day_name[date.weekday()]
print("Today is ", st)
speak("Today is " + st)
elif 'day' in query:
date = date.today()
st = calendar.day_name[date.weekday()]
speak("Today is " + st)
print("Today is ", st)
elif 'send email' in query:
try:
speak("Give the Name of Reciever.")
dic = {
"Suraj": "[email protected]",
"Bhanu": "[email protected]",
"Diwakar": "[email protected]",
"Ayush": "[email protected]",
"Rahul": "[email protected]",
}
to = takeCommand()
to = dic[to]
speak("What should I say?")
content = takeCommand()
sendEmail(to, content)
speak(f"Email has been sent to {to}, Thank you....")
except Exception as e:
print(e)
speak("Sorry Sir. I am not able to send this email")
elif 'who are you' in query or 'your name' in query:
print('I am AI Based Lucy, the assistant of Diwakar...')
speak('I am AI Based Lucy, the assistant of Diwakar...')
elif 'favourite song' in query:
speak("My favorite song is 'Megenta Riddim'. Do you want to play?")
query = takeCommand().lower()
if 'yes' in query or 'yah' in query:
url = 'https://www.youtube.com/watch?v=op4B9sNGi0k'
speak("Playing My Favorite song")
webbrowser.get(chrome_path).open(url)
else:
speak("Ok sir, no problem")
elif 'open turbo c' in query:
speak("Opening Turbo C")
path = 'C:\\TC\\BIN\\DB.EXE'
os.startfile(path)
elif 'whatsapp' in query:
try:
print("Give the name of the receiver")
speak("Give the name of the receiver")
di = {
"Suraj": "+910000000",
"Vikram": "+918191015371",
"Ajgar": "+910000000000"
}
number = di[takeCommand()]
print("What message do you want to send?")
speak("What message do you want to send?")
whatmsg = takeCommand()
print("Time in hour.")
speak("Time in hour.")
hour = int(takeCommand())
print(hour)
print("Time in minute.")
speak("Time in minute.")
minu = int(takeCommand())
print(minu)
kit.sendwhatmsg(number, whatmsg, hour, minu)
except Exception as e:
print(e)
speak("Sorry Sir. I am not able to send this... Try again..")
elif 'close music' in query:
os.system('taskkill /f /im vlc.exe')
elif 'close file' in query:
os.system('taskkill /f /im explorer.exe')
elif 'close chrome' in query:
os.system('taskkill /f /im chrome.exe')
elif 'turn off pc' in query:
speak("When should the PC turn off? Give time in seconds.")
shut = int(takeCommand())
shuts = str(shut)
os.system('shutdown -s -t ' + shuts)
print(f"PC will turn off in {shuts} seconds.")
speak(f"PC will turn off in {shuts} seconds.")
elif 'cancel' in query:
cont = "shutdown /a"
os.system(cont)
print("Ok sir, Don't worry. I will not shut down your system.")
speak("Ok sir, Don't worry. I will not shut down your system.")
elif 'hello' in query:
print("Hello sir, What can I do for you..")
speak("Hello sir, What can I do for you..")
elif 'weather' in query:
try:
api_address = 'http://api.openweathermap.org/data/2.5/weather?appid=248932e95581539a55245ccabc4b8e65&q='
unit = '&units=metric'
speak("Tell me the city name.")
city = takeCommand()
url = api_address + city + unit
json_data = requests.get(url)
data = json_data.json()
temp = data['main']['temp']
temp = str(temp)
hum = data['main']['humidity']
hum = str(hum)
wind = data['wind']['speed']
wind = wind * 2
wind = str(wind)
vis = data['visibility']
vis = vis / 100
vis = str(vis)
discript = data['weather'][0]['main']
discript = str(discript)
print("Temperature is ", temp, " degree Celsius..")
speak("Temperature is " + temp + " degree Celsius..")
print("Humidity is ", hum, " percent..")
speak("Humidity is " + hum + " percent..")
print("Wind speed is ", wind, " miles per hour..")
speak("Wind speed is " + wind + " miles per hour..")
print("Description of visibility is ", discript)
speak("Description of visibility is " + discript)
print("Visibility is ", vis, " meters..")
speak("Visibility is " + vis + " meters..")
except Exception as e:
print("Sorry Sir. I am not able to give you the weather report. Try again..")
speak("Sorry Sir. I am not able to give you the weather report. Try again..")