How Shazam works: this is how it recognizes songs

Who knows how many times you will have used the app Shazam to recognize a piece of music whose exact title you didn't remember: just press the button with the Shazam logo, preferably in a not too noisy place, and wait for the system to recognize the song. And who knows how many times you will have been surprised by the incredible effectiveness with which the application manages to complete such a complex task in an extremely short time! But you can know how does Shazam recognize songs? Basically, the application's algorithm compares 10 seconds of the song that is “fed to it” with the “digital audio fingerprints” of millions of audio samples already present in its database and, if an exact match is found, provides the user with information regarding the song in question.

How the Shazam algorithm works

To go into more detail about the how Shazam workshis algorithm compares it spectrogram of the song being played (created at the moment using the microphones of the device in use) with the spectrograms of the songs already present in the database. What is a spectrogram? Basically it is one graphic representation of the intensity of a sound as a function of frequency and time.

Conceptually, this is a graph set up on three axes, each of which represents respectively time, frequency And sound intensity. By marking the reproduction of a certain sound on the spectrogram with a dot, it is possible to determine the intensity and its frequency at a very specific moment in time. As you can easily guess, each piece of music has its own spectrogram, sort of “sonic fingerprint” which is unique and is not the same as that of any other song.

To get a little more technical, to find the track of a song the Shazam algorithm creates a graph based on the three axes and then identifies the frequencies in correspondence with which there are intensity peaks. For each of these peaks the system records both the frequency and the amount of time that has passed since the start of the song.

Since Shazam builds its catalog of music tracks as one hash table or map (to put it simply, it would be a data structure used to match a given key with a given value where the key is, in this case, the frequency), when the application is asked to recognize a song, the algorithm goes to generate a spectrogram of a few seconds of the song on the spot, marking the peaks and the time in which they occur. After that it goes to compare them with those of the hash table present in its boundless database, so as to return the requested information to the user.

Spectrogram examples and hash details. Credits: Shazam Entertainment.

Some historical tidbits about Shazam

We close with some historical tidbits about Shazam. Contrary to what some may think, Shazam is far from a recent service. It was launched, in fact, into the now distant August 2002 in the UK and operated as an SMS service. To identify musical pieces, in fact, you had to dial the number “2580”, stay on the phone while the song you wanted to recognize was playing and, once Shazam finished listening, you received an SMS with the title of the song and the name of the artist. Curious as what, right?

With the advent of the iPhone and the birth of the App Store in July 2008then, Shazam made its debut as a mobile application on the Apple store and, a October 2008, the Android app was launched on the Google Play Store. In the September 2018Finally, Apple acquired Shazam for $400 million, making song recognition even easier on its devices.