{"record":{"id":"687bf7908ab5dd29","repo":"unslothai/unsloth","slug":"minimax-h3-reference-audio-runs-up-to-h3-ref-vide","errorCode":null,"errorMessage":"MiniMax-H3 reference audio runs up to {H3_REF_VIDEO_MAX_SECONDS:g} seconds; this one is longer. Trim it first.","messagePattern":"MiniMax-H3 reference audio runs up to (.+?) seconds; this one is longer\\. Trim it first\\.","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/video_minimax_h3.py","lineNumber":476,"sourceCode":"    ``H3_REF_VIDEO_MAX_SECONDS`` anyway, so anything past it is unusable rather than merely large:\n    refuse it with the same message the video guard uses instead of decoding it first.\"\"\"\n    import av\n\n    stream = container.streams.audio[0]\n    sample_rate = int(stream.codec_context.sample_rate or 48_000)\n    # One resampler pass gives interleaved float32 whatever the source layout/format was.\n    resampler = av.AudioResampler(format = \"flt\", layout = stream.layout.name, rate = sample_rate)\n    channels = len(stream.layout.channels)\n    max_samples = math.floor(H3_REF_VIDEO_MAX_SECONDS * sample_rate + 1e-6)\n    chunks = []\n    total = 0\n\n    def _take(resampled: Any) -> None:\n        nonlocal total\n        block = resampled.to_ndarray().reshape(-1, channels)\n        total += block.shape[0]\n        if total > max_samples:\n            raise ValueError(\n                f\"MiniMax-H3 reference audio runs up to {H3_REF_VIDEO_MAX_SECONDS:g} seconds; \"\n                f\"this one is longer. Trim it first.\"\n            )\n        chunks.append(block)\n\n    for frame in container.decode(audio = 0):\n        for resampled in resampler.resample(frame):\n            _take(resampled)\n    for resampled in resampler.resample(None):\n        _take(resampled)\n    if not chunks:\n        return None, None\n    return np.concatenate(chunks, axis = 0).astype(\"float32\"), sample_rate\n\n\ndef write_h3_reference_wav(path: Path, waveform: Any, sample_rate: int) -> None:\n    \"\"\"Write a reference waveform as the 16-bit PCM WAV sd-cli's --ref-audio loader reads.\"\"\"\n    import wave","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/video_minimax_h3.py#L458-L494","documentation":"Inside _decode_audio_stream, the _take callback accumulates resampled samples and raises ValueError once total exceeds max_samples = floor(H3_REF_VIDEO_MAX_SECONDS * sample_rate + 1e-6), i.e. the audio runs past the model's 15s reference window. The check is incremental during decode because encoded size says nothing about decoded size (a 32 MiB MP3 can be over half an hour), so refusing early avoids building a multi-GB float32 array only to reject it. Uses the same message family as the video-path guards.","triggerScenarios":"Uploading a full song or podcast episode as an H3 audio reference; a 30-minute 32 MiB MP3 (the request-limit-sized example from the code); any audio whose duration exceeds 15s.","commonSituations":"Users supplying whole tracks instead of the relevant snippet; pipelines passing untrimmed voice-over masters; assuming the request size limit implies a duration limit.","solutions":["Trim the audio to at most 15s before upload: ffmpeg -ss 30 -t 10 -i song.mp3 ref.mp3.","Show the 15s cap in the upload UI and validate duration client-side.","Extract just the segment aligned with the video reference if you are building AV-conditioned generations."],"exampleFix":"# before: whole 3-minute track -> ValueError\nupload_audio_reference(open(\"song.mp3\", \"rb\").read())\n\n# after: cut the 10s hook\nffmpeg -ss 42 -t 10 -i song.mp3 -c:a libmp3lame ref.mp3","handlingStrategy":"validation","validationCode":"import av, io, math\n\nH3_REF_VIDEO_MAX_SECONDS = 15.0\n\nwith av.open(io.BytesIO(blob)) as c:\n    s = c.streams.audio[0]\n    rate = s.rate or s.codec_context.sample_rate\n    samples = s.duration or 0  # stream duration is in samples for audio\n    if samples and samples / rate > H3_REF_VIDEO_MAX_SECONDS:\n        raise ValueError(\"trim reference audio to <= 15s\")","typeGuard":null,"tryCatchPattern":"try:\n    wf, sr = decode_h3_reference_audio(blob)\nexcept ValueError as e:\n    if \"reference audio runs up to\" in str(e):\n        return HTTPException(400, \"trim the audio to at most 15s\") from e\n    raise","preventionTips":["Trim audio to <= 15s (same window as video references) before upload.","Never assume request-size limits imply duration limits — MP3 expands ~60x decoded.","Extract the exact snippet matching the video reference segment when conditioning A/V together."],"tags":["audio","minimax-h3","upload","duration","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}