fix: 豆包API加model_type=4指定ICL 2.0 + 优化音频参数

之前缺少model_type参数可能回退到ICL 1.0导致音质不如平台调试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
lanhao
2026-07-02 21:26:34 +08:00
parent 54cb8d14ba
commit ab50ca9157
+7 -3
View File
@@ -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