A full-stack application that identifies a classical music piece from a user's hummed melody.
It performs real-time audio processing, extracts pitch intervals, compares sequences using DTW + k-NN, and validates predictions using a Longest Ascending Chain algorithm.
- Uses the Web Audio API to access the microphone.
- Implements Autocorrelation (with FFT fallback) to estimate pitch.
- Extracts pitch every few milliseconds for real-time feedback.
- Converts detected pitches into musical intervals modulo 12.
- Produces a short melody "signature."
- Python/FastAPI backend analyzes the interval sequence.
- Uses Dynamic Time Warping (DTW) for robust time-series comparison.
- Applies k-Nearest Neighbors (k = 3) over pre-indexed melodies.
python.pyloads MP3 files and extracts short melody fragments.- Intervals are letter-encoded and stored in a melody hash table.
- Uses Longest Ascending Chain of splice-order predictions.
- Ensures the detected fragments appear sequentially within the true song.
This project includes:
- A React frontend
- A FastAPI/Python backend
Run them at the same time.
You will need Node.js and Python 3.
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install required libraries
pip install fastapi uvicorn numpy librosa pandas matplotlib seabornFor the Python Backend:
# It's recommended to use a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install required libraries
pip install fastapi uvicorn numpy librosa pandas matplotlib seaborn
For the React Frontend:
# Assuming you are in the project root directory
npm installThe python.py script requires a directory of classical music MP3 files to build its internal hash table.
- Create a directory named pieces inside the backend source folder (e.g., in the same directory as python.py).=
- Populate this directory with your classical music MP3 files (e.g., Beethoven_Symphony5a.mp3).
- The python.py script is designed to build the melody hash on startup by calling build_melody_hash().
Open a terminal, navigate to the backend directory, and run the API server.
python api.py
# The server should start on http://0.0.0.0:8000Open a separate terminal, navigate to the frontend directory, and start the React application.
npm start
# The app should open in your browser on http://localhost:3000Click the "Start Listening" button in the browser, and hum a melody from one of the indexed classical pieces!