mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-21 22:18:12 +02:00
fix(minimax): correct API payload and add TTS debug logging
- Fix model name: speech-2.8-hd -> speech-02-hd - Fix bitrate: 128 -> 128000 bps - Add channel, speed, pitch, vol to voice/audio settings - Handle binary audio response (Content-Type: audio/*) - Fallback audio field lookup: data.data.audio || data.audio - Add background job log: ttsProvider + hasMinimaxKey - Log full FFmpeg request body (text truncated, key masked)
This commit is contained in:
1 parent
35cf21209f
commit
211b7dc272
3 files changed
+39
-10
No files matched your search
+32
-9
@@ -202,21 +202,44 @@ def generate_tts_minimax(text: str, voice_id: str, api_key: str, audio_path: Pat
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
payload = {
|
||||
"model": "speech-2.8-hd",
|
||||
"model": "speech-02-hd",
|
||||
"text": text,
|
||||
"voice_setting": {"voice_id": voice_id},
|
||||
"audio_setting": {"format": "mp3", "sample_rate": 24000, "bitrate": 128},
|
||||
"voice_setting": {
|
||||
"voice_id": voice_id,
|
||||
"speed": 1.0,
|
||||
"pitch": 0,
|
||||
"vol": 1.0,
|
||||
},
|
||||
"audio_setting": {
|
||||
"format": "mp3",
|
||||
"sample_rate": 32000,
|
||||
"bitrate": 128000,
|
||||
"channel": 1,
|
||||
},
|
||||
}
|
||||
print(f"🔊 Minimax API request: voice_id={voice_id}, model=speech-02-hd, text_len={len(text)}")
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=60)
|
||||
print(f"🔊 Minimax API response: status={response.status_code}, content_type={response.headers.get('Content-Type', '?')}")
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
base_resp = data.get("base_resp", {})
|
||||
if base_resp.get("status_code") != 0:
|
||||
raise Exception(f"Minimax API error: {base_resp.get('status_msg', 'unknown error')}")
|
||||
content_type = response.headers.get("Content-Type", "")
|
||||
if "audio" in content_type:
|
||||
# Direct binary audio response
|
||||
audio_bytes = response.content
|
||||
print(f"🔊 Minimax returned binary audio directly ({len(audio_bytes)} bytes)")
|
||||
else:
|
||||
data = response.json()
|
||||
print(f"🔊 Minimax JSON response keys: {list(data.keys())}")
|
||||
|
||||
base_resp = data.get("base_resp", {})
|
||||
if base_resp.get("status_code") != 0:
|
||||
raise Exception(f"Minimax API error: {base_resp.get('status_msg', 'unknown error')}")
|
||||
|
||||
audio_raw = data.get("data", {}).get("audio") or data.get("audio")
|
||||
if not audio_raw:
|
||||
raise Exception(f"Minimax API: no audio field in response. Keys: {list(data.keys())}")
|
||||
audio_bytes = bytes.fromhex(audio_raw)
|
||||
|
||||
audio_hex = data["data"]["audio"]
|
||||
audio_bytes = bytes.fromhex(audio_hex)
|
||||
with open(audio_path, "wb") as f:
|
||||
f.write(audio_bytes)
|
||||
print(f"✅ Minimax TTS audio saved: {audio_path.stat().st_size} bytes")
|
||||
|
||||
Reference in new issue
Block a user