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:
print("Listening...")
text = sp.listen()
if text and "max" in text.lower():
response = loop.run_until_complete(graph.invoke_agent(text))

View File

@ -56,21 +56,28 @@ class Speak:
def listen(self):
with self.microphone as source:
#! Adjust for ambient noise
# Adjust for ambient noise
self.recognizer.adjust_for_ambient_noise(source, duration=1)
print("Listening...")
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)
text = self.recognizer.recognize_google(audio)
print("You said: ", text)
return text
except:
pass
# except sr.UnknownValueError:
# print("Sorry, I didn't get that.")
# except sr.RequestError as e:
# print("Sorry, I couldn't request results; {0}".format(e))
try:
text = self.recognizer.recognize_google(audio)
print("You said: ", text)
return text
except sr.UnknownValueError:
print("Sorry, I didn't get that.")
return None
except sr.RequestError as 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):
import urllib.parse