From e56751148d698fcfc89d117e23fc1bf1ebe4b113 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Tue, 23 Jul 2024 11:58:56 -0700 Subject: [PATCH] set use_gooey_asr and use_gooey_tts correctly --- daras_ai_v2/twilio_bot.py | 9 +++------ routers/twilio_api.py | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/daras_ai_v2/twilio_bot.py b/daras_ai_v2/twilio_bot.py index 21f34e0e3..aa6259832 100644 --- a/daras_ai_v2/twilio_bot.py +++ b/daras_ai_v2/twilio_bot.py @@ -126,7 +126,7 @@ def __init__( text: str = None, audio_url: str = None, ): - from recipes.TextToSpeech import TextToSpeechProviders + from routers.twilio_api import get_twilio_tts_voice, get_twilio_asr_language self.convo = convo @@ -149,11 +149,8 @@ def __init__( super().__init__() - self.use_gooey_asr = self.saved_run.state.get("asr_model") - tts_provider = self.saved_run.state.get("tts_provider") - self.use_gooey_tts = ( - tts_provider and tts_provider != TextToSpeechProviders.GOOGLE_TTS.name - ) + self.use_gooey_asr = not get_twilio_asr_language(self.bi) + self.use_gooey_tts = not get_twilio_tts_voice(self.bi) def get_input_text(self) -> str | None: return self._text diff --git a/routers/twilio_api.py b/routers/twilio_api.py index d8ce8d2a4..6cecace5a 100644 --- a/routers/twilio_api.py +++ b/routers/twilio_api.py @@ -43,7 +43,7 @@ router = APIRouter() -def get_twilio_tts_voice(bi: BotIntegration) -> str: +def get_twilio_tts_voice(bi: BotIntegration) -> str | None: from recipes.TextToSpeech import TextToSpeechProviders run = bi.get_active_saved_run() @@ -53,13 +53,14 @@ def get_twilio_tts_voice(bi: BotIntegration) -> str: voice = "Google." + state.get("google_voice_name", "en-US-Wavenet-F") if voice not in TWILIO_SUPPORTED_VOICES: logger.warning(f"Unsupported voice {voice=} for {bi=}") - return DEFAULT_VOICE_NAME + return None return voice - return DEFAULT_VOICE_NAME + return None -def get_twilio_asr_language(bi: BotIntegration) -> str: +def get_twilio_asr_language(bi: BotIntegration) -> str | None: from daras_ai_v2.asr import normalised_lang_in_collection + from daras_ai_v2.exceptions import UserError run = bi.get_active_saved_run() state: dict = run.state @@ -71,7 +72,7 @@ def get_twilio_asr_language(bi: BotIntegration) -> str: asr_language, TWILIO_ASR_SUPPORTED_LANGUAGES ) return asr_language - except: + except UserError: pass user_language = state.get("user_language") @@ -81,10 +82,10 @@ def get_twilio_asr_language(bi: BotIntegration) -> str: user_language, TWILIO_ASR_SUPPORTED_LANGUAGES ) return user_language - except: + except UserError: pass - return DEFAULT_ASR_LANGUAGE + return None @router.post("/__/twilio/voice/") @@ -181,7 +182,7 @@ def create_voice_call_response( action=action, method="POST", finish_on_key="0", # user can press 0 to end the input - language=get_twilio_asr_language(bot.bi), + language=get_twilio_asr_language(bot.bi) or DEFAULT_ASR_LANGUAGE, speech_model="phone_call", # optimized for phone call audio enhanced=True, # only phone_call model supports enhanced ) @@ -286,7 +287,7 @@ def resp_say_or_tts_play( else: return - resp.say(text, voice=get_twilio_tts_voice(bot.bi)) + resp.say(text, voice=get_twilio_tts_voice(bot.bi) or DEFAULT_VOICE_NAME) @router.post("/__/twilio/voice/error/")