Skip to content

HarshRaj29004/Music-Recognition-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Music-Recognition-Engine System

A full-stack audio fingerprinting application that identifies songs using advanced signal processing and machine learning. This project implements the Shazam algorithm to create unique audio fingerprints and match them against a database of known songs.

πŸ“Έ Screenshots & Demo

Add your application screenshots and demo images here:

Feature Image
Audio Upload Interface Upload
Fingerprint Visualization Fingerprints
Song Match Results Results

🎡 Features

  • Audio Fingerprinting: Generate unique audio fingerprints using spectral analysis and peak detection
  • Song Identification: Match audio samples against a database of fingerprints
  • YouTube Integration: Download and process audio directly from YouTube URLs
  • Real-time Processing: Stream audio processing with chunked data handling
  • Interactive Web Interface: User-friendly React frontend for audio recording and uploads
  • Database Storage: Supabase cloud database for storing fingerprints and metadata
  • RESTful API: FastAPI-based backend with CORS support

πŸ—οΈ Project Structure

Music-Recognition-Engine/
β”œβ”€β”€ backend/                          # FastAPI backend server
β”‚   β”œβ”€β”€ main.py                      # FastAPI application entry point
β”‚   β”œβ”€β”€ audio/
β”‚   β”‚   β”œβ”€β”€ AudioProcessing.py       # Core audio fingerprinting algorithm
β”‚   β”‚   └── testing.py               # Audio processing tests
β”‚   β”œβ”€β”€ route/
β”‚   β”‚   └── route.py                 # API route handlers
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   └── db.py                    # Database client initialization
β”‚   β”œβ”€β”€ model/
β”‚   β”‚   └── audio.py                 # Data models
β”‚   └── .env                         # Database configs
β”œβ”€β”€ frontend/                        # React + Vite frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx                  # Main application component
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   └── audioRecord.jsx      # Audio recording interface
β”‚   β”‚   └── assets/                  # Static assets
β”‚   β”œβ”€β”€ package.json                 # Frontend dependencies
|   └── .env                         # backend route(optional)
└── docker-compose.yml               # PostgreSQL database configuration

πŸ”§ Tech Stack

Backend

  • FastAPI: Modern Python web framework for building APIs
  • LibROSA: Audio analysis library
  • SciPy: Signal processing
  • OpenCV: Image/audio processing utilities
  • Pydub: Audio file conversion
  • yt-dlp: YouTube audio downloading
  • SQLAlchemy: ORM for database operations
  • Supabase/PostgreSQL: Database for storing fingerprints

Frontend

  • React 19: UI library
  • Vite: Build tool and dev server
  • Tailwind CSS: Styling framework
  • React Hot Toast: Notifications

πŸ“‹ Prerequisites

Option 1: Docker (Recommended - Easiest)

  • Docker Desktop
  • Docker Compose
  • Supabase account with API credentials

Option 2: Manual Setup

  • Python 3.8+
  • Node.js 16+
  • FFmpeg (for audio processing)
  • Supabase account with API credentials

πŸš€ Installation

1. Clone the Repository

git clone <repository-url>
cd Music-Recognition-Engine

Option A: Using Docker (Recommended) 🐳

The easiest way to run the entire application with automatic dependency installation:

Step 1: Create a .env file

Step 2: Update the .env file with your Supabase credentials

SUPABASE_URL=<your-supabase-url>
SUPABASE_KEY=<your-supabase-key>

Step 3: Start all services with a single command

docker-compose up --build

This will:

  • βœ… Build and start FastAPI backend (with all Python dependencies)
  • βœ… Build and start React frontend (with all Node dependencies)
  • βœ… Automatically install all required packages
  • βœ… Set up networking between services
  • βœ… Connect to Supabase (no local database needed)

Access the application:

  • Frontend: http://localhost:5173
  • Backend API: http://localhost:8000
  • API Docs: http://localhost:8000/docs

Stop all services:

docker-compose down

View logs:

docker-compose logs -f backend    # Backend logs
docker-compose logs -f frontend   # Frontend logs

Option B: Manual Setup (without Docker)

2. Backend Setup

Navigate to the backend directory and install Python dependencies:

cd backend
pip install -r ../requirements.txt

Create a .env file with your Supabase credentials:

SUPABASE_URL=<your-supabase-url>
SUPABASE_KEY=<your-supabase-key>

3. Frontend Setup

Navigate to the frontend directory and install Node dependencies:

cd frontend
npm install

4. Running the Application (Manual)

In one terminal, start the backend:

cd backend
python main.py

The backend will run on http://localhost:8000

In another terminal, start the frontend:

cd frontend
npm run dev

The frontend will run on http://localhost:5173


πŸ“š Docker Deployment Details

Docker Services Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Docker Compose Network          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Frontend (Node.js)                 β”‚
β”‚  - Port: 5173                       β”‚
β”‚  - Auto-installs dependencies       β”‚
β”‚  - Hot reload enabled               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Backend (Python/FastAPI)           β”‚
β”‚  - Port: 8000                       β”‚
β”‚  - Auto-installs dependencies       β”‚
β”‚  - FFmpeg pre-installed             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Supabase (Cloud Database)          β”‚
β”‚  - Remote PostgreSQL instance       β”‚
β”‚  - No local setup needed            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Docker Commands Reference

# Start all services
docker-compose up --build

# Start in background
docker-compose up -d --build

# Stop all services
docker-compose down

# View logs
docker-compose logs -f

# Rebuild a specific service
docker-compose up --build backend

# Execute command in running container
docker-compose exec backend bash
docker-compose exec frontend bash

πŸ“‘ API Endpoints

Health Check

  • GET / - Server status

Audio Upload & Processing

  • POST /audio_upload - Upload audio from YouTube URL
    • Request body: {"url": "youtube_url"}
  • POST /identify - Upload recorded audio

Audio Fingerprinting

  • Process uploaded audio and generate fingerprints
  • Store fingerprints in database
  • Match against existing fingerprints

🎀 How It Works

1. Audio Fingerprinting Algorithm

The fingerprinting process consists of several steps:

Spectral Analysis:

  • Convert audio to frequency domain using FFT
  • Generate spectrogram with normalized values
  • Normalize using standard deviation and mean

Peak Detection:

  • Identify local maxima in the spectrogram
  • Filter peaks based on loudness threshold
  • Create constellation map of peaks

Hashing:

  • Generate anchor points from peak pairs
  • Create hashes from frequency pairs and time deltas
  • Encode hashes for efficient database storage

Matching:

  • Compare input fingerprint against database
  • Count hash matches to identify songs

2. Audio Processing Pipeline

  1. File Conversion: Convert audio to standard WAV format
  2. Streaming: Process audio in chunks for memory efficiency
  3. FFmpeg Integration: Stream YouTube audio at specified sample rate
  4. Normalization: Normalize audio levels for consistent fingerprinting

πŸ”‘ Key Components

AudioProcessing Class

Handles all audio processing and fingerprinting:

  • converting_to_frequency_domain() - FFT and spectrogram generation
  • constellation_map() - Peak detection
  • fingerPrinting() - Anchor point generation
  • hashing() - Hash encoding
  • encode_hash() - Bit-packing for efficient storage

API Routes

  • Audio upload and processing
  • YouTube integration with streaming
  • Database operations
  • Fingerprint matching

πŸ“Š Configuration

Key parameters in route.py:

SAMPLE_RATE = 44100        # Hz
SAMPLE_WIDTH = 2           # Bytes
CHANNELS = 1               # Mono
CHUNK_DURATION_SEC = 5     # Seconds per chunk
BATCH = 1000               # Database batch size

πŸ› Troubleshooting

FFmpeg Not Found

Install FFmpeg:

  • Windows: choco install ffmpeg
  • macOS: brew install ffmpeg
  • Linux: apt-get install ffmpeg

Database Connection Error

Ensure PostgreSQL is running:

docker-compose ps

CORS Issues

Update allow_origins in backend/main.py with your frontend URL

πŸ“ Development

Running Tests

cd backend
python audio/testing.py

Building Frontend

cd frontend
npm run build

Linting

cd frontend
npm run lint

πŸ” Security Notes

  • Update default PostgreSQL password in docker-compose.yml
  • Restrict CORS origins in production
  • Validate API inputs
  • Use environment variables for sensitive data

πŸ“„ License

This project is open source and available under the MIT License.

🀝 Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

πŸ“š References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors