mirror of
https://github.com/maglore9900/max_headroom.git
synced 2025-06-07 12:05:50 +00:00
fallback for TTS
modified the speak portion so that if you are not using alltalk it will respond like a robot locally
This commit is contained in:
parent
22d7bdc1c3
commit
08fa93898f
2
main.py
2
main.py
@ -15,5 +15,5 @@ while True:
|
|||||||
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))
|
||||||
if response:
|
if response:
|
||||||
sp.glitch_stream_output(response)
|
sp.glitch_stream_output2(response)
|
||||||
|
|
||||||
|
@ -58,10 +58,10 @@ class Speak:
|
|||||||
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)
|
||||||
|
|
||||||
|
try:
|
||||||
#! added 5 second timeout so ambient noise detection can compensate for music that started playing
|
#! added 5 second timeout so ambient noise detection can compensate for music that started playing
|
||||||
audio = self.recognizer.listen(source, timeout=5)
|
audio = self.recognizer.listen(source, timeout=5)
|
||||||
try:
|
|
||||||
|
|
||||||
text = self.recognizer.recognize_google(audio)
|
text = self.recognizer.recognize_google(audio)
|
||||||
print("You said: ", text)
|
print("You said: ", text)
|
||||||
return text
|
return text
|
||||||
@ -207,7 +207,7 @@ class Speak:
|
|||||||
|
|
||||||
# Create the streaming URL
|
# Create the streaming URL
|
||||||
streaming_url = f"http://localhost:7851/api/tts-generate-streaming?text={encoded_text}&voice={voice}&language={language}&output_file={output_file}"
|
streaming_url = f"http://localhost:7851/api/tts-generate-streaming?text={encoded_text}&voice={voice}&language={language}&output_file={output_file}"
|
||||||
|
try:
|
||||||
# Stream the audio data
|
# Stream the audio data
|
||||||
response = requests.get(streaming_url, stream=True)
|
response = requests.get(streaming_url, stream=True)
|
||||||
|
|
||||||
@ -262,3 +262,6 @@ class Speak:
|
|||||||
stream.stop_stream()
|
stream.stop_stream()
|
||||||
stream.close()
|
stream.close()
|
||||||
p.terminate()
|
p.terminate()
|
||||||
|
except:
|
||||||
|
self.engine.say(text)
|
||||||
|
self.engine.runAndWait()
|
Loading…
x
Reference in New Issue
Block a user