-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoice Assistant.py
More file actions
78 lines (66 loc) · 2.57 KB
/
Voice Assistant.py
File metadata and controls
78 lines (66 loc) · 2.57 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
import datetime
import webbrowser
import pyttsx3
import speech_recognition as sr
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
def listen():
with sr.Microphone() as source:
print("Listening...")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
query = recognizer.recognize_google(audio)
print("You said:", query)
return query.lower()
except sr.UnknownValueError:
speak("Sorry, I didn't get that. Can you please repeat?")
return listen()
except sr.RequestError as e:
speak("Could not request results from Google Speech Recognition service; {0}".format(e))
def main():
speak("Hello Pawan! I am your voice assistant. How can I help you?")
while True:
query = listen()
if "hello" in query:
speak("Hi there! How can I assist you today?")
elif "time" in query:
# Get current time
current_time = datetime.datetime.now().strftime("%I:%M %p")
speak("The current time is " + current_time)
elif "date" in query:
# Get current date
current_date = datetime.datetime.now().strftime("%B %d, %Y")
speak("Today's date is " + current_date)
elif "open youtube" in query:
webbrowser.open("https://www.youtube.com")
speak("Opening YouTube")
elif "open chrome" in query:
webbrowser.open("https://www.chrome.com")
speak("Opening Chrome")
elif "open amazon" in query:
webbrowser.open("https://www.amazon.com")
speak("Opening Amazon")
elif "open flipkart" in query:
webbrowser.open("https://www.flipkart.com")
speak("Opening Flipkart")
elif "search" in query:
speak("What do you want me to search for pawan?")
search_query = listen()
webbrowser.open("https://www.google.com/search?q=" + search_query)
speak("Here are the search results for " + search_query)
elif "open website" in query:
speak("What website do you want me to open?")
website = listen()
webbrowser.open("https://" + website)
speak("Opening " + website)
elif "exit" in query:
speak("Thank You, Goodbye!")
break
else:
speak("Sorry, I didn't understand that.")
if __name__ == "__main__":
main()