How risris511/simsongs works
Purpose and execution model
This repository is a command-line music similarity pipeline. It collects Deezer track previews, derives audio embeddings, builds a nearest-neighbor index, and queries that index with a local audio file.
Primary entry points:
• Dataset acquisition: build_deezer_db.py
• Index construction: build_index.py
• Similarity search: query_script.py
Deezer ingestion boundary
build_deezer_db.py is the external-data boundary. It calls Deezer services via HTTP, supporting chart, playlist, and genre sources, then obtains available preview audio for selected tracks.
It handles real-world API/media failures by skipping tracks without usable previews or failed downloads. Preview downloads are cached, making subsequent database builds less dependent on repeated network retrieval.
Paths:
• build_deezer_db.py
• requirements.txt
Audio feature extraction
audio_embeddings.py defines the shared representation layer: audio input is decoded and transformed into numerical embeddings suitable for comparison. The runtime audio stack is based on librosa, soundfile, and numpy.
This module is the consistency boundary between corpus construction and query: database previews and user-provided songs must be embedded with the same feature logic and dimensionality.
Paths:
• audio_embeddings.py
• build_deezer_db.py
• query_script.py
Persistent music database
The ingestion stage combines track metadata with generated embeddings into an .npz database artifact. This artifact is the handoff from remote acquisition/audio processing to local indexing, avoiding Deezer calls during index construction and querying.
The database can be written to a custom output path; downstream scripts implicitly depend on its schema, including aligned track records and embedding rows.
Paths:
• build_deezer_db.py
• build_index.py
Index construction
build_index.py loads the persisted embedding database and creates a local similarity-search index. The project uses scikit-learn and joblib, indicating an in-process Python nearest-neighbor model serialized for reuse.
This stage separates potentially expensive model fitting from interactive query execution. Its output must preserve or reconstruct the mapping from neighbor positions back to database track metadata.
Paths:
• build_index.py
• audio_embeddings.py
• requirements.txt
Query flow
query_script.py accepts a local song path, extracts its embedding through the shared audio layer, loads the prebuilt index, and returns the closest corpus tracks. It is fully local after artifacts have been built; no Deezer API call is required during search.
Control flow is:
1. Build preview-backed embedding database.
2. Build and persist a nearest-neighbor index.
3. Embed query audio.
4. Retrieve and present matching Deezer tracks.
Paths:
• query_script.py
• audio_embeddings.py
• build_index.py
Runtime and dependencies
The system is a Python CLI workflow, not a service or web application. Material dependencies are:
• Audio decoding/features: librosa, soundfile, numpy
• Local ML search and serialization: scikit-learn, joblib
• Remote Deezer API and preview retrieval: requests
Paths:
• requirements.txt
• readme.md
Main entry points: build_deezer_db.py Database builder · query_script.py Similarity query · audio_embeddings.py Audio embeddings · requirements.txt Python dependencies
Components 13
Corpus acquisition
- Deezer services · Track metadata and preview audio source.
- Database builder
build_deezer_db.py - Preview cache · Avoids repeated preview downloads.
- Usable previews
Local similarity pipeline
- Audio embeddings · Keeps corpus and query vectors compatible.
audio_embeddings.py - Music embedding database · Aligned track metadata and embedding rows.
- Index builder
build_index.py - Nearest-neighbor index · Preserves lookup from neighbors to tracks.
- Similarity query
query_script.py - Local song file
- Matching Deezer tracks
Other components
- Python dependencies · Audio, HTTP, nearest-neighbor, and serialization libraries.
requirements.txt - Workflow documentation
readme.md
Connections 17
- Deezer services → Database builder: metadata and previews
- Database builder → Preview cache: caches downloads
- Preview cache → Usable previews: reuses audio
- Database builder → Usable previews: downloads usable audio
- Usable previews → Audio embeddings: decode and transform
- Audio embeddings → Music embedding database: corpus vectors
- Database builder → Music embedding database: writes metadata
- Music embedding database → Index builder: loads embeddings and records
- Index builder → Nearest-neighbor index: fits and serializes
- Local song file → Similarity query: song path
- Similarity query → Audio embeddings: embeds query audio
- Nearest-neighbor index → Similarity query: loads index
- Music embedding database → Similarity query: resolves track metadata
- Similarity query → Matching Deezer tracks: presents nearest tracks
- Python dependencies → Database builder: HTTP and audio runtime
- Python dependencies → Audio embeddings: audio stack
- Python dependencies → Index builder: search and serialization