利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(minimax): align audio containers (#1639)
Rudy Mizrahi Celekli3b43ea443eef
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 0bdfc64b..a907336d 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -71,7 +71,7 @@ jobs:- name: Run native revision-rendering testsrun: >-uv run --no-sync python -X utf8 -m coverage run --append -m pytest -q- test/services/test_video_project.py+ test/services/test_video_project.py test/services/test_minimax_output_container.py- name: Report test coveragerun: uv run --no-sync python -m coverage reportdiff --git a/app/services/voice.py b/app/services/voice.pyindex ed74737b..e71e3710 100644--- a/app/services/voice.py+++ b/app/services/voice.py@@ -2322,6 +2322,29 @@ def _write_validated_minimax_audio(audio_bytes: bytes, voice_file: str) -> floatoutput.write(audio_bytes)_validate_remote_tts_audio(temp_path)+ # MiniMax's configured response container can differ from the caller's+ # artifact extension (the task pipeline normally requests audio.mp3).+ # Keep matching payloads byte-identical; transcode supported mismatches+ # before publication so MIME/extension consumers see the promised codec.+ source_format = (+ "wav" if audio_bytes[:4] == b"RIFF" and audio_bytes[8:12] == b"WAVE"+ else "flac" if audio_bytes.startswith(b"fLaC")+ else "mp3" if audio_bytes.startswith(b"ID3") or (+ len(audio_bytes) >= 2 and audio_bytes[0] == 0xFF+ and audio_bytes[1] & 0xE0 == 0xE0+ )+ else None+ )+ output_format = output_suffix.lstrip(".").lower()+ if source_format and output_format in {"mp3", "wav", "flac"} and source_format != output_format:+ from pydub import AudioSegment++ _configure_pydub_ffmpeg(AudioSegment)+ segment = AudioSegment.from_file(io.BytesIO(audio_bytes), format=source_format)+ exported = segment.export(temp_path, format=output_format)+ if exported is not None:+ exported.close()+ _validate_remote_tts_audio(temp_path)audio_clip = AudioFileClip(temp_path)try:audio_duration = float(audio_clip.duration)diff --git a/test/services/test_minimax_output_container.py b/test/services/test_minimax_output_container.pynew file mode 100644index 00000000..741bdbc2--- /dev/null+++ b/test/services/test_minimax_output_container.py@@ -0,0 +1,45 @@+"""Native provider-payload decoding; no paid synthesis requests."""+import json+import shutil+import subprocess++import pytest++from app.services.voice import _write_validated_minimax_audio+++pytestmark = pytest.mark.skipif(+ not shutil.which("ffmpeg") or not shutil.which("ffprobe"),+ reason="native FFmpeg/FFprobe required; exercised in the post-install CI pass",+)++[email protected]("source_format,output_format,codec", [+ ("wav", "mp3", "mp3"),+ ("flac", "mp3", "mp3"),+ ("wav", "flac", "flac"),+])+def test_minimax_audio_matches_output_container(tmp_path, source_format, output_format, codec):+ source = tmp_path / ("provider." + source_format)+ subprocess.run([+ "ffmpeg", "-v", "error", "-f", "lavfi", "-i",+ "sine=frequency=440:duration=0.3", str(source),+ ], check=True)+ output = tmp_path / ("audio." + output_format)+ duration = _write_validated_minimax_audio(source.read_bytes(), str(output))+ assert 0.25 < duration < 0.5+ probe = json.loads(subprocess.check_output([+ "ffprobe", "-v", "error", "-show_streams", "-of", "json", str(output),+ ]))+ assert probe["streams"][0]["codec_name"] == codec+++def test_minimax_matching_wav_keeps_original_bytes(tmp_path):+ source = tmp_path / "provider.wav"+ subprocess.run([+ "ffmpeg", "-v", "error", "-f", "lavfi", "-i",+ "sine=frequency=440:duration=0.3", str(source),+ ], check=True)+ output = tmp_path / "audio.wav"+ _write_validated_minimax_audio(source.read_bytes(), str(output))+ assert output.read_bytes() == source.read_bytes()