From c44fa711a799ba7f433511d8c2f7bc3056c342a7 Mon Sep 17 00:00:00 2001 From: lanhao Date: Thu, 2 Jul 2026 21:44:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20CosyVoice=E8=A1=A5=E5=85=A8=E8=AF=AD?= =?UTF-8?q?=E9=80=9F/=E5=A3=B0=E8=B0=83/=E9=9F=B3=E9=87=8F=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 三个引擎的滑块参数现在全部生效 Co-Authored-By: Claude Opus 4.7 --- backend/app/services/cosyvoice_service.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 } }