AudioSamples
Fast, simple, and expressive audio in Rust
Overview
Most audio libraries expose samples as raw numeric buffers. In Python,
audio is typically represented as a NumPy array whose dtype is
explicit, but whose meaning is not: sample rate, amplitude range,
memory interleaving, and PCM versus floating-point semantics are tracked
externally, if at all. In Rust, the situation is reversed but not
resolved. Libraries provide fast and safe low-level primitives, yet
users are still responsible for managing raw buffers, writing ad hoc
conversion code, and manually preserving invariants across crates.
AudioSamples closes this gap with a strongly typed audio representation that encodes sample format, numeric domain, channel structure, and layout in the type system. All operations preserve or explicitly update these invariants, supporting both exploratory workflows and system-level use without requiring users to remember hidden conventions or reimplement common audio logic.
Installation
The default feature set (bare-bones) includes only the core types and
traits. Add features for the operations you need — see Features.
Quick Start
Generating and mixing signals
use ;
use Duration;
Spectral transforms
Enable the transforms feature:
use ;
use ;
use Duration;
Creating AudioSamples
AudioSamples creation returns a Result because validity requires
consistent buffer length, channel count, and sample rate. The
sample_rate! macro and non_empty_vec! guarantee invariants at
construction:
use ;
use non_empty_vec;
let audio = from_mono_vec;
For multi-channel audio:
use ;
use array;
let stereo = new_multi_channel.unwrap;
Features
The default feature is bare-bones — the core types and traits with no
optional dependencies. Enable features as needed:
Core operations
| Feature | Description |
|---|---|
statistics |
Descriptive statistics: peak, RMS, mean, variance |
processing |
Normalization, scaling, clipping (requires statistics) |
editing |
Trim, pad, reverse, perturb, concatenate (requires statistics, random-generation) |
channels |
Interleave/deinterleave, mono↔stereo conversion |
iir-filtering |
IIR filter design and application |
parametric-eq |
Parametric EQ bands (requires iir-filtering) |
dynamic-range |
Compression, limiting, expansion |
envelopes |
Amplitude, RMS, and attack-decay envelopes |
vad |
Voice activity detection |
Spectral and analysis
| Feature | Description |
|---|---|
transforms |
FFT, STFT, MFCC, chromagram, CQT, PSD |
pitch-analysis |
YIN and autocorrelation pitch detection (requires transforms) |
onset-detection |
Onset detection (requires transforms, peak-picking, processing) |
beat-tracking |
Beat tracking |
peak-picking |
Peak picking on onset envelopes |
decomposition |
Audio decomposition (requires onset-detection) |
Utility
| Feature | Description |
|---|---|
resampling |
Sample-rate conversion via rubato |
random-generation |
Noise and random audio generation |
fixed-size-audio |
Fixed-size buffer support (no heap allocation) |
plotting |
Interactive HTML plots via plotly |
static-plots |
PNG/SVG export (requires plotting — see PLOTTING.md) |
simd |
SIMD acceleration (nightly only) |
Bundles
| Feature | Description |
|---|---|
full |
All features |
full_no_plotting |
All features except plotting |
Documentation
Full API documentation: https://docs.rs/audio_samples
Examples
The repository includes runnable examples in examples/. Each is
self-contained and annotated with the required feature flags.
Additional demos:
Companion Crates
audio_samples_io— Audio file decoding and encodingaudio_samples_playback— Device-level playbackaudio_samples_python— Python bindingsspectrograms— Spectrogram and time–frequency transforms (used by thetransformsfeature)i24— 24-bit signed integer type for Rustdtmf_tones—no_stdDTMF keypad frequencies
License
MIT License
Citing
If you use AudioSamples in research, please cite:
Contributing
Contributions are welcome. Please submit a pull request and see CONTRIBUTING.md for guidance.