How I Built an Audio Fingerprinting System in Python using Dejavu
Introduction
How I Built an Audio Fingerprinting System in Python using Dejavu
Introduction
Ever wondered how apps like Shazam identify a song in seconds? The magic lies in audio fingerprinting — a technique that encodes unique sound features into digital “fingerprints.” In this post, I’ll show you how I built an audio recognition system in Python using an open-source library called Dejavu. By the end, you’ll understand how sound can be recognized just like a human fingerprint.
What is Audio Fingerprinting?
Audio fingerprinting is a method to identify audio content by analyzing its unique patterns. It doesn’t store the whole sound — instead, it creates a compact signature of the file based on frequency peaks and time intervals. This helps detect a match even if the audio is distorted or noisy.
How Dejavu Works
Dejavu is an open-source Python library that implements audio fingerprinting and recognition. It works in four major steps:
- Fingerprint Generation: Converts audio files into fingerprints using FFT (Fast Fourier Transform).
- Database Storage: Saves those fingerprints in a database (MySQL, PostgreSQL, or SQLite).
- Audio Recognition: Captures or uploads an audio snippet and generates its fingerprint.
- Matching: Compares the snippet’s fingerprint with the database and finds the closest match.
Implementation
Step 1: Install Dependencies
pip install PyDejavu sudo apt-get install ffmpeg
Step 2: Configure Database
{ “database”: { “host”: “127.0.0.1”, “user”: “root”, “passwd”: “password”, “db”: “dejavu” } }
Step 3: Fingerprint Your Songs
from dejavu import Dejavu
djv = Dejavu(config) djv.fingerprint_directory(“mp3”, [“.mp3”])
Step 4: Recognize a Song
song = djv.recognize(FileRecognizer, “test.mp3”) print(f”Recognized: {song}”)
⚠️ Python 3 Compatibility Note
The original Dejavu library was developed for Python 2, so a few things may break if you’re using Python 3.
Before running the code, make sure to:
Option 1 Use a Python 3–compatible fork (you can find several updated forks on GitHub by searching “Dejavu Python 3 fork”).
Option 2
1.Replace old-style print statements → use print() instead.
2.Update any .iteritems() → .items() and .itervalues() → .values() in the source code if needed.
3.Check for byte/string conversion issues, especially when hashing or storing fingerprints (use .encode() or .decode() accordingly).
4.Verify your MySQL connector supports Python 3 (mysql-connector-python works fine).
5. Change some Imports
database_sql.py:
i.from itertools import zip_longest as izip_longest
ii.import queue as Queue
6.Iterators vs Lists
Problem: Functions like find_matches() returned iterators in Python 3, which behave differently from lists.
Fix: Wrapped iterators with list() to ensure compatibility.
7.xrange() Removal
Problem: xrange() was removed in Python 3; range() now behaves like xrange() in Python 2.
Fix: Replaced xrange() with range().
8.Division Behavior
Problem: Integer division in Python 2 truncates, whereas Python 3 returns a float.
Fix: Used // for integer division to maintain consistency.
9.Subtraction behaviour
diff = peak1 — peak2
change it to : diff = np.bitwise_xor(peak1, peak2)
10.filter() and map() Return Types
Problem: These functions now return iterators instead of lists.
Fix: Wrapped results with list() where necessary.
These are some of the problem i faced and solved it so make sure u change all the above mentioned changes in the .venv dejavu foulder
Testing and Results
When I tested the model, Dejavu successfully identified songs even with 30% noise distortion and short 15-second clips. However, recognition speed and accuracy depend on the size of your database and how well the audio is preprocessed.
Applications
- Music identification (like Shazam)
- Copyright detection
- Video content tracking
- Forensic and media verification
Conclusion
Audio fingerprinting shows how powerful simple frequency analysis can be. Libraries like Dejavu make it incredibly easy to experiment with music recognition and sound identification.
If you’re into AI + signal processing, this is a great project to explore and even expand into a real-world app.
메타데이터
- post_id
- 88fa5a5fe744
- slug
- how-i-built-an-audio-fingerprinting-system-in-python-using-dejavu-88fa5a5fe744
- url
- https://medium.com/@varunpm132109/how-i-built-an-audio-fingerprinting-system-in-python-using-dejavu-88fa5a5fe744
- canonical_url
- https://medium.com/@varunpm132109/how-i-built-an-audio-fingerprinting-system-in-python-using-dejavu-88fa5a5fe744
- author_url
- https://medium.com/@varunpm132109
- status
- ok
- fetched_at
- 2026-07-16 23:41:35