diff --git a/backend/app/services/cosyvoice_service.py b/backend/app/services/cosyvoice_service.py index 321f6a1..3685493 100644 --- a/backend/app/services/cosyvoice_service.py +++ b/backend/app/services/cosyvoice_service.py @@ -13,6 +13,11 @@ def synthesize_cosyvoice(text, speed=1.0, pitch=0, volume=1.0, instruction=None) 'Content-Type': 'application/json' } + # 前端 pitch: -12~12 → API rate: 0.5~2.0(以1.0为中心) + pitch_ratio = max(0.5, min(2.0, 1.0 + pitch / 24)) + # 前端 volume: 0~10 → API volume: 0~100 + volume_int = int(max(0, min(100, volume * 10))) + payload = { 'model': 'cosyvoice-v3.5-flash', 'input': { @@ -20,6 +25,11 @@ def synthesize_cosyvoice(text, speed=1.0, pitch=0, volume=1.0, instruction=None) 'voice': 'cosyvoice-v3.5-flash-bailian-e859a6e87823419f9c6b3eefb1a97dc3', 'format': 'mp3', 'sample_rate': 32000 + }, + 'parameters': { + 'rate': max(0.5, min(2.0, speed)), + 'pitch': pitch_ratio, + 'volume': volume_int } }