From ab50ca91577e0030dbfd1ea507720d44694d10aa Mon Sep 17 00:00:00 2001 From: lanhao Date: Thu, 2 Jul 2026 21:26:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B1=86=E5=8C=85API=E5=8A=A0model=5Fty?= =?UTF-8?q?pe=3D4=E6=8C=87=E5=AE=9AICL=202.0=20+=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=9F=B3=E9=A2=91=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前缺少model_type参数可能回退到ICL 1.0导致音质不如平台调试 Co-Authored-By: Claude Opus 4.7 --- backend/app/services/doubao_service.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/app/services/doubao_service.py b/backend/app/services/doubao_service.py index 6384d1e..88d168e 100644 --- a/backend/app/services/doubao_service.py +++ b/backend/app/services/doubao_service.py @@ -1,6 +1,8 @@ import os import uuid import requests +import base64 + def synthesize_doubao(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'): """调用火山引擎豆包 Seed-ICL 2.0 语音合成 API""" @@ -11,7 +13,8 @@ def synthesize_doubao(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'): url = 'https://openspeech.bytedance.com/api/v1/tts' headers = { 'x-api-key': api_key, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'X-Api-Resource-Id': 'seed-icl-2.0' } payload = { @@ -25,11 +28,13 @@ def synthesize_doubao(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'): 'voice_type': 'S_LK0j18H72', 'encoding': 'mp3', 'speed_ratio': speed, + 'bitrate': 128000, }, 'request': { 'reqid': str(uuid.uuid4()), 'text': text, - 'operation': 'query' + 'operation': 'query', + 'model_type': 4, # ICL 2.0 模型 } } @@ -42,7 +47,6 @@ def synthesize_doubao(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'): # 豆包返回格式: {"code": 3000, "data": "base64编码的音频"} if result.get('code') == 3000 and result.get('data'): - import base64 audio_bytes = base64.b64decode(result['data']) return audio_bytes