Skip to main content

Crate audiofp

Crate audiofp 

Source
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

  • ErrorsAfpError (#[non_exhaustive]) plus the Result alias.
  • Value typesSampleRate (newtype around NonZeroU32 with HZ_* constants), AudioBuffer (borrowed mono PCM view), and TimestampMs (ordered millisecond timestamp).
  • TraitsFingerprinter for whole-buffer extraction, StreamingFingerprinter for incremental extraction. Every algorithm in the crate implements both.
  • Classical fingerprintersclassical::Wang (Shazam-style landmark pairs), classical::Panako (tempo-invariant triplets), classical::Haitsma (Philips robust hash bands), each with a streaming sibling.
  • DSP primitivesdsp exposes STFT, mel filterbank, peak picker, resampler, and tapered windows for users building their own pipelines on top of audiofp.

§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

FeatureDefaultDescription
stdPulls in symphoniaio.
watermarkPulls in tract-onnx → [watermark].
neuralGeneric ONNX log-mel embedder ([neural]); pulls in [tract-onnx].
mimallocInstalls 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§

AudioBuffer
A borrowed view of a mono PCM buffer in [-1.0, 1.0].
SampleRate
A sample rate in hertz, guaranteed non-zero.
TimestampMs
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.
StreamingFingerprinter
Streaming fingerprinter that emits zero-or-more frames per push.

Type Aliases§

Result
Shorthand for core::result::Result<T, AfpError>.