Skip to main content

What emotions run through your playlist?

Hola !!

Long time. So I was upto creating this application one night , I named: "Playlist Emotions" , "What does the song says" :P , "PlayWithEmotions" and what not, each project of a failed experimentation.


The project took way too long. Thanks to the noble idea of making and deploying it as a GWT application and then to improve upon the GUI of the app.
FYI , I tried but done neither of the things above. My Google Console developers trial account  supposedly has some issues with this app, yet to be resolved. So before the entire idea behind the app and the excitement of results it displays fades out , I thought, lemme write a blog post on the same.

So what is this all about?

The idea originated from a candid discussion with my friend on how songs influence our moods and also how our emotions affect the type of songs we listen to.

Being fascinated about knowing what kinds of songs I listen to, I thought of creating an application where I would just enter the folder location where my songs are and it would return me emotional composition of the songs I listen to.

Next stage was how to do that?

Logic is somewhat like this: When you share your music directory with me, I read the titles of all ,mp3 / .wav songs. Then the application extracts lyrics for those songs.

There exists no robust API that can give the lyrics of the song. Trouble multiplies when it is a Hindi Song, because we need to fetch the lyrics in English to do the sentiment analysis of the song.

So, indeed the program does a google search of "English Lyrics" + title of the song in your directory.
This gives me a list of links. I pick up the links resembling to either one of the following four trusted websites on lyrics , whichever is encountered first: (for Bollywood Songs) (for Bollywood Songs)

Next step is scraping lyrics from these links. I studies the html structure of the websites and using JSoup library I finally fetched the string of my interest.

Then comes the third step of doing sentiment analysis, I did it using Synesketch .

"Synesketch analyses the emotional content of text sentences in terms of emotional types (happiness, sadness, anger, fear, disgust, and surprise), weights (how intense the emotion is), and a valence (is it positive or negative). The recognition technique is grounded on a refined keyword spotting method which employs a set of heuristic rules, a WordNet-based word lexicon, and a lexicon of emoticons and common abbreviations. Synesketch visualizes the emotions recognized in the form of real-time generative art. The art is partially based on Jared Tarbel’s algorithms and is inspired by the physics graphics of colliding particles."

And tadaa, I have the composition of emotions in songs I frequently listen too.
Mine was overall positive, with more of happy and surprise content :D If you want to try, find the app here:

The code is open source, feel free to download and experiment. :)

This is how the raw application looks:

And when you get your results :D

The accuracy is challengable though, majorly because of two reasons:
1. Not the entire playlist is analysed, as in the trick that we applied to fetch the lyrics is usually applicable to around 70-80% songs, at times all, if you have named your songs properly in your playlist rather than random strings/numbers.

2. The Synesketch does sentiment analysis on words the song uses, we are equating the category of words with the category of songs, as in sad words corresponds to sad songs, This might not be the case always, for song also constitutes of musical beats , eh. Ok, just for clarification there is nothing like sad words, I just used it to indicate the set of words that can be categorized to a sad emotion. The details of it lie in the logic of Synesketch itself.
Detecting emotions in text is an ongoing research so high accuracy cannot be expected as of now.

So that was it, a whole night and the abstract thought of yesterday concreted into the application of today. Its fun to get your hands dirty into code this way.

See you in next post soon, with one more exciting creation/ exploration.

It would be great to hear your comments below!

Till then, keep hacking ;)



Popular posts from this blog

Duh - Saves you the trouble to correct your command


This is no more an expression for me but a command now. Thanks to the hack I have been doing for past couple of days.

What's it about? Well, here it goes.

How many times it happens that we screw up commands on terminal?
A typo, a syntax mistake or jumbled up arguments. The command doesn't run and then we spend time retyping it ensuring everything is in place this time.
Quite time consuming, eh?

My laziness simply denied me such a behaviour. So I coded up a powershell cmdlet which can do this for me.
Now if I mess up a command, I just have to type 'Duh' and the right command will be displayed on the prompt for you to check and execute (press ENTER).

How Duh operates internally?
Well, guess what. Answer lies in the "tries".
We have a trie and we do closest match using Leveinshtein Distance.
In short, how to figure out how close two strings are?  Find the no of letters you need to remove/insert/replace in order to attain string 2 from string 1.
This is wha…

How would you make an HTML Parser?

Hola folks,

Here we will be walking through how html is being parsed by a widely popular parser: Angle Sharp
You can find it here !
This is just a walkthrough and gives an idea on the breadth of issues  one has to deal with while designing a parser.

Let's sneak peek into what kind of data structures are used and how is the code structured.

It all begins with this line:
var parser = new HtmlParser();
We have folowing variations in constructing the HtmlParser object:

  public HtmlParser()
            : this(Configuration.Default)

        /// <summary>
        /// Creates a new parser with the custom options.
        /// </summary>
        /// <param name="options">The options to use.</param>
        public HtmlParser(HtmlParserOptions options)
            : this(options, Configuration.Default)

        /// <summary>
        /// Creates a new parser with the custom configuration.
        /// </summary&…