Audio fingerprinting engine built in Python and PostgreSQL.
This project identifies songs by converting audio into compact acoustic fingerprints through a pipeline consisting of STFT preprocessing, spectral peak detection, constellation mapping, combinatorial hash generation, and temporal coherence matching. The engine supports both file-based and live microphone recognition while visualizing every stage of the fingerprinting process.
This repository is an independent, open-source implementation inspired by the algorithmic principles presented in Avery Li-Chun Wang's 2003 paper, An Industrial-Strength Audio Search Algorithm. It recreates the published DSP pipelineβincluding constellation mapping, combinatorial hashing, and temporal histogram alignmentβusing a modern Python and PostgreSQL stack for educational exploration and analysis.
This project is not affiliated with Shazam and is not a reproduction of its proprietary implementation. The commercial service incorporates proprietary optimizations, distributed infrastructure, and production engineering that are not publicly documented and are therefore beyond the scope of this repository. Instead, this repository serves as a transparent reference implementation for studying audio fingerprinting algorithms and digital signal processing techniques.
- Technical Highlights
- Tech Stack
- Audio Fingerprinting Pipeline
- Desktop Application
- Setup & Installation
- Usage
- Project Structure
- Database Architecture
- License
- β‘ Decoupled DSP & Database Pipeline: Stateless processing modules operate on NumPy arrays and standard Python data structures, making the engine straightforward to integrate into FastAPI, gRPC, or other backend services.
- πΉ Live System Audio Capture: Captures system audio through WASAPI loopback for real-time song identification without requiring external microphones.
- π 64-bit Acoustic Fingerprinting: Generates compact combinatorial hashes from constellation-map peak pairs, enabling robust and efficient song identification using integer-based database lookups.
- ποΈ PostgreSQL Fingerprint Database: Designed to efficiently store and query millions of 64-bit acoustic fingerprints using indexed BIGINT lookups and optimized batch operations.
- π Two-Stage Temporal Matching: Combines fingerprint vote counting with temporal offset histogram alignment to verify candidate matches and reject random hash collisions.
- π‘οΈ False Positive Rejection: Uses SNR-based confidence scoring together with an ambiguity filter that rejects matches when the runner-up score falls within a configurable ratio threshold.
- π Dynamic Pipeline Visualizer: Incorporates a six-panel diagnostic visualization including the waveform, spectrogram, constellation map, vote tally, clip localization, and temporal offset histogram for every identification.
The identification engine follows a multi-stage DSP pipeline:
End-to-end visualization of the fingerprinting pipeline, showing the major processing stages used during song identification.
π See METHODOLOGY.md for a complete explanation of every stageβincluding the underlying mathematics, DSP concepts, implementation details, and individual visualizations
The project includes a modern desktop application built with CustomTkinter for indexing songs, identifying music from audio files or live system audio, and visualizing every stage of the fingerprinting pipeline.
- Real-Time Recognition: Identify songs from uploaded audio files or live system audio.
- Responsive Interface: Background threading keeps the UI responsive during fingerprint generation and database queries.
- Pipeline Visualization: Inspect waveform, spectrogram, constellation map, timeline localization, vote distribution, and offset histograms for every match.
- Embedded Analysis: Matplotlib figures are rendered directly inside the application for interactive inspection.
- Live Database Metrics: Displays indexed song and fingerprint counts retrieved from PostgreSQL.
git clone https://github.com/rhthm/audio-fingerprint-engine.git
cd audio-fingerprint-engineEnsure the following software is installed before continuing:
-
Python 3.10+
-
Docker Desktop (recommended)
or
-
PostgreSQL 14+ (only for manual setup)
Download links:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# Linux / macOS
source venv/bin/activate
# Windows (Command Prompt)
venv\Scripts\activate
# Install project dependencies
pip install -r requirements.txtdocker compose up -dThis will automatically:
- Start PostgreSQL
- Create the
audio_fingerprint_dbdatabase - Initialize the schema from
database/schema.sql - Persist your database using a Docker volume
Click to expand setup instructions
Ensure the PostgreSQL server is installed and running before executing the commands below.
# Create the database
psql -U postgres -c "CREATE DATABASE audio_fingerprint_db;"
# Initialize the schema
psql -U postgres -d audio_fingerprint_db -f database/schema.sqlCreate a .env file in the project root (refer to .env.template):
DB_HOST=localhost
DB_PORT=5432
DB_NAME=audio_fingerprint_db
DB_USER=postgres
DB_PASSWORD=your_secure_passwordDrop your reference music files (.mp3, .wav, .flac, .ogg, .m4a) into data/songs/ (or any other folder of your choice). If your audio files do not already contain embedded metadata, name them using the format Artist - Title.mp3.
Note: Embedded metadata (ID3/Vorbis/MP4 tags) always takes priority. When metadata is unavailable, the engine automatically extracts the artist and title from filenames following the format
Artist - Title.ext. Files without embedded metadata or this naming convention are still indexed, but will appear using the filename and Unknown Artist.
Run the ingestion pipeline:
python scripts/ingest.py --folder data/songsTip: The
--folderargument can point to any directory containing your audio library.
To rebuild the fingerprint database from scratch, use the --reset flag:
python scripts/ingest.py --folder data/songs/ --resetpython ui/app.pyFor users who prefer a terminal workflow, the engine supports both saved audio file identification and live recognition directly from microphone or system audio:
python scripts/recognize.py --file path/to/clip.mp3To view available input devices:
python scripts/recognize.py --list-devicesStart live recognition:
python scripts/recognize.py --duration 8audio-fingerprint-engine/
βββ assets/
β βββ demo.gif
β βββ icon.png
β βββ ui.png
β βββ pipeline.png
β βββ waveform.png
β βββ spectrogram.png
β βββ constellation.png
β βββ hash_histogram.png
β βββ offset_histogram.png
β
βββ data/
β βββ samples/
β β βββ .gitkeep
β βββ songs/
β βββ .gitkeep
β
βββ database/
β βββ db.py
β βββ schema.sql
β
βββ engine/
β βββ preprocessor.py
β βββ constellation_map.py
β βββ fingerprint.py
β βββ fingerprint_encoding.py
β βββ matcher.py
β
βββ scripts/
β βββ ingest.py
β βββ recognize.py
β
βββ ui/
β βββ app.py
β βββ config.py
β
βββ visualization/
β βββ plots.py
β βββ config.py
β
βββ .dockerignore
βββ .env.template
βββ .gitignore
βββ docker-compose.yml
βββ LICENSE
βββ README.md
βββ METHODOLOGY.md
βββ DATABASE.md
βββ requirements.txt
The engine stores and queries over 2.36 million acoustic fingerprints using a highly optimized single-node PostgreSQL instance.
- Dataset Scale: Stores 2,361,758 fingerprints across 74 indexed tracks using compact 64-bit (
BIGINT) acoustic hashes. - Covering Index: Uses
(hash_val, song_id) INCLUDE (frame_offset)to execute lookups as Index Only Scans, eliminating heap access. - Measured Performance: Completes a realistic 700-hash fingerprint lookup in 2.322 ms, verified using
EXPLAIN (ANALYZE, BUFFERS). - Stable Query Plans: Uses PostgreSQL array binding (
= ANY(%s)) so the SQL statement remains constant regardless of batch size. - Atomic Data Ingestion: Relies on
INSERT ... ON CONFLICTtogether with PostgreSQL transaction metadata (xmax) to perform race-condition-safe upserts in a single database round trip.
π See DATABASE.md for the complete database architecture, schema design, indexing strategy, benchmark results, execution plans, and query implementation details.
This project is licensed under the MIT License - see the LICENSE file for details.
Built by rhthm.


