This project is a music recommendation system that finds similar songs based on extracted features from audio files. The system also provides lyrics extraction for songs using speech recognition.
- Find Similar Songs: Given a song title, the system finds similar songs based on their audio features.
- Lyrics Extraction: Extracts and displays lyrics from the provided audio files.
- Play Songs: Allows users to play songs directly from the web interface.
- Python 3.x
- MongoDB
- Flask
- ffmpeg
os
tempfile
shutil
speech_recognition
eyed3
numpy
torch
scikit-learn
tensorflow
pymongo
flask
-
Clone the repository:
git clone https://github.com/your-username/music-recommendation-system.git cd music-recommendation-system
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Install
ffmpeg
:Follow the instructions on the FFmpeg website to install
ffmpeg
on your system. -
Set up MongoDB:
Ensure MongoDB is installed and running on your local machine. Create a database named
Audio1
and a collection namedFeatures1
. -
Download the FMA Dataset:
You can download the
fma_large
dataset which contains songs andfma_metadata
which contains metadata about songs from this link: FMA: A Dataset For Music Analysis. -
Extract Features and Save to MongoDB:
After downloading the dataset, you can save the data in MongoDB by running the
features.py
file. This script will extract features from the audio files and store them in the MongoDB collection.python features.py
-
Start the Flask app:
python app.py
-
Open your browser and navigate to
http://127.0.0.1:5000
to access the web interface.
music-recommendation-system/
│
├── app.py # Main application script
├── train_model.py # Contains the MLP class definition and training script
├── features.py # Script to extract features and save to MongoDB
├── requirements.txt # Python dependencies
├── templates/
│ ├── index.html # Home page template
│ ├── songs.html # Songs display template
│ ├── error.html # Error display template
├── static/ # Static files (CSS, JS, images)
└── README.md # This README file
The recommendation system uses a Multi-Layer Perceptron (MLP) model to learn features from the audio data. The MLP model is implemented in train_model.py
and consists of the following:
- Input Layer: Takes the flattened MFCC features as input.
- Hidden Layer: A fully connected layer followed by a ReLU activation function.
- Output Layer: A fully connected layer that outputs the feature representation for similarity comparison.
- Feature Extraction: Extract MFCC features from audio files and store them in MongoDB.
- Data Preprocessing: Scale the features using
StandardScaler
and convert them into PyTorch tensors. - Model Training: Train the MLP model using the preprocessed features. The model learns to generate a feature representation for each audio file.
- Model Saving: Save the trained model as a pickle file (
trained_model.pkl
) for later use in the recommendation system.
- Extract Features: Extract MFCC features from your audio files.
- Store Features: Store the extracted features in MongoDB.
- Train Model: Train the MLP model using the stored features.
- Save Model: Save the trained model to a file.
If you encounter a FileNotFoundError
related to temp.wav
, ensure that ffmpeg
is correctly installed and accessible. Check that the input file path provided to ffmpeg
is correct and that the script has permission to write to the directory.
Ensure all necessary Python libraries are installed. You can install missing libraries using pip install library_name
.