Skip to content

Commit

Permalink
fix: issue where an error occurs when invoking TTS without selecting …
Browse files Browse the repository at this point in the history
…a voice (#5046)
  • Loading branch information
takatost authored Jun 9, 2024
1 parent 2573b13 commit 5986841
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/controllers/web/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion api/core/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions api/services/audio_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5986841

Please sign in to comment.