Richard Augustine break between name and current page in header PROJECTS

Making a Spotify Playlist Generator (feat. ChatGPT)
Coding a better way to discover new music!
Skills: Python, APIs, Javascript, Project Management
January 2023 - April 2023

Overview

Have you ever listened to a song and thought, “Wow, that was a great song!! I want to hear more like it…” only to check Spotify’s recommendations and find that it’s either:

  • More music from the same artist, but not the same style
  • Music that doesn’t match the style at all
  • Or a random popular song that just happens to be trending, not relevant to what you liked

That was our team’s experience with Spotify at the time, so we sought out a way to provide better recommendations to Spotify users as a project for our club, Western Cyber Society.

a meme describing spotify's recommendation system

Our Solution

At first, this seemed like a challenging task, considering that Spotify is a proprietary service. Fortunately, Spotify provides access to a wealth of backend data through its public API. Using this API, we were able to retrieve detailed information about individual songs on the platform. For any given track, Spotify labels a set of audio features, including:

  • Acousticness: A score from 0.0 to 1.0 indicating the likelihood that a track is acoustic. A value closer to 1.0 means higher confidence that the track is acoustic.
  • Danceability: Describes how suitable a track is for dancing based on its tempo, rhythm stability, beat strength, and overall regularity. A score of 0.0 is least danceable, and 1.0 is most danceable.
  • Energy: A score from 0.0 to 1.0 reflecting the track’s intensity and activity level. Energetic tracks typically feel fast, loud, and dynamic.
  • Instrumentalness: Predicts whether a track contains no vocals. For example, “ooh” and “aah” sounds are treated as instrumental, whereas rap or spoken word are considered vocal. A value closer to 1.0 indicates a higher probability that the track is purely instrumental.
  • Valence: A score from 0.0 to 1.0 describing the musical positiveness conveyed by the track. High valence tracks tend to sound happier and more euphoric, while low valence tracks sound sadder or more somber.

And that’s just the beginning. Spotify provides even more features—such as tempo, key, loudness, and speechiness—all of which we leveraged to match the characteristics of a given song and recommend the most similar tracks to users.

a look at spotify's api documentation Figure 1: Spotify's API Documentation

Our Solution

The Algorithm & Front-End

The algorithm starts by taking a song chosen by the user and analyzing its audio features using Spotify’s API. Using this information, the algorithm asks Spotify to find a list of songs that are similar in style, audio features, and sound. Finally, it creates a new playlist on the user’s account, adds the original song, and appends the recommended tracks, effectively generating a playlist that feels like an extension of the user’s initial song choice. For customization, we also allowed users to tweak certain audio features to better control what they want to hear.

This algorithm was coded in Python and the front-end was created using React JS. FastAPI was used to help integrate our python into a web application.

spotify playlist generator interface Figure 2: User Interface of Final Product

Our Solution

Incorporating AI

A condition for the project was that we had to incorporate AI into it somehow. Given the context of our tool, we saw an opportunity to use AI not to create music directly, but to understand and recommend music more intelligently. Using OpenAI API's GPT-4 model, we built a system where users can input a natural language prompt, something like "chill jazz for studying" or "hype songs for a gym session", and have the AI interpret that into meaningful Spotify audio features like danceability, valence, energy, acousticness, and more.

The AI essentially acts as a translator between human intent and music metadata, generating the appropriate track characteristics and genre suggestions. These are then passed into the Spotify API to curate a playlist that reflects the user’s mood or use-case with surprising accuracy. This layer of AI reasoning turned a basic playlist generator into a highly personalized, music discovery tool that personally helped me discover new music during testing.

Next Steps and Conclusion

And with that, we reached our final product. When we showcased our project at Western Cyber Society’s first Toronto Tech Expo, hosted at IBM Headquarters, it received a lot of interest and support from judges, observers, and peers alike. In fact, the response was so positive that we were awarded the Entertainment Award! It was an incredible day for our team, and for my first time helping to develop a full-fledged software application, I’d say it went really well :)

With more time, I’d love to see:

  • Applying the algorithm to different music services, such as Apple Music, Soundcloud, Youtube Music, etc.
  • Enhanced recommendation engine with AI that can be fine-tuned with a user's recommendations to each song.
  • Changing playlist generation based on external factors, such as time or weather (this was about the same time Spotify's 'Daylist' feature was announced, whoops).

Overall, this was a great project that eventually inspired me to pursue the AI Music Composer project, taking things a step further with combining music and tech 👀 Details about the Spotify Playlist Generator project can be found on my GitHub, thanks for reading!

project showcase Figure 3: Team & Prize after Successful Implementation

Many Thanks to my Team: Ethan C., Raymond L., Elbert C., Kevin F., and Kevin L. 🎉