-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoiceAssistantProject
More file actions
37 lines (31 loc) · 899 Bytes
/
VoiceAssistantProject
File metadata and controls
37 lines (31 loc) · 899 Bytes
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
import speech_recognition as sr
import pyttsx3
import pyaudio
r = sr.Recognizer()
engine = pyttsx3.init()
def listen():
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio)
print(f"You said: {query}")
return query
except sr.UnknownValueError:
print("Sorry, I didn't catch that. Could you please repeat?")
return listen()
def speak(text):
print(f"Assistant: {text}")
engine.say(text)
engine.runAndWait()
def process_query(query):
if "hello" in query:
speak("Hello! How can I assist you today?")
elif "time" in query:
speak("The current time is 9:00 AM.")
else:
speak("I'm sorry, I didn't understand your request.")
while True:
query = listen().lower()
process_query(query)