AudioSamples Python Documentation
Fast, simple, and expressive audio processing for Python
AudioSamples Python is a set of Python bindings to the AudioSamples Rust crates for audio processing.
An AudioSamples object stores its sample rate, channel layout and sample type together with the samples,
so these properties do not have to be passed separately to each function.
Note
Load, save and analysis times, measured against other Python audio libraries, are in Moving from librosa.
Quick Start
Install AudioSamples:
pip install audio_samples
Generate and process audio:
import audio_samples as aus
import numpy as np
# Generate audio signals
sine = aus.generation.sine_wave(440.0, 1.0, 44100)
cosine = aus.generation.cosine_wave(880.0, 1.0, 44100)
# Mix signals with operator overloading
mixed = sine + cosine * 0.3
# Audio analysis (built-in, no external libraries needed)
print(f"RMS level: {mixed.rms():.4f}")
print(f"Spectral centroid: {mixed.spectral_centroid():.2f} Hz")
Key Features
Rust implementation: processing runs in Rust, with little Python overhead
Type Safety: Audio semantics encoded in the data structure, not external metadata
Audio Operations: signal generation, analysis and processing
NumPy Integration: conversion to and from NumPy arrays; NumPy functions and ufuncs accept
AudioSamplesMulti-channel Support: mono, stereo and multi-channel audio
Real-time Analysis: Spectral analysis, statistics, and audio metrics
Audio Effects: Fading, normalization, filtering, and more
Fast I/O: WAV and FLAC reading and writing
Why AudioSamples?
Audio as a bare array
When audio is held as a plain NumPy array, the sample rate is a separate variable, and the caller passes it to every function that needs it. Nothing checks that it belongs to the array:
# The sample rate travels separately from the samples
data, sr = read_wav('audio.wav')
mel = melspectrogram(data, sr=sr) # pass sr by hand
freqs = fft_frequencies(sr=sr, n_fft=2048) # and again
Audio that carries its properties
An AudioSamples object stores its own properties:
# The audio holds its sample rate
audio = aus.io.read('audio.wav')
stft = audio.stft(aus.StftParams(n_fft=2048, hop_size=512, window=aus.WindowType.hanning))
freqs = stft.frequencies # frequency axis from the audio's own sample rate
Learning guide
Tutorials: a short course in speech and audio processing is a short course in speech and audio processing: fourteen notebooks that check every number they state. The same course exists for the Rust crate as an illustrated book with figures computed by the library.
Coming from librosa
Moving from librosa is for someone who knows librosa and is deciding whether
to move: measurements on both sides, a pipeline side by side, the differences that
trip people up, and what is still better in librosa. Coming from librosa is the
lookup table: every librosa 1.0 function, its audio_samples equivalent and every
documented difference.
Table of Contents
Documentation
- Moving from librosa
- Coming from librosa
- Tutorials: a short course in speech and audio processing
- 01. Sampling and aliasing
- 02. Quantisation and dither
- 03. The DFT, windows and leakage
- 04. STFT and spectrograms
- 05. Convolution and FIR filters
- 06. IIR filters: design, poles, zeros and stability
- 07. Resampling
- 08. LPC, the source-filter model and formants
- 09. Pitch: autocorrelation and YIN
- 10. Cepstrum, mel and MFCC
- 11. Short-time energy, zero crossings and voice activity detection
- 12. Dynamics: compressors and limiters
- 13. Onsets and tempo
- 14. Psychoacoustics and codecs
- For instructors
- Examples
- Threads and free-threaded Python
- API Reference
- AudioSamples Core
- Spectral Analysis
- Features, Tonal, Constant-Q and Pitch Analysis
- Sequence Alignment and Decoding
- Structure and Segmentation
- Array Helpers
- Array Forms and Options
- Linear Algebra
- Mel and MFCC Inversion
- Matrix Factorisation
- Semitone Filterbank
- Tuning and Notation
- Rhythm: Onsets, Tempo and Beats
- Effects and Decomposition
- Signal Generation
- File I/O Operations
- Types
- Core Classes
- Quick Reference
Development
Citing
If you use AudioSamples in research, please cite
Audio Made Simple: A Modern Framework for Audio Processing (Geraghty, Golpayegani and Hines,
MMSys ‘26). The CITATION.cff file in the repository has the full reference.