fix : tts not working with web interface

This commit is contained in:
martin legrand
2025-05-03 19:22:01 +02:00
parent bddaa75e8c
commit 52e5af8116
5 changed files with 19 additions and 7 deletions
+1
View File
@@ -250,6 +250,7 @@ class BrowserAgent(Agent):
Expand on the finding or step that lead to success, and provide a conclusion that answer the request. Include link when possible.
Do not give advices or try to answer the human. Just structure the AI finding in a structured and clear way.
You should answer in the same language as the user.
"""
def search_prompt(self, user_prompt: str) -> str:
+11 -2
View File
@@ -5,6 +5,7 @@ from sources.text_to_speech import Speech
from sources.utility import pretty_print, animate_thinking
from sources.router import AgentRouter
from sources.speech_to_text import AudioTranscriber, AudioRecorder
import threading
class Interaction:
@@ -173,12 +174,20 @@ class Interaction:
return None
return self.current_agent.get_last_block_answer()
def speak_answer(self) -> None:
"""Speak the answer to the user in a non-blocking thread."""
if self.last_query is None:
return
if self.tts_enabled and self.last_answer and self.speech:
def speak_in_thread(speech_instance, text):
speech_instance.speak(text)
thread = threading.Thread(target=speak_in_thread, args=(self.speech, self.last_answer))
thread.start()
def show_answer(self) -> None:
"""Show the answer to the user."""
if self.last_query is None:
return
if self.current_agent is not None:
self.current_agent.show_answer()
if self.tts_enabled and self.last_answer:
self.speech.speak(self.last_answer)
+2 -2
View File
@@ -173,10 +173,10 @@ if __name__ == "__main__":
tosay_fr = """
J'ai consulté les dernières nouvelles sur le site https://www.theguardian.com/world
"""
spk = Speech(enable=True, language="ja", voice_idx=2)
spk = Speech(enable=True, language="zh", voice_idx=0)
for i in range(0, 2):
print(f"Speaking chinese with voice {i}")
spk.speak(tosay_ja, voice_idx=i)
spk.speak(tosay_zh, voice_idx=i)
spk = Speech(enable=True, language="en", voice_idx=2)
for i in range(0, 5):
print(f"Speaking english with voice {i}")