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