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.
-
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
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 .
-
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)
Arousal is computed as:
- Energy (primary factor)
- Tempo (normalized)
- Loudness (normalized)
Aggression is also calculated using energy, loudness, valence, and speechiness .
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 .
The system computes:
- Mood distribution (percentage of each mood)
- Dominant mood
- Emotional diversity using entropy
- Average valence and arousal
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
- Clone the repository:
git clone https://github.com/Shikhar-kulshreshtha/MusicAnalyser.git
cd MusicAnalyser- Install dependencies:
pip install -r requirements.txt- Set up Spotify credentials:
- Add credentials in
.streamlit/secrets.toml:
SPOTIFY_CLIENT_ID = "your_client_id"
SPOTIFY_CLIENT_SECRET = "your_client_secret"Run the data collection script:
python main.pyThen run analysis:
python analysis.pyThe program will:
- Fetch and cache features
- Analyze songs
- Output mood distribution and playlist personality
The system generates enriched track data like:
- valence
- arousal
- aggression
- mood classification
Example dataset:
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
- Replace rule-based classification with ML models
- Train on labeled emotional datasets
- Refine arousal and aggression formulas
- Add additional audio features
- Incorporate temporal patterns in music
- Python
- Spotipy (Spotify API)
- Requests
- JSON
- Statistics and Math libraries
- (Planned) Streamlit
- 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