mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-13 18:36:04 +08:00
fix: issue where an error occurs when invoking TTS without selecting a voice (#5046)
This commit is contained in:
parent
2573b138bf
commit
5986841e27
@ -74,7 +74,7 @@ class TextApi(WebApiResource):
|
|||||||
app_model=app_model,
|
app_model=app_model,
|
||||||
text=request.form['text'],
|
text=request.form['text'],
|
||||||
end_user=end_user.external_user_id,
|
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
|
streaming=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ class ModelInstance:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise 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
|
Invoke large language tts model voices
|
||||||
|
|
||||||
|
@ -93,6 +93,13 @@ class AudioService:
|
|||||||
raise ProviderNotSupportTextToSpeechServiceError()
|
raise ProviderNotSupportTextToSpeechServiceError()
|
||||||
|
|
||||||
try:
|
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(
|
return model_instance.invoke_tts(
|
||||||
content_text=text.strip(),
|
content_text=text.strip(),
|
||||||
user=end_user,
|
user=end_user,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user