Classifying music genres. From Scratch: Part I

Music information retrieval using librosa and python

Anupam vashist
Karma and Eggs

--

I developed a taste in rock and metal music back in school days. Prior to that i liked popular music for the lack of exposure to extreme genres, but still i can safely count hundreds of pop songs i could listen to even now as my guilty pleasure (Celine dion, Backstreet boys, Blues, everyone). Then i got introduced to Rock music (R.I.P Chester) and subsequently started exploring its associated genres, it’s history with dissent and how it got to the extremes of metal. over the years i’ve seen sections of rock and metal music fuse into popular, electronic, alternative and even doom music, on the other hand, ive heard sounds of rock, creating ever-evolving list of sub-genres.

But what’s the meaning of Genre? what do you mean by “Sounds” of Genre?

Glad you asked. Anyone with a slightest sense of hearing with an inclination of listening to a variety of music would intuitively understand there’s “something different” between 2 sets of songs. Lets explore these sets and the intuition:

Let’s say we’re listening to an album. Unless its a a collaboration between mixed artists, all the songs in the album will be on a similar central lyrical theme, will have similar sounding instruments, and will probably contain similar signature notes and variations. But of course, there would be more differences than similarities, because who knows the limit of art and the artist (and just imagine the infinite combinations of tunes, beats, theme and lyrics).

Now let’s say we’re listening to the same artist/band but it’s songs are from 2 albums spaced years apart. Now we’ll see the difference pertaining to audio recording technology, changing tones of the era, central theme, tempo/beats, and possibly much more.

In another case, let’s listen to songs from 2 different bands on a similar central theme (let’s say, Horror. yes, Horror) and in the similar era and playing the similar instruments and possibly in a faster tempo (Metallica vs Megadeth, anyone?).

Will you be able to differentiate between these songs? of course yes. But will you be able to spot the similarities by just listening to the songs? of course yes again. mostly. In the above examples, these similarities and differences are the basis of a song’s classification into genres- similar sounding tunes, on a similar central theme, in a similar era (more or less).

Music genres, clustered by similarity. Image:musicmachinery

Now, it’s clear that no two songs are the same if we come down to find the differences. However, if we’re to find the similarity, all the songs are the same on a higher level. they are vibrations. period. Somewhere in between, we find an optimum level of difference where we can segregate these songs efficiently. more we’d want to segregate, more genres we create.

Our goal here is to collect some songs, extract it’s features and see if we are able to detect it’s genre.

STEP 1: Data collection

We’ll do this the novel way. we’d need a list of songs from different genres, explicitly tagged genre labels as well. Let’s begin with making song list in excel the following way

and we’ll try to download the songs directly to .wav format and assign the Band and Genre labels accordingly through the following snippet of code.

importing above csv/excel
Define youtube to wav function
calling youtube to wav function

After following these steps we’ll have all the .wav files downloaded into a specified folder, and with a relevant name including genre and band information with a “.” delimiter for future processing. Here is the Github link for the code i used to convert tracks to wav.

Keeping this one light. In the next article we’ll extract relevant features from the data and will be able to perform EDA on these features that might wave our way forth.

Keep rocking!

--

--