Skip to main content

A lightweight Python library for musical emotion analysis

Project description

feel: Python Library for Musical Emotion Analysis

feel is a lightweight Python library for analyzing a music file and scoring it across multiple emotions based on its acoustic features (pitch, rhythm, timbre).


🚀 Installation

Install via PyPI:

pip install feelling

🎵 Supported Formats

  • WAV
  • FLAC
  • MP3
  • M4A/AAC
  • OGG/OPUS

(FFmpeg must be installed and in your PATH for MP3/AAC/OGG/OPUS support.)


🔍 How It Works

  1. Load Audio: Uses soundfile or pydub (with FFmpeg) to read and resample to 22.05 kHz mono.

  2. Extract Features: Computes:

    • Harmonic vs. percussive energy ratio
    • Chroma (CQT) to detect minor/major ratio
    • Tempo (beats per minute)
    • Spectral descriptors (centroid, bandwidth, contrast, rolloff, flatness)
    • Zero-crossing rate (ZCR)
    • Root-mean-square (RMS) loudness
  3. Normalize: Feature values are min–max normalized within the file.

  4. Score Emotions: A weighted sum over features for each emotion (sadness, happiness, grandeur, etc.).

Weights for each emotion are configurable in EMOTION_WEIGHTS.


⚙️ Quickstart

from feelling import analyze

# Analyze an audio file and get emotion scores
scores = analyze("path/to/song.mp3")
print(scores)
# Example output:
{'amazement': 2.785994294009202,
 'anger': 2.7061781529298923,
 'awe': 2.3857337980174704,
 'bittersweet': -0.6897889961401367,
 'brooding': -1.2310171365296803,
 'calmness': -1.3223295386507186,
 'compassion': 0.8462746872436658,
 'contemplation': -0.6982909427247976,
 'courage': 2.02148080255978,
 'despair': -2.231273017589515,
 'devotion': 0.6195735408259397,
 'ecstasy': 3.1549486543435767,
 'empathy': 0.5456626971919932,
 'energy': 2.7875557099155377,
 'euphoria': 3.4885498522529366,
 'excitement': 2.3111535163286896,
 'fear': 1.376430927354388,
 'fun': 2.5987931168715916,
 'fury': 2.647916600269525,
 'gloom': -2.528004024674664,
 'grandeur': 2.413186509472432,
 'guilt': -2.0240664318416393,
 'happiness': 2.019107444540511,
 'hope': 1.8475886363524776,
 'intimacy': 0.8485076464346826,
 'joy': 2.847461883314458,
 'jubilation': 2.7760478539781217,
 'longing': -1.1097125270242696,
 'love': 1.5902762628566427,
 'melancholy': -1.6859296441216043,
 'mourning': -2.0619032976192506,
 'mysticism': -0.08503173099393924,
 'nostalgia': -0.9471086633393663,
 'optimism': 2.1649828698552853,
 'peace': -1.0088574401582806,
 'playfulness': 2.469039451504274,
 'pride': 1.7142282816425052,
 'relief': -1.2378913124481465,
 'reverence': 2.0027256095964767,
 'sadness': -1.4695416250468998,
 'serenity': -1.2599763350028974,
 'shame': -1.716638007519969,
 'solitude': -1.0641904277010628,
 'surprise': 3.0351611656705053,
 'tenderness': 0.9212167712326097,
 'tension': 1.8677738672595334,
 'tranquility': -1.383235730007885,
 'wistfulness': -1.064112344330448,
 'yearning': -1.5448817048229317,
 'zeal': 2.4694397366889294}

Each score is a floating-point value (higher = stronger presence of that emotion).


🎨 Customizing Emotions

You can add, remove, or adjust emotion weights in your local feel.py before calling analyze. Example:

from feel import EMOTION_WEIGHTS

# Add a new emotion "mystical"
EMOTION_WEIGHTS['mystical'] = {
    'minor_ratio': 0.0,
    'tempo': -0.2,
    'centroid': 0.1,
    # ... specify all 10 features
}

📝 License

MIT © \Mr. Mohammad Taha Gorji

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

feelling-1.0.4.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

feelling-1.0.4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file feelling-1.0.4.tar.gz.

File metadata

  • Download URL: feelling-1.0.4.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for feelling-1.0.4.tar.gz
Algorithm Hash digest
SHA256 7780cf0d3a77b1acad55f9d2c72e4dbd39038d9cb9525040e7c94a158d5b90a9
MD5 25708e2b57550fd4bddfdc724710885b
BLAKE2b-256 69b4a49471d5b798a06710a399bdba17bbf14b1eb4f99875287a5804fe018996

See more details on using hashes here.

File details

Details for the file feelling-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: feelling-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for feelling-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4951e4041a3acae3b51bd69ec03cfac6d265d8d94a0ac64abded46450b53ed9b
MD5 aad00e03eba9f846e684362283632091
BLAKE2b-256 3c825289922f70bb457e33edf8d817bd88fc56ebbf77f4e40afe1c67237790c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page