Fix talking voice error

This commit is contained in:
Xin Wang
2026-02-12 19:39:26 +08:00
parent 81ed89b84f
commit 56f8aa2191
3 changed files with 82 additions and 12 deletions

View File

@@ -53,11 +53,20 @@ class OpenAICompatibleTTSService(BaseTTSService):
sample_rate: Output sample rate (8000, 16000, 24000, 32000, 44100)
speed: Speech speed (0.25 to 4.0)
"""
# Resolve voice name
if voice in self.VOICES:
full_voice = self.VOICES[voice]
# Resolve voice name (case-insensitive), and normalize "model:VoiceId" suffix.
resolved_voice = (voice or "").strip()
voice_lookup = resolved_voice.lower()
if voice_lookup in self.VOICES:
full_voice = self.VOICES[voice_lookup]
elif ":" in resolved_voice:
model_part, voice_part = resolved_voice.split(":", 1)
normalized_voice_part = voice_part.strip().lower()
if normalized_voice_part in self.VOICES:
full_voice = f"{(model_part or model).strip()}:{normalized_voice_part}"
else:
full_voice = resolved_voice
else:
full_voice = voice
full_voice = resolved_voice
super().__init__(voice=full_voice, sample_rate=sample_rate, speed=speed)