callcut.io.load_audio🔗
- callcut.io.load_audio(fname, *, sample_rate=None, mono=True, device=None)[source]🔗
Load an audio file.
Supports common audio formats (wav, mp3, flac, ogg, etc.) and video files with audio streams (mp4, etc.) via torchcodec/FFmpeg.
- Parameters:
- fname
str|Path Path to the audio file.
- sample_rate
int|None Target sample rate in Hz. If
None, the original sample rate is preserved. If specified, the audio is resampled to this rate.- mono
bool If
True, convert multi-channel audio to mono by averaging channels.- device
str|torch.device|None Device to place the loaded tensor on (e.g.,
"cpu","cuda:0","mps"). IfNone, uses the default torch device.
- fname
- Returns:
Examples
Load an audio file at its original sample rate:
>>> waveform, sr = load_audio("recording.wav") >>> waveform.shape torch.Size([1, 32000])
Load and resample to 16 kHz:
>>> waveform, sr = load_audio("recording.wav", sample_rate=16000) >>> sr 16000
Load directly to GPU:
>>> waveform, sr = load_audio("recording.wav", device="cuda:0") >>> waveform.device device(type='cuda', index=0)