Inspiration

I don't like the recommendation engines on Apple Music and Spotify. Too often, they suggest a song that kills the "vibe" of my playlist. I wanted to build a personal recommendation engine that I could understand and build upon myself. A key goal was to make it run offline and on low-power hardware, like a Raspberry Pi.

What it does

DJPi is an end-to-end music analysis and recommendation pipeline. First, it helps you build your library by either scanning local audio files or by downloading the audio files from a list of provided songs.

Next, its scanner analyzes every song for its musical "fingerprint"—extracting features like tempo, timbre, and key—and stores it in a local database. Finally, the main app lets you pick a "seed playlist," and it uses a machine learning algorithm to analyze that playlist's "vibe" and recommend other songs from your library that match what you're going for.

How I built it

I built this in Python using a stack of powerful open-source libraries:

  • Feature Extraction: librosa is the core, used to perform Harmonic-Percussive Source Separation (HPSS) and then extract MFCCs (plus their first and second-order deltas) and chroma features from every track.
  • Recommendation Engine: scipy and numpy are used to run the core "vibe" matching algorithm, which is based on Dynamic Time Warping (DTW).
  • Database: TinyDB (a lightweight JSON database) stores all the extracted features for offline use.
  • Data Pipeline: tinytag is used to read metadata from the audio files.

Challenges I ran into

The biggest challenge was defining a "vibe." Our first attempt involved averaging all of a song's feature matrices into a single "fingerprint" vector. This failed, as it lost all of a song's dynamic progression—a quiet verse and a loud chorus just averaged out to "medium," which was useless. I overcame this by implementing DTW. This algorithm compares the entire sequence of features, allowing us to match songs based on their structural journey, not just their average "sound."

Accomplishments that we're proud of

I'm proud of building a recommendation engine from scratch that can run offline and build playlists from my music library. Moving from a failed averaging-based model to a working DTW-based model was a huge win, the recommendations were much more "accurate". The fact that this all runs on a low-power Raspberry Pi is exactly what I set out to do.

What I learned

I learned a massive amount about digital signal processing (DSP). I can now understand what happens "behind the scenes" of the recommendation engines from services like Apple Music and Spotify. I now understand what a musical fingerprint is (MFCCs, chroma) and why it's important to analyze a song as a sequence. This project was a practical lesson in machine learning and learning what "features" can be extracted from a song.

What's next for DJPi

The next step is to build a full graphical user interface (GUI) to replace the command-line app. I also want to add a built-in music player and eventually create a "smart playlist" generator that can automatically sequence the recommended songs for smooth, DJ-like transitions.

Built With

Share this project:

Updates