Spot Your Mood!
Utilizing the Spotify API in conjunction with Google's NLP API in order to generate a better emotion classifier, allowing users to view insights into their listening history from a new lens. Check out the code here!
A user links their Spotify account with our service. On this process, the app generates a json header to send to Spotify. This authentication token allows the service to gain access to the user's account for the duration of one browser session. If the user refreshes the page, one challenge was keeping the token alive. A refresh token had to be used in order to tell Spotify that this session was still logged in.
Once on the page, the data is pre-populated with the user's current mood, as well as the mood of each of their playlists. The generation of these metrics involve multiple steps.
- Lyric Sentiment Analysis - For any set of songs that were being analyzed (whether it be a user's recent 50 songs, or one of their playlists), I contacted the Genius API and retrieved lyrics for all songs in question. After retrieving these lyrics, the service called Google's Natural Language Processing API in order to perform sentiment analysis on these words. This value was one metric utilized in our final score.
- Spotify's Provided Data - Spotify provides a variety of song data about a selection of songs, so we queried the Spotify API in order to utilize a song's happiness, tempo, valence, danceability, etc. in our final score.
- Creating Mood Vector - We looked through nearly 100 songs that satisfied each of our moods, and performed these above two calculations on all of these songs. We then used this training dataset to create a baseline mood vector for each of these moods.
- Classifying Song's Mood - When we get a song's specific vector, we perform an error analysis of this vector compared to the standard vectors we created in step 3. Whichever vector has the least error is our mood classification of this song.
When a user is feeling some specific type of mood, we want them to be able to listen to music that fits that taste. As a result, we developed a feature that allows users to input song types that they are interested in, such as danceability, happiness, tempo, and other features that they might be feeling at the moment. After submitting this form, we generate a 10 or 15-song playlist that satisfies these requirements. This playlist gets directly added to the user's Spotify profile, so they can immediately enjoy the music of the mood that they're feeling.