From ef0d19d144175dc31f66d7aac511a86e31e556dc Mon Sep 17 00:00:00 2001 From: imeepos Date: Thu, 31 Jul 2025 13:36:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9F=B3=E8=89=B2?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8=E6=95=B0=E6=8D=AE=E6=BA=90=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9C=9F=E5=AE=9E=E7=B3=BB=E7=BB=9F=E9=9F=B3?= =?UTF-8?q?=E8=89=B2=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主要修复: - 替换VoiceSelector中的假数据为真实系统音色数据 - 使用SystemVoiceService.getAllSystemVoices()获取系统音色 - 修复VoiceInfo.description类型兼容性问题(string[] -> string) - 根据音色类型和性别自动生成标签 - 并行加载系统音色和自定义音色,提升性能 技术改进: � 集成SystemVoiceService获取真实数据 �️ 智能标签生成(系统/精品/童声等) � 类型安全的数据转换 ⚡ 并行数据加载优化 � 详细的加载日志输出 现在音色选择器将显示真实的系统音色数据,而不是模拟数据! --- apps/desktop/src/components/VoiceSelector.tsx | 96 +++++++++++++------ 1 file changed, 67 insertions(+), 29 deletions(-) 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({