fix: 修复音色选择器数据源,使用真实系统音色数据

主要修复:
- 替换VoiceSelector中的假数据为真实系统音色数据
- 使用SystemVoiceService.getAllSystemVoices()获取系统音色
- 修复VoiceInfo.description类型兼容性问题(string[] -> string)
- 根据音色类型和性别自动生成标签
- 并行加载系统音色和自定义音色,提升性能

技术改进:
� 集成SystemVoiceService获取真实数据
�️ 智能标签生成(系统/精品/童声等)
� 类型安全的数据转换
 并行数据加载优化
� 详细的加载日志输出

现在音色选择器将显示真实的系统音色数据,而不是模拟数据!
This commit is contained in:
杨明明 2025-07-31 13:36:20 +08:00
parent efc3fb9d82
commit ef0d19d144
1 changed files with 67 additions and 29 deletions

View File

@ -16,12 +16,12 @@ import {
import { invoke } from '@tauri-apps/api/core'; import { invoke } from '@tauri-apps/api/core';
import { Modal } from './Modal'; import { Modal } from './Modal';
import { useNotifications } from './NotificationSystem'; import { useNotifications } from './NotificationSystem';
import SystemVoiceSelector from './SystemVoiceSelector'; import { SystemVoiceService } from '../services/systemVoiceService';
import { import {
VoiceInfo, VoiceInfo,
GetVoicesResponse GetVoicesResponse
} from '../types/voiceClone'; } from '../types/voiceClone';
import { SystemVoice } from '../types/systemVoice'; import { SystemVoice, SystemVoiceType, VoiceGender } from '../types/systemVoice';
interface VoiceSelectorProps { interface VoiceSelectorProps {
isOpen: boolean; isOpen: boolean;
@ -69,43 +69,81 @@ export const VoiceSelector: React.FC<VoiceSelectorProps> = ({
const loadVoices = useCallback(async () => { const loadVoices = useCallback(async () => {
setLoading(true); setLoading(true);
try { try {
// 加载自定义音色 // 并行加载系统音色和自定义音色
const customVoicesResponse = await invoke<GetVoicesResponse>('get_voices'); const [systemVoicesData, customVoicesResponse] = await Promise.all([
SystemVoiceService.getAllSystemVoices(),
invoke<GetVoicesResponse>('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 => ({ const customVoices: CombinedVoice[] = customVoicesResponse.data?.map(voice => ({
id: voice.voice_id, id: voice.voice_id,
name: voice.voice_name || 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, type: 'custom' as const,
tags: ['自定义'], tags: ['自定义'],
data: voice 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]; const allVoices = [...systemVoices, ...customVoices];
setVoices(allVoices); setVoices(allVoices);
console.log('🎵 成功加载音色:', {
系统音色: systemVoices.length,
自定义音色: customVoices.length,
总计: allVoices.length
});
} catch (error) { } catch (error) {
console.error('加载音色列表失败:', error); console.error('加载音色列表失败:', error);
addNotification({ addNotification({