Skip to content

Shikhar-kulshreshtha/MusicAnalyser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Music Emotion Analyser

Overview

Music Emotion Analyser is a Python-based project that analyzes the emotional characteristics of songs using audio features such as valence, energy, tempo, and loudness. The system classifies individual tracks into mood categories and determines the overall emotional profile of a playlist.

The project integrates Spotify data with external audio feature APIs and applies a Valence–Arousal-based approach enhanced with additional computed metrics.


Key Features

  • Fetches playlist data using the Spotify API

  • Retrieves detailed audio features using the ReccoBeats API

  • Caches track features locally to avoid redundant API calls

  • Computes custom arousal and aggression scores

  • Classifies songs into mood categories

  • Calculates playlist-level statistics:

    • Mood distribution
    • Dominant mood
    • Emotional diversity (entropy-based)
  • Assigns a "playlist personality" based on emotional patterns


Concept: Valence–Arousal Model

The system uses:

  • Valence → positivity of the track
  • Arousal → computed from energy, tempo, and loudness

Unlike simple models, arousal is not taken directly but calculated using weighted normalization of multiple features .


How It Works

1. Data Collection

  • Extracts playlist tracks from Spotify

  • Maps Spotify track IDs to ReccoBeats IDs

  • Fetches audio features such as:

    • energy
    • tempo
    • loudness
    • valence
  • Stores results in a local cache (feature.json)


2. Feature Engineering

Arousal is computed as:

  • Energy (primary factor)
  • Tempo (normalized)
  • Loudness (normalized)

Aggression is also calculated using energy, loudness, valence, and speechiness .


3. Mood Classification

Each song is classified using valence and computed arousal:

  • Happy / Energetic
  • Calm / Content
  • Sad / Melancholic
  • Intense / Angry
  • Neutral / Mixed

Classification includes thresholds for neutrality and intensity .


4. Playlist Analysis

The system computes:

  • Mood distribution (percentage of each mood)
  • Dominant mood
  • Emotional diversity using entropy
  • Average valence and arousal

5. Playlist Personality

Based on emotional metrics, playlists are categorized into personalities such as:

  • The Emotional Rollercoaster
  • The Rebel Manifesto
  • The Feel-Good Mix
  • The Chill Companion
  • The In the Feels Mix

Installation

  1. Clone the repository:
git clone https://github.com/Shikhar-kulshreshtha/MusicAnalyser.git
cd MusicAnalyser
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up Spotify credentials:
  • Add credentials in .streamlit/secrets.toml:
SPOTIFY_CLIENT_ID = "your_client_id"
SPOTIFY_CLIENT_SECRET = "your_client_secret"

Usage

Run the data collection script:

python main.py

Then run analysis:

python analysis.py

The program will:

  • Fetch and cache features
  • Analyze songs
  • Output mood distribution and playlist personality

Example Output

The system generates enriched track data like:

  • valence
  • arousal
  • aggression
  • mood classification

Example dataset:


Future Enhancements

Streamlit Frontend (Planned)

A web-based interface will be developed using Streamlit.

Planned features:

  • Input Spotify playlist URL
  • Real-time emotion analysis
  • Interactive valence–arousal visualization
  • Mood distribution charts
  • Playlist personality dashboard

Machine Learning Integration

  • Replace rule-based classification with ML models
  • Train on labeled emotional datasets

Improved Feature Modeling

  • Refine arousal and aggression formulas
  • Add additional audio features
  • Incorporate temporal patterns in music

Technologies Used

  • Python
  • Spotipy (Spotify API)
  • Requests
  • JSON
  • Statistics and Math libraries
  • (Planned) Streamlit

Notes

  • API rate limits are handled using batching and retries
  • Feature caching is implemented to improve efficiency
  • The system is modular and can be extended easily

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages