diff --git a/main.py b/main.py index 0819698..07da5a5 100644 --- a/main.py +++ b/main.py @@ -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)) diff --git a/modules/speak.py b/modules/speak.py index 12e7c87..1a16ea4 100644 --- a/modules/speak.py +++ b/modules/speak.py @@ -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