Live model · Shazam
How Shazam Actually Works
Shazam turns a few seconds of sound into a spectrogram and keeps only its loudest points. It pairs those points into hashes: two frequencies and the time between them. Then it looks the hashes up. The right song is the one where many hashes agree on the same moment in the track.
A model of Avery Wang's 2003 paper, An Industrial-Strength Audio Search Algorithm, run on six public-domain recordings. It isn't the system Shazam runs today.
Sound into a spectrogram
- CH1 sound
Change one thing
Clip
Break it
From sound to a spectrogram
To the model, sound is a list of numbers, 8,000 a second, as in the paper. The FFT measures how loud each frequency is in 64 ms of them. Slide 32 ms along and measure again, and the columns line up into a spectrogram. Press Play to hear exactly what the model hears.
Keep the peaks, pair them into hashes
A peak is a point louder than everything near it. Noise can bury quiet sound, but the loudest peaks tend to survive it, so the model keeps only those, up to 10 a second. Then each peak becomes an anchor and pairs with up to five peaks just after it. Two frequencies and the gap between them make a hash.
Peaks into hashes
- CH1 peaks
- CH3 pairs
Line the hashes up
Each hash the library also holds is a vote for a track, and for where in it the clip would start: the time in the track minus the time in the clip. Chance hits scatter. The right track piles its votes on one offset. A track needs 8 votes on one offset to count as a match.
Hashes into a match
Let it listen
Play one of the six recordings on another device, and let this one listen for 5 seconds. The speaker, the room and the microphone all change the sound, and the peaks that survive still line up. No microphone? The page plays a clip from a random point with hiss added, and matches that.
With a microphone
Open this page on another device and play a recording there. Hold it near this one and press Listen. The recording stays in this browser: it's analyzed here and never uploaded.
Without one
The page picks a recording from the library, starts at a random point, adds hiss, plays it, and matches what it played.
Questions
- Is this how Shazam works today?
- It's the method Avery Wang published in 2003, when you called Shazam from a phone and held it up to the music. Shazam hasn't published how its system works now, and it has surely changed. This page runs the paper's steps on six recordings, not Shazam's code or its catalog.
- How does Shazam cope with noise?
- Noise adds peaks, but it rarely moves the loudest ones, and a match needs only a few hashes to survive. Here, a 5 s clip still matches 94% of the time with hiss 3 dB louder than the recording, and 78% at 6 dB louder. The paper, with 10,000 songs and noise recorded in a pub, recognizes half its 5 s clips when the noise is 3 dB louder.
- Why pair peaks instead of matching single peaks?
- One peak is one frequency, and countless songs share it. A pair adds a second frequency and the time between them, so a hash is far rarer and a lookup returns only a few places. The paper puts the gain at about 10,000 times faster search for 10 times the storage.
- Can it recognize a live performance or humming?
- Not with this method. It matches one exact recording: the same notes at the same moments with the same sound. A live version, a cover or a hum makes different peaks. The paper says the algorithm isn't expected to generalize to live recordings.
- Why does half a second fail?
- Half a second of Morning Mood makes 18 hashes, and six of them line up with the recording, short of the 8 a match needs. A longer clip gives more hashes a chance to survive, which is why the paper's 15 s clips beat its 5 s ones.
Drill the mechanism
The library is a hash table: a hash goes in, every place it occurs comes out. Two Sum looks up what it needs the same way. Scoring counts votes per offset and keeps the most common, which is Top K Frequent Elements with k = 1. Group Anagrams files each word under a key made from it, as a hash files a pair of peaks.