Streaming audio I/O and high-level processing for NumPy
Maintained. Last release 3 months ago, commits in 2 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install audiolabaudiolab
audiolab is a compact Python toolkit for loading, transforming, streaming, inspecting, and saving audio. It accepts local files, URLs, encoded bytes, and file-like objects, and returns NumPy arrays with a consistent channels-first layout.
Common operations such as resampling, mono conversion, dtype conversion, speed changes, and pitch shifts use optimized processing paths automatically. You describe the result you want; audiolab chooses the implementation.
Highlights
- Decode WAV, FLAC, MP3, AAC, M4A, WebM, and other formats supported by the installed audio libraries.
- Read from paths, URLs,
bytes, and binary file-like objects. - Resample, convert to mono, change dtype, alter speed, and shift pitch through one high-level API.
- Process complete files, decoded PCM chunks, or incoming encoded byte streams.
- Apply advanced audio filters when the high-level transforms are not enough.
- Write NumPy audio to files and file-like objects.
- Inspect audio metadata from Python or the
audicommand.
Installation
pip install audiolab
Python 3.10 or newer is required.
Quick start
Load and transform audio
import numpy as np
from audiolab import load_audio
audio, sample_rate = load_audio(
"speech.mp3",
offset=7.0,
duration=23.0,
sample_rate=16_000,
to_mono=True,
dtype=np.float32,
)
print(audio.shape) # (channels, samples); here channels == 1
print(sample_rate) # 16000
By default, decoded arrays are two-dimensional and channels-first: (channels, samples). Set always_2d=False if you want mono audio returned as a one-dimensional array.
Change speed and pitch
from audiolab import load_audio
# 25% faster, with the original pitch preserved.
faster, sample_rate = load_audio("speech.wav", speed=1.25)
# Two semitones higher, with approximately the original duration preserved.
higher, sample_rate = load_audio("speech.wav", pitch_shift=2)
# Both operations can be combined.
transformed, sample_rate = load_audio("speech.wav", speed=0.9, pitch_shift=-3)