You've had this happen. A song is stuck in your head. You remember exactly how the melody goes but nothing useful enough to search for it. Not the title. Not the artist. Definitely not the lyrics.
So you open YouTube Music, tap the search bar, and hum a few seconds of it into your phone.
And your phone tells you what song it is.
You didn't give it the recording. You didn't give it words. You gave it your imperfect, instrument-free, slightly off-tempo humming. And somehow that was enough.
What exactly is the phone matching?
Sound Is Not What Your Phone Hears
When you listen to music, you experience it as melody, rhythm, instruments, and vocals. Your brain does an enormous amount of work to assemble those pieces from raw sound.
A microphone captures something much simpler: a changing signal. Pressure variations in the air, recorded over time.
That raw signal isn't easy to work with directly. But there's a useful transformation: break the signal down into which frequencies are present at each moment, and how strong each one is. Run a short window of audio through frequency analysis, slide that window forward in time, repeat, and you get a two-dimensional picture of the sound: frequency on one axis, time on the other, intensity represented as brightness.
This is a spectrogram. A song viewed as a spectrogram becomes a kind of visual fingerprint. Bass drums create bursts at low frequencies. Vocals trace arcing patterns through the mid range. A guitar chord fans out across multiple frequencies simultaneously. The melody leaves its own distinct shape.
The sound hasn't changed. It's just been represented in a way that makes its structure visible and, more importantly, comparable.
Turning a Song Into Something Searchable
This is where acoustic fingerprinting comes in. Shazam's published research describes a particularly elegant version of it.
A song's spectrogram contains thousands of frequency peaks over time. The key insight is that most of them aren't useful for identification. They're too common, too easily masked by noise, or too dependent on recording conditions. What matters are the peaks that are locally prominent: the highest-energy point within a small region of the spectrogram. These stand out from their neighbours and tend to survive interference.
Shazam calls these anchor points. The fingerprint isn't built from individual peaks but from pairs of them: an anchor point paired with a nearby peak, capturing the frequencies of both and the time gap between them. Each pair becomes a hash, a compact numeric value that encodes those three things.
Song spectrogram
↓
Extract locally prominent peaks
↓
Pair each anchor with nearby peaks
↓
Hash each pair: (freq1, freq2, time_delta)
↓
Store hashes with song ID and timestamp
↓
Database of billions of hashes
When you hold your phone up to a song:
Your recording
↓
Same spectrogram analysis
↓
Same peak extraction
↓
Same hashing
↓
Look up matching hashes in the database
↓
Find the song where matches cluster at consistent time offsets
↓
Song identified
That last step is the clever part. A hash match alone isn't enough because many songs might share some identical frequency pairs by coincidence. What makes a match convincing is when dozens of hashes from your clip all match the same song and at time offsets that are mutually consistent, meaning they all point to the same position in the original recording. Random coincidences don't produce that kind of coherent alignment.
Why a Few Seconds Can Be Enough
A four-second clip might generate hundreds of hash pairs. The system doesn't need all of them to match. It needs enough of them to cluster coherently against one song in the database.
If the fragment you captured contains a section with prominent, distinctive peaks, those peaks generate hashes that are unlikely to match anything except the original. A recognisable chorus or a distinctive instrumental passage can be enough. A quiet intro with few prominent features may not be.
The system is looking for confident, coherent alignment, not exhaustive coverage. Enough distinctive structure in a short window can produce that alignment reliably.
Why a Noisy Room Doesn't Always Ruin It
You're in a coffee shop. Voices, an espresso machine, the clatter of cups. Your recording is picking all of that up alongside the song.
And Shazam still identifies it.
The reason connects back to how the fingerprint is built. By selecting only locally prominent peaks, the system already filters out a lot of low-level detail. Background noise raises the overall energy floor, but it tends to do so broadly. The peaks that were prominent in a clean recording often remain relatively prominent even in a noisy one because they still stand out locally.
Not every hash survives. But enough typically do that the coherent alignment is still findable. The system is designed around the assumption that real-world recordings are messy, and it extracts structure that is robust to that messiness by design.
Loud, chaotic environments can overwhelm even prominent peaks. But moderate noise is the expected case, not the edge case.
Humming Is a Different Problem Entirely
Here's where YouTube Music's hum recognition becomes interesting, because humming breaks every assumption the fingerprinting approach relies on.
When Shazam listens to a song playing in a room, it has the original acoustic characteristics of that recording. Instruments, production, the specific mix. The spectrogram of your recording will resemble the spectrogram of the original closely enough that hashes align.
When you hum, none of that transfers. Your voice produces a completely different spectral signature than a guitar or a synthesiser. The instruments are gone. Your pitch might be slightly off. Your tempo might drift. The timbre of your humming shares almost nothing acoustically with the original recording.
Running Shazam's fingerprinting algorithm on a hummed melody would produce hashes that match nothing in the database. The representations are simply too different.
So the system has to work from something that does transfer between your humming and the original: the relative movement of the melody.
A melody can be described as a sequence of pitch relationships. Not absolute notes, but whether each note is higher or lower than the previous one, and by roughly how much. This is called pitch contour. The same melody hummed in any key, by any voice, at any tempo, preserves its contour even when everything else changes.
Your humming goes through pitch detection first: tracking the fundamental frequency of your voice over time and converting that trajectory into a sequence of relative pitch movements. That sequence becomes a representation of the melody you have in your head.
Your humming
↓
Pitch detection over time
↓
Sequence of relative pitch movements (contour)
↓
Compare against melody representations of known songs
↓
Ranked likely matches
The song database, for this kind of search, stores melodies in a form that can be compared against contour sequences despite differences in key, tempo, and voice. The system is looking for songs whose melodic shape resembles yours, not songs that sound like your humming.
The exact implementation Google uses for YouTube Music isn't publicly documented in full detail, but the core principle is consistent across melody-matching research: since the acoustic surface is useless, extract what is structurally invariant.
Same Question, Different Representation
Shazam and humming recognition are solving the same problem from completely different starting points.
When you play the original recording, the system can exploit the acoustic fingerprint: locally prominent spectral peaks, paired into hashes, matched by coherent time alignment. The recording carries enough of the original's structure that the comparison is direct.
When you hum, the acoustic surface is gone. The system has to extract the one thing that persists across all versions of a melody: the shape of how the notes move.
Same question: what song is this? Different input, different representation, different matching strategy.
You didn't know the title. You didn't know the artist. You had nothing except a melody in your head, imperfectly remembered and imperfectly hummed.
But a melody has a shape that survives your voice, your key, your tempo, and your memory. Your phone didn't try to hear the music the way you do. It found a representation that captured the one thing you were actually able to give it.
You heard a song. Your phone read its shape. And that was enough.
Top comments (0)