mirror of
https://github.com/maglore9900/max_headroom.git
synced 2025-06-07 03:55:30 +00:00
.
This commit is contained in:
parent
fea8e32499
commit
d1d412945b
1
main.py
1
main.py
@ -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))
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user