back to projects

Audio Fingerprinting via Normalized Compression Distance

Algorithms & Audio ProcessingPythonFlaskAudio MatchingNCDSignal Processingcompleted2025

This project builds a music identification system grounded entirely in algorithmic information theory, developed for a university Algorithmic Information Theory course. Rather than using traditional audio fingerprinting based on spectral peak hashing, it converts audio into compact frequency representations and measures similarity using Normalized Compression Distance (NCD): NCD(x,y) = (C(xy) - min(C(x),C(y))) / max(C(x),C(y)), where C(.) is the compressed byte size of a file. The intuition is that if two frequency files compress significantly better together than separately, they share structure and likely come from the same song. An NCD near 0 indicates a strong match; near 1 indicates no relationship.

Audio is first reduced to a sparse frequency representation (.freq file) before comparison, since comparing raw audio would be dominated by silence, encoding artifacts, and sample-rate differences. The preferred extraction path uses a compiled C++ tool (GetMaxFreqs) that extracts the top-N dominant frequencies per FFT frame; a pure-Python fallback using librosa produces a richer representation including MFCCs, spectral centroid, spectral contrast, and chroma features, making the system runnable even without the compiled binary.

NCD is computed across four general-purpose compressors (gzip, bzip2, lzma, zstd), each with different sensitivity to redundancy patterns in the frequency data. Raw NCD values above 0.9 are adaptively rescaled into a wider 0.7-1.0 range, spreading out near-miss matches for more reliable rank ordering.

The system ships five interfaces. A full-featured CLI supports segment extraction, format conversion, database comparison, and audio degradation (noise, reverb, pitch shift, speed change) via both a simple librosa backend and a comprehensive SoX effects pipeline that mixes synthesized noise at the sample level for realistic degradation. A Flask web application with SSL provides browser-based microphone recording: it records 10 seconds of audio, splits it into seven overlapping 7-second segments, runs NCD matching on each, and aggregates results by vote count and mean NCD across segments — a multi-segment voting strategy that makes identification robust to a single noisy or silent window. A command-line live listener performs the same 10-second capture-and-match flow directly in the terminal.

The most sophisticated component is the automated testing framework, which systematically benchmarks identification accuracy across every meaningful variation axis: all four compressors, a battery of audio transformations (clean, white/pink noise at multiple levels, reverb, EQ, speed change, pitch shift, and combined effects), multiple segment durations (5s vs 10s), genre breakdowns, and a parameter sweep over feature extraction settings (number of frequencies and FFT window size). Results are written incrementally as each test completes, and error analysis produces confusion matrices showing which songs are systematically confused with each other.

  • ·Implemented NCD-based audio matching across four compressors (gzip, bzip2, lzma, zstd) with adaptive score rescaling for improved discrimination
  • ·Built a feature extraction pipeline with a compiled C++ backend and a librosa-based Python fallback (MFCCs, chroma, spectral contrast)
  • ·Built a Flask web app with live microphone recording and overlapping-segment voting for robust real-time identification
  • ·Designed a systematic benchmarking framework testing accuracy across compressors, durations, genres, and audio degradations (noise, reverb, pitch, speed)
  • ·Achieved a top grade of 19/20

Core

PythonC++

Audio

librosaSoXpydub

Web

FlaskSSL/TLS

Theory

Normalized Compression DistanceData Compression