Skip to content

Latest commit

 

History

History
77 lines (59 loc) · 1.95 KB

File metadata and controls

77 lines (59 loc) · 1.95 KB

Music Genre Classification System

This is a machine learning-based system for classifying music into different genres. The system uses audio features extracted from music files to train a Random Forest Classifier.

Features

  • Extracts various audio features including MFCCs, spectral centroids, chroma features, and spectral rolloff
  • Uses Random Forest Classifier for genre prediction
  • Supports both training and prediction modes
  • Can save and load trained models
  • Supports MP3 and WAV audio formats

Requirements

  • Python 3.8 or higher
  • Required packages are listed in requirements.txt

Installation

  1. Clone this repository
  2. Install the required packages:
pip install -r requirements.txt

Project Structure

.
├── README.md
├── requirements.txt
├── music_classifier.py
└── data/
    ├── genre1/
    │   ├── song1.mp3
    │   ├── song2.wav
    │   └── ...
    ├── genre2/
    │   ├── song1.mp3
    │   └── ...
    └── ...

Usage

  1. Prepare your dataset:

    • Create a data directory
    • Inside the data directory, create subdirectories for each genre
    • Place audio files (MP3 or WAV) in their respective genre directories
  2. Train the model:

from music_classifier import MusicClassifier

classifier = MusicClassifier()
X, y = classifier.prepare_dataset("data")
classifier.train(X, y)
classifier.save_model()
  1. Make predictions:
prediction = classifier.predict("path/to/audio/file.mp3")
print(f"Predicted genre: {prediction}")

Features Used

The system extracts the following features from audio files:

  • Mel-frequency cepstral coefficients (MFCCs)
  • Spectral centroid
  • Chroma features
  • Spectral rolloff

Model

The system uses a Random Forest Classifier with 100 trees. The features are preprocessed using StandardScaler before training.