Skip to main content

A library for analysis and synthesis of Indian classical music

Project description

Bhargava Swara

A Python library for analyzing and visualizing Indian classical music, including spectrogram generation (Mel-frequency, Chroma, CQT, and Cent filterbank), raga, tala, tempo, tradition, ornaments, and full analysis.

Prerequisites

  • Gemini API Key:
    This library uses Google's Gemini API for music analysis. To obtain a key:

    1. Sign up for a Google Cloud account
    2. Enable the Generative AI API in the Google Cloud Console
    3. Create an API key in the "Credentials" section
      Refer to Google's Generative AI Docs for details
  • Audio Files:
    Supported formats include WAV and MP3 for analysis and spectrogram generation

Installation

Install the library using pip:

pip install bhargava_swara

Dependencies

  • google-generativeai>=0.1.0
  • librosa>=0.10.0
  • matplotlib>=3.7.0
  • numpy>=1.24.0

Spectrogram Generation

Generate various types of spectrograms to visualize different aspects of audio frequency content over time.

Mel-Frequency Spectrogram

from bhargava_swara import generate_mel_spectrogram

audio = "path/to/audio.wav"
output = "path/to/output_mel_spectrogram.png"
generate_mel_spectrogram(audio, output, n_mels=128, fmax=8000)
print("Mel spectrogram generated successfully!")

Chroma Spectrogram

from bhargava_swara import generate_chroma_spectrogram

audio = "path/to/audio.wav"
output = "path/to/output_chroma_spectrogram.png"
generate_chroma_spectrogram(audio, output, n_chroma=12, hop_length=512)
print("Chroma spectrogram generated successfully!")

CQT Spectrogram

from bhargava_swara import generate_cqt_spectrogram

audio = "path/to/audio.wav"
output = "path/to/output_cqt_spectrogram.png"
generate_cqt_spectrogram(audio, output, hop_length=512, n_bins=84)
print("CQT spectrogram generated successfully!")

Cent Filterbank Spectrogram

from bhargava_swara import generate_cent_spectrogram

audio = "path/to/audio.wav"
output = "path/to/output_cent_spectrogram.png"
generate_cent_spectrogram(audio, output, n_filters=128, fmax=8000)
print("Cent filterbank spectrogram generated successfully!")

Spectrogram Parameters:

  • audio: Path to the input audio file (e.g., WAV or MP3)
  • output: Path to save the PNG file
  • Mel-specific: n_mels (default: 128), fmax (default: 8000)
  • Chroma-specific: n_chroma (default: 12), hop_length (default: 512)
  • CQT-specific: hop_length (default: 512), n_bins (default: 84)
  • Cent-specific: n_filters (default: 128), fmax (default: 8000)

Music Analysis

Analyze various aspects of Indian classical music using the Gemini API.

Raga Analysis

from bhargava_swara import analyze_raga

api_key = "YOUR_API_KEY"
audio = "path/to/audio.wav"
result = analyze_raga(audio, api_key)
print(f"Raga: {result}")

Tala Analysis

from bhargava_swara import analyze_tala

api_key = "YOUR_API_KEY"
audio = "path/to/audio.wav"
result = analyze_tala(audio, api_key)
print(f"Tala: {result}")

Tempo Analysis

from bhargava_swara import analyze_tempo

api_key = "YOUR_API_KEY"
audio = "path/to/audio.wav"
result = analyze_tempo(audio, api_key)
print(f"Tempo: {result}")

Tradition Analysis

from bhargava_swara import analyze_tradition

api_key = "YOUR_API_KEY"
audio = "path/to/audio.wav"
result = analyze_tradition(audio, api_key)
print(f"Tradition: {result}")

Ornament Analysis

from bhargava_swara import analyze_ornaments

api_key = "YOUR_API_KEY"
audio = "path/to/audio.wav"
result = analyze_ornaments(audio, api_key)
print(f"Ornaments: {result}")

Full Music Analysis

from bhargava_swara import analyze_music_full

api_key = "YOUR_API_KEY"
audio = "path/to/audio.wav"
result = analyze_music_full(audio, api_key)
print(f"Full Analysis:\n{result}")

Music Synthesis

Create Indian classical music elements with ease.

Tanpura Drone

Generate a tanpura drone for practice or ambiance.

from bhargava_swara import generate_tanpura_drone

# Play in real-time
generate_tanpura_drone(pitch=261.63, duration=10)

# Save to WAV
generate_tanpura_drone(pitch=261.63, duration=10, output_path="tanpura_drone.wav")

Parameters:

  • pitch: Fundamental frequency of Sa (e.g., 261.63 Hz for C4).
  • duration: Length of the drone in seconds.
  • output_path: Path to save WAV file (optional; if None, plays in real-time).

License

This library is licensed under the MIT License. See the LICENSE file for details.



Change Log
==========

0.0.1 (26/03/2025)
-------------------
- First Release

===========

0.0.2 (27/03/2025)
-------------------
- Fixed missing module files in package

0.0.3 (27/03/2025)
-------------------
- Fixed ornaments detection file

0.0.4 (27/03/2025)
-------------------
- Fixed real time full analysis file

0.0.5 (27/03/2025)
-------------------
- Added mel-frequency spectogram generation

0.0.6 (27/03/2025)
-------------------
- seaborn included. README.txt updated

0.0.7 (27/03/2025)
-------------------
- mel-frequency spectogram issue resolved. README.md is created

0.0.8 (06/04/2025)
-------------------
- 3 more spectogram generations added. README.md file updated

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

bhargava_swara-0.0.11.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

bhargava_swara-0.0.11-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file bhargava_swara-0.0.11.tar.gz.

File metadata

  • Download URL: bhargava_swara-0.0.11.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for bhargava_swara-0.0.11.tar.gz
Algorithm Hash digest
SHA256 92c010db43b3fae0c247208093d3d3f4d6f49eccd5ea01362bb7bc0339f1038e
MD5 57b9f45e7a9da5d4137e388881a953d1
BLAKE2b-256 6007e3ac527cce665beee5a0f84faf04f95bf9d1343ffc9703890ae7c14926ff

See more details on using hashes here.

File details

Details for the file bhargava_swara-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for bhargava_swara-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a509998a26daea9e60840efbbe76615ff30dfecfad38eff16d36da2d4692669e
MD5 1cf7f2660fce51da2b4dbb71fd47dae0
BLAKE2b-256 4d64db48ccc87a46810bf9031a43c17e9659074b2fe5c4a698cbbfda337b5099

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