Initial commit: 军事科技AI配音系统 v1.0
- Flask backend with MiniMax and CosyVoice TTS engines - Frontend UI with emotion tags, speed/pitch/volume controls - Nginx reverse proxy configuration - Dual engine support (MiniMax speech-2.8-hd, CosyVoice v3.5-flash)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
import base64
|
||||
import requests
|
||||
from io import BytesIO
|
||||
|
||||
def synthesize_minimax(text, speed=1.0, pitch=0, volume=1.0):
|
||||
"""调用MiniMax TTS API"""
|
||||
api_key = os.getenv('MINIMAX_API_KEY', '')
|
||||
if not api_key:
|
||||
raise ValueError('MINIMAX_API_KEY未设置')
|
||||
|
||||
# 将音量映射到0-100
|
||||
volume_int = int(volume * 100)
|
||||
|
||||
url = 'https://api.minimax.chat/v1/t2a_v2'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {api_key}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
payload = {
|
||||
'model': 'speech-2.8-hd',
|
||||
'text': text,
|
||||
'stream': False,
|
||||
'voice_setting': {
|
||||
'voice_id': 'lanhao_military_tech',
|
||||
'speed': speed,
|
||||
'vol': volume_int,
|
||||
'pitch': pitch,
|
||||
},
|
||||
'audio_setting': {
|
||||
'audio_sample_rate': 32000,
|
||||
'bitrate': 128000,
|
||||
'format': 'mp3'
|
||||
}
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers, timeout=60)
|
||||
|
||||
if response.status_code != 200:
|
||||
raise Exception(f'MiniMax API错误: {response.status_code} - {response.text}')
|
||||
|
||||
result = response.json()
|
||||
|
||||
if 'data' in result and 'audio' in result['data']:
|
||||
audio_hex = result['data']['audio']
|
||||
audio_bytes = bytes.fromhex(audio_hex)
|
||||
return audio_bytes
|
||||
|
||||
raise Exception(f'MiniMax返回格式异常: {result}')
|
||||
Reference in New Issue
Block a user