Fix talking voice error
This commit is contained in:
@@ -16,12 +16,37 @@ const isOpenAICompatibleVendor = (vendor?: string) => {
|
||||
};
|
||||
|
||||
const OPENAI_COMPATIBLE_DEFAULT_MODEL = 'FunAudioLLM/CosyVoice2-0.5B';
|
||||
const OPENAI_COMPATIBLE_KNOWN_VOICES = new Set([
|
||||
'alex',
|
||||
'anna',
|
||||
'bella',
|
||||
'benjamin',
|
||||
'charles',
|
||||
'claire',
|
||||
'david',
|
||||
'diana',
|
||||
]);
|
||||
|
||||
const normalizeOpenAICompatibleVoiceKey = (voiceValue: string, model?: string) => {
|
||||
const raw = String(voiceValue || '').trim();
|
||||
const modelName = String(model || '').trim() || OPENAI_COMPATIBLE_DEFAULT_MODEL;
|
||||
if (!raw) return `${modelName}:anna`;
|
||||
|
||||
if (raw.includes(':')) {
|
||||
const [prefix, ...rest] = raw.split(':');
|
||||
const voiceIdRaw = rest.join(':').trim();
|
||||
const voiceIdLower = voiceIdRaw.toLowerCase();
|
||||
const normalizedVoiceId = OPENAI_COMPATIBLE_KNOWN_VOICES.has(voiceIdLower) ? voiceIdLower : voiceIdRaw;
|
||||
return `${(prefix || modelName).trim()}:${normalizedVoiceId}`;
|
||||
}
|
||||
|
||||
const rawLower = raw.toLowerCase();
|
||||
const normalizedVoiceId = OPENAI_COMPATIBLE_KNOWN_VOICES.has(rawLower) ? rawLower : raw;
|
||||
return `${modelName}:${normalizedVoiceId}`;
|
||||
};
|
||||
|
||||
const buildOpenAICompatibleVoiceKey = (voiceId: string, model?: string) => {
|
||||
const id = String(voiceId || '').trim();
|
||||
if (!id) return '';
|
||||
if (id.includes(':')) return id;
|
||||
return `${model || OPENAI_COMPATIBLE_DEFAULT_MODEL}:${id}`;
|
||||
return normalizeOpenAICompatibleVoiceKey(voiceId, model);
|
||||
};
|
||||
|
||||
const resolveRuntimeTtsVoice = (selectedVoiceId: string, voice: Voice) => {
|
||||
@@ -29,13 +54,14 @@ const resolveRuntimeTtsVoice = (selectedVoiceId: string, voice: Voice) => {
|
||||
if (!isOpenAICompatibleVendor(voice.vendor)) {
|
||||
return explicitKey || selectedVoiceId;
|
||||
}
|
||||
const resolved = normalizeOpenAICompatibleVoiceKey(explicitKey || selectedVoiceId, voice.model);
|
||||
if (voice.isSystem) {
|
||||
const canonical = buildOpenAICompatibleVoiceKey(selectedVoiceId, voice.model);
|
||||
const canonical = normalizeOpenAICompatibleVoiceKey(selectedVoiceId, voice.model);
|
||||
if (!explicitKey) return canonical;
|
||||
const explicitSuffix = explicitKey.includes(':') ? explicitKey.split(':').pop() : explicitKey;
|
||||
if (explicitSuffix && explicitSuffix !== selectedVoiceId) return canonical;
|
||||
}
|
||||
return explicitKey || buildOpenAICompatibleVoiceKey(selectedVoiceId, voice.model);
|
||||
return resolved;
|
||||
};
|
||||
|
||||
const renderToolIcon = (icon: string) => {
|
||||
|
||||
Reference in New Issue
Block a user