mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
2.4 KiB
2.4 KiB
SiliconFlow Voice Format Fix
Issue
SiliconFlow CosyVoice API requires system-predefined voices to be prefixed with the model name in the format:
FunAudioLLM/CosyVoice2-0.5B:alex
Solution Implemented
1. Updated TTS Provider Logic
The siliconflow.py provider now automatically handles voice formatting:
# Voice configuration - default to diana with model prefix
if config.get("private_voice"):
self.voice = config.get("private_voice")
else:
voice_name = config.get("voice", "diana")
# If voice doesn't already contain model prefix, add it
if ":" not in voice_name:
self.voice = f"{self.model}:{voice_name}"
else:
self.voice = voice_name
2. Voice Parameter in API Request
The voice parameter is now properly included in the API payload:
# Add voice parameter with model prefix (e.g., FunAudioLLM/CosyVoice2-0.5B:diana)
if self.voice:
payload["voice"] = self.voice
3. Updated Available Voices
The get_available_voices() method now returns properly formatted voice names:
def get_available_voices(self):
model_prefix = self.model
return [
(f"{model_prefix}:diana", "Diana (Female)"),
(f"{model_prefix}:alex", "Alex (Male)"),
(f"{model_prefix}:bella", "Bella (Female)"),
]
Configuration Examples
Simple Configuration (Recommended)
siliconflow:
model: FunAudioLLM/CosyVoice2-0.5B
voice: diana # Automatically becomes FunAudioLLM/CosyVoice2-0.5B:diana
Full Format Configuration
siliconflow:
model: FunAudioLLM/CosyVoice2-0.5B
voice: FunAudioLLM/CosyVoice2-0.5B:alex # Used as-is
API Request Format
The final API request will look like:
{
"input": "Hello world",
"response_format": "mp3",
"stream": true,
"speed": 1.0,
"gain": 0,
"model": "FunAudioLLM/CosyVoice2-0.5B",
"voice": "FunAudioLLM/CosyVoice2-0.5B:diana"
}
Benefits
- User-Friendly: Users can specify just the voice name (
diana,alex,bella) - Flexible: Supports both simple names and full format
- Automatic: Model prefix is added automatically
- Backward Compatible: Existing full-format configurations still work
Testing
Use test_voice_format.py to verify the voice formatting logic works correctly.
The system now properly handles the SiliconFlow voice format requirement while maintaining ease of use for configuration.