Fix tts voice bug

This commit is contained in:
Xin Wang
2026-02-09 14:39:43 +08:00
parent c7044c4c77
commit a42dd4c712
2 changed files with 44 additions and 5 deletions

View File

@@ -19,6 +19,29 @@ const isSiliconflowVendor = (vendor?: string) => {
return normalized === 'siliconflow' || normalized === '硅基流动';
};
const SILICONFLOW_DEFAULT_MODEL = 'FunAudioLLM/CosyVoice2-0.5B';
const buildSiliconflowVoiceKey = (voiceId: string, model?: string) => {
const id = String(voiceId || '').trim();
if (!id) return '';
if (id.includes(':')) return id;
return `${model || SILICONFLOW_DEFAULT_MODEL}:${id}`;
};
const resolveRuntimeTtsVoice = (selectedVoiceId: string, voice: Voice) => {
const explicitKey = String(voice.voiceKey || '').trim();
if (!isSiliconflowVendor(voice.vendor)) {
return explicitKey || selectedVoiceId;
}
if (voice.isSystem) {
const canonical = buildSiliconflowVoiceKey(selectedVoiceId, voice.model);
if (!explicitKey) return canonical;
const explicitSuffix = explicitKey.includes(':') ? explicitKey.split(':').pop() : explicitKey;
if (explicitSuffix && explicitSuffix !== selectedVoiceId) return canonical;
}
return explicitKey || buildSiliconflowVoiceKey(selectedVoiceId, voice.model);
};
export const AssistantsPage: React.FC = () => {
const [assistants, setAssistants] = useState<Assistant[]>([]);
const [voices, setVoices] = useState<Voice[]>([]);
@@ -1404,7 +1427,7 @@ export const DebugDrawer: React.FC<{
provider: ttsProvider,
model: voice.model,
apiKey: ttsProvider === 'siliconflow' ? voice.apiKey : null,
voice: voice.voiceKey || voice.id,
voice: resolveRuntimeTtsVoice(assistant.voice, voice),
speed: assistant.speed || voice.speed || 1.0,
};
} else {