Expand description
audiofp — audio fingerprinting SDK for Rust.
audiofp extracts compact, codec-tolerant perceptual hashes from audio
so you can identify the same recording across re-encoding, modest
noise, and (for some algorithms) tempo or pitch changes — the
fundamental primitive behind systems like Shazam or AcoustID.
The crate compiles no_std + alloc by default (when the std
feature is disabled), so the DSP primitives and classical
fingerprinters can target embedded systems such as
thumbv7em-none-eabihf. The file decoder (io) and watermark
detector ([watermark]) live behind feature flags and require std.
§Quick tour
- Errors —
AfpError(#[non_exhaustive]) plus theResultalias. - Value types —
SampleRate(newtype aroundNonZeroU32withHZ_*constants),AudioBuffer(borrowed mono PCM view), andTimestampMs(ordered millisecond timestamp). - Traits —
Fingerprinterfor whole-buffer extraction,StreamingFingerprinterfor incremental extraction. Every algorithm in the crate implements both. - Classical fingerprinters —
classical::Wang(Shazam-style landmark pairs),classical::Panako(tempo-invariant triplets),classical::Haitsma(Philips robust hash bands), each with a streaming sibling. - DSP primitives —
dspexposes STFT, mel filterbank, peak picker, resampler, and tapered windows for users building their own pipelines on top ofaudiofp.
§Example
Identify a song by counting Wang hash collisions between two files:
use audiofp::classical::Wang;
use audiofp::io::decode_to_mono_at;
use audiofp::{AudioBuffer, Fingerprinter, SampleRate};
use std::collections::HashSet;
let samples = decode_to_mono_at("song.flac", 8_000)?;
let mut wang = Wang::default();
let buf = AudioBuffer { samples: &samples, rate: SampleRate::HZ_8000 };
let fp = wang.extract(buf)?;
let unique: HashSet<u32> = fp.hashes.into_iter().map(|h| h.hash).collect();
println!("{} unique landmark hashes", unique.len());§Cargo features
| Feature | Default | Description |
|---|---|---|
std | ✅ | Pulls in symphonia → io. |
watermark | Pulls in tract-onnx → [watermark]. | |
neural | Reserved for the upcoming neural fingerprinter. | |
mimalloc | Installs mimalloc::MiMalloc as the process-wide allocator. |
See USAGE.md
for the complete API guide.
Modules§
- classical
- Classical (DSP-only) fingerprinters.
- dsp
- Digital signal processing primitives.
- io
- Audio file I/O helpers.
Structs§
- Audio
Buffer - A borrowed view of a mono PCM buffer in
[-1.0, 1.0]. - Sample
Rate - A sample rate in hertz, guaranteed non-zero.
- Timestamp
Ms - A timestamp in milliseconds since the start of a stream.
Enums§
- AfpError
- All errors surfaced by
audiofp.
Constants§
- VERSION
- Crate version string, sourced from
Cargo.toml.
Traits§
- Fingerprinter
- Offline (whole-buffer) fingerprinter.
- Streaming
Fingerprinter - Streaming fingerprinter that emits zero-or-more frames per push.
Type Aliases§
- Result
- Shorthand for
core::result::Result<T, AfpError>.