@@ -66,7 +66,19 @@ def LoadModel(self, request, context):
66
66
67
67
def TTS (self , request , context ):
68
68
try :
69
- self .tts .tts_to_file (text = request .text , speaker_wav = self .AudioPath , language = COQUI_LANGUAGE , file_path = request .dst )
69
+ # if model is multilangual add language from request or env as fallback
70
+ lang = request .Lang or COQUI_LANGUAGE
71
+ if self .tts .is_multi_lingual and lang is None :
72
+ return backend_pb2 .Result (success = False , message = f"Model is multi-lingual, but no language was provided" )
73
+
74
+ # if model is multi-speaker, use speaker_wav or the speaker_id from request.voice
75
+ if self .tts .is_multi_speaker and self .AudioPath is None and request .voice is None :
76
+ return backend_pb2 .Result (success = False , message = f"Model is multi-speaker, but no speaker was provided" )
77
+
78
+ if self .tts .is_multi_speaker and request .voice is not None :
79
+ self .tts .tts_to_file (text = request .text , speaker = request .voice , language = lang , file_path = request .dst )
80
+ else :
81
+ self .tts .tts_to_file (text = request .text , speaker_wav = self .AudioPath , language = lang , file_path = request .dst )
70
82
except Exception as err :
71
83
return backend_pb2 .Result (success = False , message = f"Unexpected { err = } , { type (err )= } " )
72
84
return backend_pb2 .Result (success = True )
0 commit comments