Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(minimax): reject unsupported raw PCM before synthesis

Rudy Celeklie3a677434679
diff --git a/app/services/voice.py b/app/services/voice.py
index 0e12c486..ed74737b 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -2365,8 +2365,8 @@ def minimax_tts(text: str, voice_id: str, voice_rate: float, voice_file: str, vo
logger.error(f"Invalid MiniMax TTS audio setting: {str(exc)}")
return None
audio_format = str(settings.get("audio_format", "mp3") or "mp3").strip()
- if audio_format not in {"mp3", "wav", "flac", "pcm"}:
- logger.error(f"Unsupported MiniMax TTS audio format: {audio_format}")
+ if audio_format not in {"mp3", "wav", "flac"}:
+ logger.error(f"Unsupported MiniMax TTS audio format: {audio_format}; choose mp3, wav, or flac")
return None
payload = {
"model": model, "text": text, "stream": False, "language_boost": "auto", "output_format": "hex",
diff --git a/config.example.toml b/config.example.toml
index 4d2f1265..5156f398 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -630,6 +630,8 @@ model_id = "speech-2.8-hd"
voice_id = "English_expressive_narrator"
sample_rate = 32000
bitrate = 128000
+# Container formats supported by local validation: mp3, wav, flac.
+# Headerless PCM is rejected before synthesis.
audio_format = "mp3"
channel = 1
pitch = 0
diff --git a/test/services/test_minimax_pcm_preflight.py b/test/services/test_minimax_pcm_preflight.py
new file mode 100644
index 00000000..b77ed487
--- /dev/null
+++ b/test/services/test_minimax_pcm_preflight.py
@@ -0,0 +1,50 @@
+"""Do not submit raw audio formats the local validation path cannot decode."""
+
+import io
+import wave
+from unittest.mock import Mock, patch
+
+import numpy as np
+import pytest
+
+from app.services import voice
+
+
+def _pcm():
+ samples = np.sin(np.arange(6400) * (2 * np.pi * 440 / 32000)) * 10000
+ return samples.astype("<i2").tobytes()
+
+
+def test_pcm_setting_fails_before_paid_submission(tmp_path):
+ output = tmp_path / "speech.mp3"
+ output.write_bytes(b"previous narration")
+ response = Mock(status_code=200)
+ response.json.return_value = {
+ "base_resp": {"status_code": 0},
+ "data": {"status": 2, "audio": _pcm().hex()},
+ }
+ with patch.dict(voice.config.minimax_tts, {"api_key": "fixture", "audio_format": "pcm"}), \
+ patch.object(voice.requests, "post", return_value=response) as post:
+ assert voice.minimax_tts("Hello.", "voice-id", 1, str(output)) is None
+ post.assert_not_called()
+ assert output.read_bytes() == b"previous narration"
+
+
+def test_native_container_validator_rejects_headerless_pcm(tmp_path):
+ output = tmp_path / "speech.mp3"
+ with pytest.raises(ValueError, match="fully decoded"):
+ voice._write_validated_minimax_audio(_pcm(), str(output))
+ assert not output.exists()
+
+
+def test_native_container_audio_still_publishes(tmp_path):
+ wav = io.BytesIO()
+ with wave.open(wav, "wb") as audio:
+ audio.setnchannels(1)
+ audio.setsampwidth(2)
+ audio.setframerate(32000)
+ audio.writeframes(_pcm())
+ output = tmp_path / "speech.wav"
+ duration = voice._write_validated_minimax_audio(wav.getvalue(), str(output))
+ assert 0.19 <= duration <= 0.21
+ assert output.read_bytes() == wav.getvalue()