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:- Sign up for a Google Cloud account
- Enable the Generative AI API in the Google Cloud Console
- 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.0librosa>=0.10.0matplotlib>=3.7.0numpy>=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!")
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)
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 secondsoutput_path: Path to save WAV file (optional; if None, plays in real-time)
Future Development
We plan to enhance Bhargava Swara with the following features:
Spectrogram Enhancements
- Chroma Spectrogram: Add support for visualizing pitch class distributions over time.
- CQT Spectrogram: Implement constant-Q transform spectrograms for better frequency resolution.
- Cent Filterbank Spectrogram: Generate spectrograms using cent-scaled filterbanks for microtonal analysis.
Analysis Features
- Automatic Raga Recognition: Develop algorithms to identify ragas automatically from audio input.
- Tonic Identification: Detect the tonic (base pitch) of a performance for accurate analysis.
- Pitch Extraction: Extract pitch contours from audio to analyze melodic structure.
- Rhythm Analysis: Analyze meter, rhythmic patterns, and structure in talas.
Synthesis Tools
- Tala Generation: Create rhythmic cycles (talas) programmatically for practice or composition.
- Generate Music Based on Raga: Synthesize music adhering to a specific raga's rules.
- Music Imitation: Generate music imitating the style of a given audio input.
Contributions and suggestions for these features are welcome! Please submit ideas or pull requests to the GitHub repository.
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
0.0.9 (06/04/2025)
- fixed bugs
0.0.10 to 0.0.12 (18/04/2025)
- added tanpura droid generation
0.0.13 (18/04/2025)
- removed spectograms
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bhargava_swara-0.0.14.tar.gz.
File metadata
- Download URL: bhargava_swara-0.0.14.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0e2ccb499e58137d32bfc6b131da557471dc9aaf09ece631daa2a20d9848292
|
|
| MD5 |
459f0acbfc68405460807c34eacb0d10
|
|
| BLAKE2b-256 |
c4026516165eef872c442ad88a33780b02f7422fd77ab0eeda0a35779173095a
|
File details
Details for the file bhargava_swara-0.0.14-py3-none-any.whl.
File metadata
- Download URL: bhargava_swara-0.0.14-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98d6156f20f76cf9a89ca132b89c953105bcecb821877c6d57d2e5e1e8689e14
|
|
| MD5 |
74f6a638b52f32838badb1714f7797f9
|
|
| BLAKE2b-256 |
189e456b62a7542a70b67e2404eb31b07d8ba96b959b5ca0c5dde291c17f7b73
|