{"record":{"id":"e434f12dc5249a55","repo":"microsoft/VibeVoice","slug":"load-audio-bytes-use-ffmpeg-requires-resample-true","errorCode":null,"errorMessage":"load_audio_bytes_use_ffmpeg requires resample=True","messagePattern":"load_audio_bytes_use_ffmpeg requires resample=True","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"vibevoice/processor/audio_utils.py","lineNumber":131,"sourceCode":"    Parameters\n    ----------\n    data: bytes\n        The audio data bytes\n    resample: bool\n        Whether to resample the audio (must be True)\n    target_sr: int\n        The target sample rate if resampling is requested\n\n    Returns\n    -------\n    A tuple containing:\n    - A NumPy array with the audio waveform in float32 dtype\n    - The sample rate\n    \"\"\"\n    if not resample:\n        # For stdin bytes, we don't have a cheap/robust way to probe original sr.\n        # Keep behavior explicit.\n        raise ValueError(\"load_audio_bytes_use_ffmpeg requires resample=True\")\n\n    cmd = [\n        \"ffmpeg\",\n        \"-loglevel\", \"error\",\n        \"-threads\", \"0\",\n        \"-i\", \"pipe:0\",\n        \"-f\", \"s16le\",\n        \"-ac\", \"1\",\n        \"-acodec\", \"pcm_s16le\",\n        \"-ar\", str(target_sr),\n        \"-\",\n    ]\n    out = _run_ffmpeg(cmd, stdin_bytes=data).stdout\n    audio_data = np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0\n    return audio_data, target_sr\n\n\nclass AudioNormalizer:","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/microsoft/VibeVoice/blob/94da20d98b2fa7688e9cbfaf7692ddb4954f7600/vibevoice/processor/audio_utils.py#L113-L149","documentation":"load_audio_bytes_use_ffmpeg decodes in-memory audio bytes by piping them through ffmpeg's stdin. Because ffmpeg is invoked with a fixed output sample rate (-ar target_sr), the function cannot honor resample=False — there is no way to probe the original sample rate of an anonymous byte stream without a second ffmpeg pass, so the API rejects the combination up front rather than silently returning wrong-rate audio.","triggerScenarios":"Calling load_audio_bytes_use_ffmpeg(data, resample=False, target_sr=24000) — any call with resample falsy. Typically happens when a generic audio-loading wrapper forwards a user-supplied resample flag to the bytes variant.","commonSituations":"Code that abstracts over load_audio_from_file (which allows resample=False) and load_audio_bytes_use_ffmpeg passes the same flags to both; users trying to skip resampling for speed when handling uploaded bytes or HTTP responses.","solutions":["Call with resample=True and an explicit target_sr matching your pipeline (e.g. 24000 for VibeVoice).","If you truly need native-rate audio, first write the bytes to a temp file and use the path-based loader that probes the source rate.","Audit wrapper functions so the resample flag is not blindly forwarded to the bytes-based loader."],"exampleFix":"# before\nwav, sr = load_audio_bytes_use_ffmpeg(data, resample=False, target_sr=24000)\n\n# after\nwav, sr = load_audio_bytes_use_ffmpeg(data, resample=True, target_sr=24000)","handlingStrategy":"validation","validationCode":"def load_bytes(data: bytes, target_sr: int = 24000):\n    # bytes loader only supports resampling; force it explicitly\n    return load_audio_bytes_use_ffmpeg(data, resample=True, target_sr=target_sr)","typeGuard":null,"tryCatchPattern":"try:\n    wav, sr = load_audio_bytes_use_ffmpeg(data, resample=True, target_sr=24000)\nexcept ValueError as e:\n    if 'requires resample=True' in str(e):\n        wav, sr = load_audio_bytes_use_ffmpeg(data, resample=True, target_sr=24000)\n    else:\n        raise","preventionTips":["Never forward a user-controlled resample flag into the bytes-based loader.","Standardize on resample=True with one target sample rate per pipeline (24000 for VibeVoice).","Write bytes to a temp file and use the path loader when native-rate probing is required."],"tags":["audio","ffmpeg","resampling","io"],"backgroundTag":null,"analyzedSha":"94da20d98b2fa7688e9cbfaf7692ddb4954f7600","analyzedAt":"2026-08-15T04:12:07.418Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}