This commit is contained in:
maglore9900 2024-08-28 10:23:42 -04:00
parent fea8e32499
commit d1d412945b
2 changed files with 19 additions and 13 deletions

View File

@ -10,7 +10,6 @@ graph = agent.Agent()
while True: while True:
print("Listening...")
text = sp.listen() text = sp.listen()
if text and "max" in text.lower(): if text and "max" in text.lower():
response = loop.run_until_complete(graph.invoke_agent(text)) response = loop.run_until_complete(graph.invoke_agent(text))

View File

@ -56,21 +56,28 @@ class Speak:
def listen(self): def listen(self):
with self.microphone as source: with self.microphone as source:
#! Adjust for ambient noise # Adjust for ambient noise
self.recognizer.adjust_for_ambient_noise(source, duration=1) self.recognizer.adjust_for_ambient_noise(source, duration=1)
print("Listening...")
try: try:
#! added 5 second timeout so ambient noise detection can compensate for music that started playing # Listen with a 5-second timeout
audio = self.recognizer.listen(source, timeout=5) audio = self.recognizer.listen(source, timeout=5)
text = self.recognizer.recognize_google(audio) try:
print("You said: ", text) text = self.recognizer.recognize_google(audio)
return text print("You said: ", text)
except: return text
pass except sr.UnknownValueError:
# except sr.UnknownValueError: print("Sorry, I didn't get that.")
# print("Sorry, I didn't get that.") return None
# except sr.RequestError as e: except sr.RequestError as e:
# print("Sorry, I couldn't request results; {0}".format(e)) print("Sorry, I couldn't request results; {0}".format(e))
return None
except sr.WaitTimeoutError:
print("Timeout. No speech detected.")
return None
def stream_output(self, text): def stream_output(self, text):
import urllib.parse import urllib.parse