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

@@ -4,6 +4,14 @@ import { Button, Input, TableHeader, TableRow, TableHead, TableCell, Dialog, Bad
import { Voice } from '../types';
import { createVoice, deleteVoice, fetchVoices, previewVoice, updateVoice } from '../services/backendApi';
const SILICONFLOW_DEFAULT_MODEL = 'FunAudioLLM/CosyVoice2-0.5B';
const buildSiliconflowVoiceKey = (rawId: string, model: string): string => {
const id = (rawId || '').trim();
if (!id) return `${model}:anna`;
return id.includes(':') ? id : `${model}:${id}`;
};
export const VoiceLibraryPage: React.FC = () => {
const [voices, setVoices] = useState<Voice[]>([]);
const [searchTerm, setSearchTerm] = useState('');
@@ -249,7 +257,7 @@ const AddVoiceModal: React.FC<{
const [vendor, setVendor] = useState<'硅基流动' | 'Ali' | 'Volcano' | 'Minimax'>('硅基流动');
const [name, setName] = useState('');
const [sfModel, setSfModel] = useState('FunAudioLLM/CosyVoice2-0.5B');
const [sfModel, setSfModel] = useState(SILICONFLOW_DEFAULT_MODEL);
const [sfVoiceId, setSfVoiceId] = useState('FunAudioLLM/CosyVoice2-0.5B:anna');
const [sfSpeed, setSfSpeed] = useState(1);
const [sfGain, setSfGain] = useState(0);
@@ -271,6 +279,8 @@ const AddVoiceModal: React.FC<{
useEffect(() => {
if (!initialVoice) return;
const nextVendor = initialVoice.vendor === 'SiliconFlow' ? '硅基流动' : initialVoice.vendor;
const nextModel = initialVoice.model || SILICONFLOW_DEFAULT_MODEL;
const defaultVoiceKey = buildSiliconflowVoiceKey(initialVoice.id || initialVoice.name || '', nextModel);
setVendor((nextVendor as any) || '硅基流动');
setName(initialVoice.name || '');
setGender(initialVoice.gender || 'Female');
@@ -278,8 +288,8 @@ const AddVoiceModal: React.FC<{
setDescription(initialVoice.description || '');
setModel(initialVoice.model || '');
setVoiceKey(initialVoice.voiceKey || '');
setSfModel(initialVoice.model || 'FunAudioLLM/CosyVoice2-0.5B');
setSfVoiceId(initialVoice.voiceKey || 'FunAudioLLM/CosyVoice2-0.5B:anna');
setSfModel(nextModel);
setSfVoiceId((initialVoice.voiceKey || '').trim() || defaultVoiceKey);
setSfSpeed(initialVoice.speed ?? 1);
setSfGain(initialVoice.gain ?? 0);
setSfPitch(initialVoice.pitch ?? 0);
@@ -315,6 +325,12 @@ const AddVoiceModal: React.FC<{
return;
}
const resolvedSiliconflowVoiceKey = (() => {
const current = (sfVoiceId || '').trim();
if (current) return current;
return buildSiliconflowVoiceKey(initialVoice?.id || name, sfModel || SILICONFLOW_DEFAULT_MODEL);
})();
const newVoice: Voice = {
id: initialVoice?.id || `${vendor === '硅基流动' ? 'sf' : 'gen'}-${Date.now()}`,
name,
@@ -323,7 +339,7 @@ const AddVoiceModal: React.FC<{
language,
description: description || (vendor === '硅基流动' ? `Model: ${sfModel}` : `Model: ${model}`),
model: vendor === '硅基流动' ? sfModel : model,
voiceKey: vendor === '硅基流动' ? sfVoiceId : voiceKey,
voiceKey: vendor === '硅基流动' ? resolvedSiliconflowVoiceKey : voiceKey,
apiKey,
baseUrl,
speed: sfSpeed,