How Shazam names a song from a few seconds of noisy audio
The app never compares raw sound. It turns your clip into a spectrogram, a picture of which pitches (frequencies) are loud at each moment, and keeps only the brightest spots, called peaks.
It then pairs nearby peaks and turns each pair into a short code: first pitch, second pitch, and the time gap between them. Those codes are the song's fingerprint, and a ten-second clip produces many of them.
Concept of the day2 / 3
Audio fingerprinting
Real-life use case
Shazam names a song playing over café chatter
You hold your phone up in a noisy café. The app makes fingerprint codes from the clip and looks each one up in a giant table built in advance from millions of recordings.
The same idea is used for copyright matching: YouTube's Content ID compares uploads against reference files supplied by rights holders, to spot reused music and video.
Concept of the day3 / 3
Audio fingerprinting
How it helps
Real matches all line up at the same point in the song
Noise adds sound but rarely hides the loudest peaks, so many codes from your clip are exactly the same as codes stored for the real song. Each code is a hash table key, so each lookup is close to instant.
Timing settles it: for the real song, every matching code sits the same distance in. If clip codes at 1 s and 3 s appear at 61 s and 63 s, both say the clip began 60 s in. Chance hits give scattered gaps.
What it’s forDecides which stored song a clip really comes from.
δ = t_song − t_clip; score = number of hits sharing the most common δ
t_clip
when a matching code occurs in your clip, in seconds
t_song
when that same code occurs in the stored song
δ
the offset: how far into the song your clip started
score
how many hits agree on one offset; the highest-scoring song wins
What it givesThe song with the most agreeing hits, and where in it you are listening.
Clip codes at 1 s, 3 s, 4 s are found in song A at 61 s, 63 s, 64 s → δ = 60, 60, 60: score 3.
Two clip codes hit song B at 12 s and 90 s from clip times 1 s and 3 s → δ = 11 and 87: score 1.