Skip to content

Commit

Permalink
set use_gooey_asr and use_gooey_tts correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Jul 23, 2024
1 parent 01e3c81 commit e567511
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
9 changes: 3 additions & 6 deletions daras_ai_v2/twilio_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
19 changes: 10 additions & 9 deletions routers/twilio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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/")
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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/")
Expand Down

0 comments on commit e567511

Please sign in to comment.