vllm.multimodal.media.audio
¶
Classes:
-
AudioEmbeddingMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
AudioMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
Functions:
-
load_audio–Load audio using the selected decoding backend.
-
load_audio_pyav–Load an audio file using PyAV (FFmpeg), returning float32 mono waveform.
-
load_audio_soundfile–Load audio via soundfile.
-
load_audio_torchcodec–Load an audio file using torchcodec, returning a float32 waveform.
AudioEmbeddingMediaIO
¶
AudioMediaIO
¶
_CorruptAudioError
¶
Bases: ValueError
torchcodec could not open or decode the input.
Kept distinct from the duration/memory guard ValueErrors so that
load_audio(backend="auto") can retry with soundfile, whose decoders
(e.g. mpg123 for MP3) resync past bad frames that FFmpeg aborts on.
_normalize_decode_limits(max_duration_s, max_decode_bytes)
¶
Treat documented zero-valued audio decode limits as disabled.
load_audio(path, *, sr=22050, mono=True, max_duration_s=None, max_decode_bytes=None, backend=None)
¶
Load audio using the selected decoding backend.
Parameters:
-
(path¶BytesIO | Path | str) –Audio file path or in-memory buffer.
-
(sr¶float | None, default:22050) –Target sample rate, or None to keep the native rate.
-
(mono¶bool, default:True) –Whether to downmix to a single channel.
-
(max_duration_s¶float | None, default:None) –Reject audio longer than this many seconds.
-
(max_decode_bytes¶int | None, default:None) –Reject audio that would decode to more than this many bytes.
-
(backend¶str | None, default:None) –One of
AUDIO_BACKENDS.None(default) selects"auto", which tries torchcodec, then falls back to the soundfile → PyAV chain (only to soundfile if torchcodec fails to decode the input); the other values select a single backend with no fallback.
load_audio_pyav(path, *, sr=22050, mono=True, max_duration_s=None, max_decode_bytes=None)
¶
Load an audio file using PyAV (FFmpeg), returning float32 mono waveform.
Decodes the audio stream at its native sample rate. Channel reduction to
mono is performed by averaging across channels. Resampling to a
model-specific rate is left to the downstream AudioResampler.
Parameters:
-
(path¶BytesIO | Path | str) –A
BytesIObuffer, a filesystemPath, or a string path. -
(sr¶float | None, default:22050) –Target sample rate, or None to keep the native rate.
-
(mono¶bool, default:True) –Whether to average the channels down to mono.
-
(max_decode_bytes¶int | None, default:None) –If set, abort decoding once this many bytes have been read from the source.
-
(max_duration_s¶float | None, default:None) –If set, abort decoding once the accumulated sample count exceeds this many seconds of audio. Prevents decompression-bomb attacks where a small compressed file expands into gigabytes of PCM.
Returns:
load_audio_soundfile(path, *, sr=22050, mono=True, max_duration_s=None, max_decode_bytes=None)
¶
Load audio via soundfile.
load_audio_torchcodec(path, *, sr=22050, mono=True, max_duration_s=None, max_decode_bytes=None)
¶
Load an audio file using torchcodec, returning a float32 waveform.
Unlike load_audio_pyav, which drives FFmpeg through a per-frame
Python generator, torchcodec decodes inside a single call that releases
the GIL. Resampling also happens in C++ (sample_rate=sr), so this
backend never falls back to PyAV or libsndfile.
Parameters:
-
(path¶BytesIO | Path | str) –A
BytesIObuffer, a filesystemPath, or a string path. -
(sr¶float | None, default:22050) –Output sample rate;
Nonekeeps the native rate. Must be an integer when set. -
(mono¶bool, default:True) –Average channels down to a single channel.
-
(max_duration_s¶float | None, default:None) –Reject audio longer than this many seconds. Prevents decompression-bomb attacks where a small compressed file expands into gigabytes of PCM.
-
(max_decode_bytes¶int | None, default:None) –Reject audio whose decoded PCM exceeds this many bytes.
Returns: