This commit is contained in:
superlishunqin 2025-09-15 00:53:55 +08:00
parent cfa15f2c5c
commit 36c3c45a0d

View File

@ -34,21 +34,16 @@ class CosyVoiceService:
return []
result = self.client.predict(api_name="/refresh_sft_spk")
logger.info(f"音色列表原始返回: {result}")
# 处理返回的字典格式
# 处理返回的字典格式{'choices': [['name', 'name'], ...], '__type__': 'update'}
if isinstance(result, dict) and 'choices' in result:
# 从choices中提取音色名称格式是 [['name', 'name'], ...]
voices = []
for choice in result['choices']:
if isinstance(choice, list) and len(choice) > 0:
voice_name = choice[0]
voice_name = choice[0] # 取第一个元素
if voice_name != '.ipynb_checkpoints':
voices.append(voice_name)
return voices
elif isinstance(result, list):
# 直接是列表格式
return [voice for voice in result if voice != '.ipynb_checkpoints']
else:
logger.error(f"未知的音色列表格式: {result}")
return []
@ -73,8 +68,6 @@ class CosyVoiceService:
if isinstance(choice, list) and len(choice) > 0:
audios.append(choice[0])
return audios
elif isinstance(result, list):
return result
else:
return []
@ -159,7 +152,7 @@ class CosyVoiceService:
api_name="/generate_audio"
)
logger.info(f"预训练音色生成结果: {result}")
logger.info(f"预训练音色生成结果类型: {type(result)}")
# result是一个元组 [流式音频路径, 完整音频路径]
if isinstance(result, (list, tuple)) and len(result) >= 2: