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 AudioSamples

  • Multi-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

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.

Indices and tables