diff --git a/apps/desktop/src/components/VoiceSelector.tsx b/apps/desktop/src/components/VoiceSelector.tsx index 616cca2..fa10b61 100644 --- a/apps/desktop/src/components/VoiceSelector.tsx +++ b/apps/desktop/src/components/VoiceSelector.tsx @@ -16,12 +16,12 @@ import { import { invoke } from '@tauri-apps/api/core'; import { Modal } from './Modal'; import { useNotifications } from './NotificationSystem'; -import SystemVoiceSelector from './SystemVoiceSelector'; +import { SystemVoiceService } from '../services/systemVoiceService'; import { VoiceInfo, GetVoicesResponse } from '../types/voiceClone'; -import { SystemVoice } from '../types/systemVoice'; +import { SystemVoice, SystemVoiceType, VoiceGender } from '../types/systemVoice'; interface VoiceSelectorProps { isOpen: boolean; @@ -69,43 +69,81 @@ export const VoiceSelector: React.FC = ({ const loadVoices = useCallback(async () => { setLoading(true); try { - // 加载自定义音色 - const customVoicesResponse = await invoke('get_voices'); + // 并行加载系统音色和自定义音色 + const [systemVoicesData, customVoicesResponse] = await Promise.all([ + SystemVoiceService.getAllSystemVoices(), + invoke('get_voices') + ]); + + // 转换系统音色数据 + const systemVoices: CombinedVoice[] = systemVoicesData.map(voice => { + const tags = []; + + // 根据音色类型添加标签 + switch (voice.voice_type) { + case SystemVoiceType.SYSTEM: + tags.push('系统'); + break; + case SystemVoiceType.PREMIUM: + tags.push('精品'); + break; + case SystemVoiceType.CHILD: + tags.push('童声'); + break; + case SystemVoiceType.CHARACTER: + tags.push('角色'); + break; + case SystemVoiceType.HOLIDAY: + tags.push('节日'); + break; + case SystemVoiceType.ENGLISH: + tags.push('英文'); + break; + } + + // 根据性别添加标签 + switch (voice.gender) { + case VoiceGender.MALE: + tags.push('男声'); + break; + case VoiceGender.FEMALE: + tags.push('女声'); + break; + case VoiceGender.CHILD: + tags.push('童声'); + break; + } + + return { + id: voice.voice_id, + name: voice.voice_name, + description: voice.description, + type: 'system' as const, + gender: voice.gender === VoiceGender.MALE ? 'male' : voice.gender === VoiceGender.FEMALE ? 'female' : undefined, + language: voice.language, + tags, + data: voice + }; + }); + + // 转换自定义音色数据 const customVoices: CombinedVoice[] = customVoicesResponse.data?.map(voice => ({ id: voice.voice_id, name: voice.voice_name || voice.voice_id, - description: voice.description, + description: Array.isArray(voice.description) ? voice.description.join(', ') : voice.description, type: 'custom' as const, tags: ['自定义'], data: voice })) || []; - // 这里应该加载系统音色,暂时使用模拟数据 - const systemVoices: CombinedVoice[] = [ - { - id: 'system_voice_1', - name: '小雅', - description: '温柔女声,适合朗读', - type: 'system', - gender: 'female', - language: 'zh-CN', - tags: ['温柔', '朗读'], - data: { id: 'system_voice_1', name: '小雅' } as SystemVoice - }, - { - id: 'system_voice_2', - name: '小明', - description: '清晰男声,适合播报', - type: 'system', - gender: 'male', - language: 'zh-CN', - tags: ['清晰', '播报'], - data: { id: 'system_voice_2', name: '小明' } as SystemVoice - } - ]; - const allVoices = [...systemVoices, ...customVoices]; setVoices(allVoices); + + console.log('🎵 成功加载音色:', { + 系统音色: systemVoices.length, + 自定义音色: customVoices.length, + 总计: allVoices.length + }); } catch (error) { console.error('加载音色列表失败:', error); addNotification({