AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Resolved conflicts in config.py and speak.py
meta-fx3cdde2d49cba
diff --git a/scripts/config.py b/scripts/config.pyindex f636da7dfd..cdf0287c4b 100644--- a/scripts/config.py+++ b/scripts/config.py@@ -33,7 +33,7 @@ class Config(metaclass=Singleton):def __init__(self):"""Initialize the Config class"""- self.debug = False+ self.debug_mode = Falseself.continuous_mode = Falseself.speak_mode = False@@ -92,9 +92,6 @@ class Config(metaclass=Singleton):"""Set the speak mode value."""self.speak_mode = value- def set_debug_mode(self, value: bool):- self.debug_mode = value-def set_fast_llm_model(self, value: str):"""Set the fast LLM model value."""self.fast_llm_model = value@@ -137,4 +134,4 @@ class Config(metaclass=Singleton):def set_debug_mode(self, value: bool):"""Set the debug mode value."""- self.debug = value\ No newline at end of file+ self.debug_mode = value\ No newline at end of filediff --git a/scripts/speak.py b/scripts/speak.pyindex 2464c62596..bf5c6034fa 100644--- a/scripts/speak.py+++ b/scripts/speak.py@@ -4,6 +4,8 @@ import requestsfrom config import Configcfg = Config()import gtts+import threading+from threading import Lock, Semaphore# TODO: Nicer names for these ids@@ -14,6 +16,9 @@ tts_headers = {"xi-api-key": cfg.elevenlabs_api_key}+mutex_lock = Lock() # Ensure only one sound is played at a time+queue_semaphore = Semaphore(1) # The amount of sounds to queue before blocking the main thread+def eleven_labs_speech(text, voice_index=0):"""Speak text using elevenlabs.io's API"""tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format(@@ -23,10 +28,11 @@ def eleven_labs_speech(text, voice_index=0):tts_url, headers=tts_headers, json=formatted_message)if response.status_code == 200:- with open("speech.mpeg", "wb") as f:- f.write(response.content)- playsound("speech.mpeg")- os.remove("speech.mpeg")+ with mutex_lock:+ with open("speech.mpeg", "wb") as f:+ f.write(response.content)+ playsound("speech.mpeg", True)+ os.remove("speech.mpeg")return Trueelse:print("Request failed with status code:", response.status_code)@@ -39,10 +45,11 @@ def brian_speech(text):response = requests.get(tts_url)if response.status_code == 200:- with open("speech.mp3", "wb") as f:- f.write(response.content)- playsound("speech.mp3")- os.remove("speech.mp3")+ with mutex_lock:+ with open("speech.mp3", "wb") as f:+ f.write(response.content)+ playsound("speech.mp3")+ os.remove("speech.mp3")return Trueelse:print("Request failed with status code:", response.status_code)@@ -51,24 +58,33 @@ def brian_speech(text):def gtts_speech(text):tts = gtts.gTTS(text)- tts.save("speech.mp3")- playsound("speech.mp3")- os.remove("speech.mp3")+ with mutex_lock:+ tts.save("speech.mp3")+ playsound("speech.mp3", True)+ os.remove("speech.mp3")def macos_tts_speech(text):os.system(f'say "{text}"')def say_text(text, voice_index=0):- if not cfg.elevenlabs_api_key:- if cfg.use_mac_os_tts == 'True':- macos_tts_speech(text)- elif cfg.use_brian_tts == 'True':- success = brian_speech(text)- if not success:++ def speak():+ if not cfg.elevenlabs_api_key:+ if cfg.use_mac_os_tts == 'True':+ macos_tts_speech(text)+ elif cfg.use_brian_tts == 'True':+ success = brian_speech(text)+ if not success:+ gtts_speech(text)+ else:gtts_speech(text)else:- gtts_speech(text)- else:- success = eleven_labs_speech(text, voice_index)- if not success:- gtts_speech(text)\ No newline at end of file+ success = eleven_labs_speech(text, voice_index)+ if not success:+ gtts_speech(text)++ queue_semaphore.release()++ queue_semaphore.acquire(True)+ thread = threading.Thread(target=speak)+ thread.start()\ No newline at end of file