From 5986841e276b9af85d86c24e93963f582e7c3397 Mon Sep 17 00:00:00 2001 From: takatost Date: Sun, 9 Jun 2024 20:28:24 +0800 Subject: [PATCH] fix: issue where an error occurs when invoking TTS without selecting a voice (#5046) --- api/controllers/web/audio.py | 2 +- api/core/model_manager.py | 2 +- api/services/audio_service.py | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/controllers/web/audio.py b/api/controllers/web/audio.py index ca6d774e9d970a..3fed7895e26249 100644 --- a/api/controllers/web/audio.py +++ b/api/controllers/web/audio.py @@ -74,7 +74,7 @@ def post(self, app_model: App, end_user): app_model=app_model, text=request.form['text'], end_user=end_user.external_user_id, - voice=request.form['voice'] if request.form.get('voice') else app_model.app_model_config.text_to_speech_dict.get('voice'), + voice=request.form['voice'] if request.form.get('voice') else None, streaming=False ) diff --git a/api/core/model_manager.py b/api/core/model_manager.py index 8da8442e602ffb..51dff09609472f 100644 --- a/api/core/model_manager.py +++ b/api/core/model_manager.py @@ -328,7 +328,7 @@ def _round_robin_invoke(self, function: callable, *args, **kwargs): except Exception as e: raise e - def get_tts_voices(self, language: str) -> list: + def get_tts_voices(self, language: Optional[str] = None) -> list: """ Invoke large language tts model voices diff --git a/api/services/audio_service.py b/api/services/audio_service.py index d013a51c3e6507..965df918d86744 100644 --- a/api/services/audio_service.py +++ b/api/services/audio_service.py @@ -93,6 +93,13 @@ def transcript_tts(cls, app_model: App, text: str, streaming: bool, raise ProviderNotSupportTextToSpeechServiceError() try: + if not voice: + voices = model_instance.get_tts_voices() + if voices: + voice = voices[0].get('value') + else: + raise ValueError("Sorry, no voice available.") + return model_instance.invoke_tts( content_text=text.strip(), user=end_user,