-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprada_ass_virtual_update
80 lines (67 loc) · 2.38 KB
/
prada_ass_virtual_update
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
import pyttsx3
import speech_recognition as sr
import webbrowser
import datetime
import wikipedia
def take_command():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print('Listening')
recognizer.pause_threshold = 0.7
audio = recognizer.listen(source)
try:
print("Recognizing")
query = recognizer.recognize_google(audio, language='en-in')
print("The command is:", query)
except Exception as e:
print(e)
print("Say that again, please")
return "None"
return query.lower()
def speak(audio):
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
engine.say(audio)
engine.runAndWait()
def tell_day():
day = datetime.datetime.today().weekday() + 1
day_dict = {1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday', 7: 'Sunday'}
if day in day_dict.keys():
day_of_the_week = day_dict[day]
print(day_of_the_week)
speak("The day is " + day_of_the_week)
def tell_time():
current_time = datetime.datetime.now()
formatted_time = current_time.strftime("%H:%M")
print(formatted_time)
speak("The time is " + formatted_time)
def hello():
speak("Hello sir, I am your Prada virtual assistant. Tell me how may I help you")
def take_query():
hello()
while True:
query = take_command()
if "open geeksforgeeks" in query:
speak("Opening GeeksforGeeks")
webbrowser.open("https://www.geeksforgeeks.org")
elif "open google" in query:
speak("Opening Google")
webbrowser.open("https://www.google.com")
elif "which day it is" in query:
tell_day()
elif "tell me the time" in query:
tell_time()
elif "bye" in query:
speak("Goodbye. Check out GeeksforGeeks for more exciting things")
exit()
elif "from wikipedia" in query:
speak("Checking Wikipedia")
query = query.replace("wikipedia", "")
result = wikipedia.summary(query, sentences=4)
speak("According to Wikipedia")
speak(result)
elif "tell me your name" in query:
speak("I am Prada, your virtual assistant")
if __name__ == '__main__':
take_query()