Skip to content

snigdhasv/Music_Mood_Analyzer

Repository files navigation

Real-Time Music Mood Analyzer System

This project implements a complete real-time music mood analysis and recommendation system. It analyzes audio features of songs, classifies their mood, processes user feedback, and provides playlist recommendations based on user preferences.

Screenshots

dash1
Dashboard

dash2
Dashboard

batch processing
Batch Processing

System Components

1. Streaming Pipeline

  • stream_music.py: Simulates music streaming and extracts audio features.
  • mood_classifier.py: Classifies song mood in real-time using Kafka.
  • user_feedback.py: Simulates and collects listener feedback.
  • spark_streaming_processor.py: Processes real-time music mood analysis using Apache Spark Streaming and Kafka, handling mood classification and feature extraction.

2. Data Processing

  • mysql_connector.py: Manages database connections and Kafka-to-MySQL streaming.
  • playlist_manager.py: Generates dynamic playlist recommendations.
  • batch_processor.py: Handles batch processing of historical data.

3. Visualization

  • dashboard.py: Interactive Plotly Dash dashboard showing real-time analytics of mood classification and recommendations.

Technology Stack 🛠️

Component Technology/Tool
Streaming Apache Kafka
Database MySQL
Real-time Analysis Python (Librosa)
Batch Processing Python (Pandas)
Dashboard Plotly Dash
Audio Processing Librosa

Setup Instructions

1. Install Dependencies

pip install mysql-connector-python dash plotly pandas numpy kafka-python librosa yt-dlp

2. Set Up MySQL Database

Create a MySQL database and tables using the following SQL commands:

CREATE DATABASE music_mood_analyzer;
USE music_mood_analyzer;

3. Configure Database Connection

Create a database named music_mood_analyzer and configure the credentials in:

  • mysql_connector.py
  • dashboard.py
  • batch_processor.py
MYSQL_CONFIG = {
    'host': 'your_sql_host',
    'database': 'music_mood_analyzer',
    'user': 'sql_user',
    'password': 'sql_pass',
    'port': 3306,
    'autocommit': True,
    'connect_timeout': 30,
    'pool_name': 'mood_pool',
    'pool_size': 5,
    'pool_reset_session': True
}

4. Configure Kafka

Create Kafka topics for streaming and feedback handling:

kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic playlist_recommendations
kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic mood_classified
kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic song_stream
kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic user_feedback

5. Get LastFM API

Login to LastFM for developers, get an API key, and update stream_music.py with your credentials:

LASTFM_API_KEY = "your_api_key"
LASTFM_USER = "your_username"

Usage

  1. Start Kafka (in separate terminal):
# Start Zookeeper
zookeeper-server-start.sh config/zookeeper.properties

# Start Kafka server
kafka-server-start.sh config/server.properties
  1. Run the streaming pipeline (in separate terminals):
# Simulate music stream
python stream_music.py

# Mood classification service-using kafka (run this if you want kafka instead of spark to classify mood)
python mood_classifier.py

# Feedback simulator
python user_feedback.py

# Database connector
python mysql_connector.py

# Playlist manager
python playlist_manager.py
  1. Run the Spark Streaming Pipeline (in a separate terminal)
# Start Spark Streaming to process music data (mood classification using spark streaming)
spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.4.1 spark_streaming_processor.py
  1. Run dashboard:
python dashboard.py

Access the dashboard at: http://localhost:8051

  1. Run Batch Processing:
python batch_processor.py --classify  # Run batch classification
python batch_processor.py --analyze   # Generate recommendations
python batch_processor.py --compare   # Compare real-time vs batch

Understanding Mood Classification

The system classifies songs into the following moods based on audio features:

  • Happy: High valence (positivity) and danceability
  • Energetic: High energy, fast tempo, and good danceability
  • Calm: Acoustic, soft, and slower tempo
  • Sad: Low valence, low energy, and slower tempo
  • Dark: Low valence but high energy
  • Neutral: Songs that don't fit clearly into other categories

Project Structure

music-mood-analyzer/
├── batch_processor.py                  # Batch processing and analysis
├── dashboard.py                        # Visualization dashboard
├── mood_classifier.py                  # Real-time mood classification
├── mysql_connector.py                  # Database integration
├── playlist_manager.py                 # Dynamic playlist management
├── spark_streaming_processor.py        # Real-time mood classification using Spark
├── stream_music.py                     # Music stream simulator
├── user_feedback.py                    # Feedback simulator/collector
├── requirements.txt                    # Python dependencies
└── README.md                           # This file

About

This Real-Time Music Mood Analyzer system processes streaming music data to classify songs by mood using audio features. It combines Apache Kafka for real-time streaming, Spark Streaming for mood classification, and MySQL for storage. A dashboard visualizes results, while batch processing reanalyzes historical data for accuracy.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages