From 053caaa22270d18254d7766dcb97f327ad25b618 Mon Sep 17 00:00:00 2001 From: zachRadack Date: Thu, 6 Jul 2023 20:49:59 -0700 Subject: [PATCH] Bugfix fixtts (#4902) * changing configs names to tts_provider * accidently triggered circular importing. * added config to places it needs other than the logger * got it to work on windows * did all the formatting stuff --------- Co-authored-by: James Collins --- autogpt/agent/agent.py | 2 +- autogpt/logs.py | 8 ++++++-- autogpt/main.py | 3 +++ autogpt/speech/base.py | 2 +- autogpt/speech/gtts.py | 3 ++- autogpt/speech/macos_tts.py | 3 ++- autogpt/speech/say.py | 8 ++++---- autogpt/speech/stream_elements_speech.py | 3 ++- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.py index 10051956..fd476e56 100644 --- a/autogpt/agent/agent.py +++ b/autogpt/agent/agent.py @@ -165,7 +165,7 @@ class Agent: assistant_reply_json, assistant_reply, self.config ) if self.config.speak_mode: - say_text(f"I want to execute {command_name}") + say_text(f"I want to execute {command_name}", self.config) arguments = self._resolve_pathlike_command_args(arguments) diff --git a/autogpt/logs.py b/autogpt/logs.py index 9d99f274..535cce32 100644 --- a/autogpt/logs.py +++ b/autogpt/logs.py @@ -16,7 +16,6 @@ if TYPE_CHECKING: from autogpt.log_cycle.json_handler import JsonFileHandler, JsonFormatter from autogpt.singleton import Singleton -from autogpt.speech import say_text class Logger(metaclass=Singleton): @@ -87,13 +86,16 @@ class Logger(metaclass=Singleton): self.json_logger.setLevel(logging.DEBUG) self.speak_mode = False + self.config = None self.chat_plugins = [] def typewriter_log( self, title="", title_color="", content="", speak_text=False, level=logging.INFO ): + from autogpt.speech import say_text + if speak_text and self.speak_mode: - say_text(f"{title}. {content}") + say_text(f"{title}. {content}", self.config) for plugin in self.chat_plugins: plugin.report(f"{title}. {content}") @@ -265,6 +267,8 @@ def print_assistant_thoughts( assistant_reply_json_valid: object, config: Config, ) -> None: + from autogpt.speech import say_text + assistant_thoughts_reasoning = None assistant_thoughts_plan = None assistant_thoughts_speak = None diff --git a/autogpt/main.py b/autogpt/main.py index c1b79c78..26e8e331 100644 --- a/autogpt/main.py +++ b/autogpt/main.py @@ -58,6 +58,9 @@ def run_auto_gpt( logger.speak_mode = speak config = ConfigBuilder.build_config_from_env() + # HACK: This is a hack to allow the config into the logger without having to pass it around everywhere + # or import it directly. + logger.config = config # TODO: fill in llm values here check_openai_api_key(config) diff --git a/autogpt/speech/base.py b/autogpt/speech/base.py index 44e90eaa..b3dd03bd 100644 --- a/autogpt/speech/base.py +++ b/autogpt/speech/base.py @@ -45,7 +45,7 @@ class VoiceBase(AbstractSingleton): return self._speech(text, voice_index) @abc.abstractmethod - def _setup(self) -> None: + def _setup(self, config: Config) -> None: """ Setup the voices, API key, etc. """ diff --git a/autogpt/speech/gtts.py b/autogpt/speech/gtts.py index 1c3e9cae..deef4f27 100644 --- a/autogpt/speech/gtts.py +++ b/autogpt/speech/gtts.py @@ -4,13 +4,14 @@ import os import gtts from playsound import playsound +from autogpt.config import Config from autogpt.speech.base import VoiceBase class GTTSVoice(VoiceBase): """GTTS Voice.""" - def _setup(self) -> None: + def _setup(self, config: Config) -> None: pass def _speech(self, text: str, _: int = 0) -> bool: diff --git a/autogpt/speech/macos_tts.py b/autogpt/speech/macos_tts.py index 4c072ce2..e48522cf 100644 --- a/autogpt/speech/macos_tts.py +++ b/autogpt/speech/macos_tts.py @@ -1,13 +1,14 @@ """ MacOS TTS Voice. """ import os +from autogpt.config import Config from autogpt.speech.base import VoiceBase class MacOSTTS(VoiceBase): """MacOS TTS Voice.""" - def _setup(self) -> None: + def _setup(self, config: Config) -> None: pass def _speech(self, text: str, voice_index: int = 0) -> bool: diff --git a/autogpt/speech/say.py b/autogpt/speech/say.py index 3d71a392..5d04c76f 100644 --- a/autogpt/speech/say.py +++ b/autogpt/speech/say.py @@ -41,10 +41,10 @@ def _get_voice_engine(config: Config) -> tuple[VoiceBase, VoiceBase]: if tts_provider == "elevenlabs": voice_engine = ElevenLabsSpeech(config) elif tts_provider == "macos": - voice_engine = MacOSTTS() + voice_engine = MacOSTTS(config) elif tts_provider == "streamelements": - voice_engine = StreamElementsSpeech() + voice_engine = StreamElementsSpeech(config) else: - voice_engine = GTTSVoice() + voice_engine = GTTSVoice(config) - return GTTSVoice(), voice_engine + return GTTSVoice(config), voice_engine diff --git a/autogpt/speech/stream_elements_speech.py b/autogpt/speech/stream_elements_speech.py index 9019cf09..e4e4e8bf 100644 --- a/autogpt/speech/stream_elements_speech.py +++ b/autogpt/speech/stream_elements_speech.py @@ -4,13 +4,14 @@ import os import requests from playsound import playsound +from autogpt.config import Config from autogpt.speech.base import VoiceBase class StreamElementsSpeech(VoiceBase): """Streamelements speech module for autogpt""" - def _setup(self) -> None: + def _setup(self, config: Config) -> None: """Setup the voices, API key, etc.""" def _speech(self, text: str, voice: str, _: int = 0) -> bool: