An intelligent, multi-agent audio intelligence framework for Semantic Music Structure Analysis (Semantic MSA).
Traditional Music Information Retrieval (MIR) relies on purely acoustic boundary detection or monolithic models that lack semantic grounding. Semantic MSA (tesi_msa) introduces an explainable, bottom-up approach: raw audio is separated, tracked, and discretized into musical tokens (16-beat bars), enriched with physical DSP telemetry, and interpreted by a coordinated team of specialized Large Language Model (LLM) agents to perform macro-structural segmentation, functional labeling, and cross-modal semantic captioning.
intro, verse, chorus, bridge, inst, outro, silence).Raw Audio (.wav / .mp3)
β
βββΊ Demucs v4 (Source Separation: Vocals / Instrumental)
βββΊ BeatNet (Downbeat Grid & BPM Tracking)
βββΊ Cue-DETR (Structural Boundary Priors)
βββΊ WhisperX (Lyrical Transcription & Word Alignment)
βββΊ Vocal Energy VAD (K-Means Clustering)
β
βΌ
βββββββββββββββββββββ
β 16-Beat Telemetry β
β Token Stream β
βββββββββββ¬ββββββββββ
β
βββββββββββββ΄βββββββββββββββββββββββββββββββ
β Multi-Agent LLM Orchestration Engine β
β β
β ββββββββββββββββββ ββββββββββββββββββ β
β β Researcher β β Profiler β β
β β (Web Grounded) β β (DSP Bounds) β β
β βββββββββ¬βββββββββ βββββββββ¬βββββββββ β
β βββββββββββββ¬ββββββββ β
β βΌ β
β ββββββββββββββββββ β
β β Token Captionerβ β
β ββββββββββ¬ββββββββ β
β βΌ β
β ββββββββββββββββββ β
β β Segmenter β β
β ββββββββββ¬ββββββββ β
ββββββββββββββββββββββββΌββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β final.json β
β β’ Macro Structural Boundaries β
β β’ Explainable Segment Rationales β
β β’ Dense 16-Beat Cross-Modal Captions β
ββββββββββββββββββββββββββββββββββββββββββββ
Before any LLM invocation, audio is converted into structured telemetry:
beatnet_engine/: Tracks exact bar-downbeats to establish the 16-beat token boundaries.cue_detr/: Predicts transition points and mixes them into segment candidates.whisper_engine/: Transcribes lyrics with exact sub-second timestamps.telemetry.py: Serializes audio signals into token representations combining RMS vocal density, spectral contrast, percussion energy, and lyrical content.The agents communicate hierarchically:
.
βββ pyproject.toml # UV workspace root configuration
βββ semantic_msa/ # Core framework package
β βββ pyproject.toml
β βββ src/semantic_msa/
β βββ adapters/ # Demucs, Cue-DETR, WhisperX adapters
β βββ agents/ # Multi-agent implementations & pipeline runner
β β βββ core/ # LLM factory, schemas, rate limiter, synthesizer
β β βββ direct_audio.py # Multimodal raw-audio baseline agent
β β βββ pipeline.py # AgentsPipeline orchestrator
β βββ config/ # YAML configurations
β βββ main.py # Feature extraction CLI
βββ eval/ # Benchmark & Evaluation Suite
β βββ agents_inference/ # Batch experiment runner and YAML configs
β βββ dataset_loaders/ # SongFormBench HarmonixSet loader & split tagger
β βββ futga_inference/ # FUTGA baseline conversion and Kaggle inference
β βββ eval_clap_intra_track.py# Intra-track CLAP cross-modal evaluation
β βββ eval_clap_many_to_many.py# Many-to-many cross-track CLAP pool retrieval
β βββ generate_postprocess_json.py # Baseline post-processing & repair
β βββ plot_rq2_*.py # Publication-ready CMC & confusion matrix plots
β βββ to_msa_format.py # Exporter to standard SongFormer MSA format
β βββ eval_artifacts.tar.gz # Compressed reproduction bundle (7.4 MB)
This repository uses uv as its package and workspace manager.
git clone https://github.com/ApuMbett/tesi_msa.git
cd tesi_msa
# Create and synchronize workspace virtual environment
uv sync
Important Note on WhisperX: Upstream WhisperX requirements enforce conflicting PyTorch index URLs (
--extra-index-url cu128). To install WhisperX safely in your environment:uv pip install git+https://github.com/m-bain/whisperx.git@2cfd7b7c5c7bba144954364db747319b50e8232bRun commands with
uv run --no-syncwhen executing to prevent package resolution conflicts.
Create a .env file in semantic_msa/:
cp semantic_msa/.env.example semantic_msa/.env # or create manually
Add your provider API keys:
GEMINI_API_KEY="your-google-gemini-key"
# Optional secondary providers:
OPENROUTER_API_KEY="your-openrouter-key"
GROQ_API_KEY="your-groq-key"
HF_TOKEN="your-huggingface-token"
Extract physical telemetry, stems, beat grids, and transcribe lyrics into data/processed/<track_name>/LLM.json:
uv run --no-sync analyze-track --audio path/to/song.wav --output-dir data/processed/
Run the multi-agent pipeline on an extracted track to produce final.json:
uv run --no-sync run-agents \
--track data/processed/<track_name>/LLM.json \
--config semantic_msa/src/semantic_msa/config/pipeline.yaml \
--run-name evaluation_flash_v1
Run the agent pipeline over an entire directory of tracks:
python eval/agents_inference/run_agents_pipeline.py \
--processed-dir eval/eval_processed \
--config eval/agents_inference/evaluation_flash_lite.yaml \
--run-name flash_lite_run
The evaluation suite benchmarks Semantic MSA against human ground truth (HarmonixSet via SongFormBench) and baseline models across two core Research Questions:
Evaluates boundary precision ($F_{0.58}$, $F_{3.0}$) and functional label classification accuracy against HarmonixSet annotations:
# Convert final.json to standard MSA TXT format
python eval/to_msa_format.py --input-dir eval/eval_processed/ --run-name flash_lite_run
# Compute segment distribution and count statistics
python eval/calculate_average_segments.py
Evaluates whether generated token captions capture distinctive acoustic features using CLAP embeddings:
# Intra-track retrieval (discriminating sections within the same song)
python eval/eval_clap_intra_track.py
# Many-to-many pool retrieval across the full 50-track corpus (500+ segments)
python eval/eval_clap_many_to_many.py
# Generate publication-grade CMC curves and confusion matrices
python eval/plot_rq2_many_to_many.py
Interactive Jupyter notebooks are available in eval/ for running baselines and computing benchmark metrics:
SongFormerBatchInference.ipynb: Executes batch baseline inference for SongFormer across the evaluation corpus.SongFormerEvaluation.ipynb: Computes structural segmentation metrics ($F_{0.58}$, $F_{3.0}$, precision, recall) comparing model predictions against ground-truth annotations.futga_kaggle_inference.ipynb: Standalone Kaggle environment notebook for zero-shot audio captioning inference using FUTGA-7B.The system supports multiple LLM inference providers via LLMFactory:
google-genai): Recommended for speed, native Google Search grounding, and audio multimodal processing.openrouter/<model>): Third-party models.groq/<model>): Low-latency open-source models (Llama 3, Qwen).hf/<model>): Serverless inference.Client-side rate pacing is automatically handled via RateLimiter and exponential backoff retry mechanisms to respect provider RPM limits.
For further details regarding methodology, system evaluation, and theoretical background, please refer to tesi.pdf.
An intelligent, multi-agent audio intelligence framework for Semantic Music Structure Analysis (Semantic MSA).
Traditional Music Information Retrieval (MIR) relies on purely acoustic boundary detection or monolithic models that lack semantic grounding. Semantic MSA (tesi_msa) introduces an explainable, bottom-up approach: raw audio is separated, tracked, and discretized into musical tokens (16-beat bars), enriched with physical DSP telemetry, and interpreted by a coordinated team of specialized Large Language Model (LLM) agents to perform macro-structural segmentation, functional labeling, and cross-modal semantic captioning.
intro, verse, chorus, bridge, inst, outro, silence).Raw Audio (.wav / .mp3)
β
βββΊ Demucs v4 (Source Separation: Vocals / Instrumental)
βββΊ BeatNet (Downbeat Grid & BPM Tracking)
βββΊ Cue-DETR (Structural Boundary Priors)
βββΊ WhisperX (Lyrical Transcription & Word Alignment)
βββΊ Vocal Energy VAD (K-Means Clustering)
β
βΌ
βββββββββββββββββββββ
β 16-Beat Telemetry β
β Token Stream β
βββββββββββ¬ββββββββββ
β
βββββββββββββ΄βββββββββββββββββββββββββββββββ
β Multi-Agent LLM Orchestration Engine β
β β
β ββββββββββββββββββ ββββββββββββββββββ β
β β Researcher β β Profiler β β
β β (Web Grounded) β β (DSP Bounds) β β
β βββββββββ¬βββββββββ βββββββββ¬βββββββββ β
β βββββββββββββ¬ββββββββ β
β βΌ β
β ββββββββββββββββββ β
β β Token Captionerβ β
β ββββββββββ¬ββββββββ β
β βΌ β
β ββββββββββββββββββ β
β β Segmenter β β
β ββββββββββ¬ββββββββ β
ββββββββββββββββββββββββΌββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β final.json β
β β’ Macro Structural Boundaries β
β β’ Explainable Segment Rationales β
β β’ Dense 16-Beat Cross-Modal Captions β
ββββββββββββββββββββββββββββββββββββββββββββ
Before any LLM invocation, audio is converted into structured telemetry:
beatnet_engine/: Tracks exact bar-downbeats to establish the 16-beat token boundaries.cue_detr/: Predicts transition points and mixes them into segment candidates.whisper_engine/: Transcribes lyrics with exact sub-second timestamps.telemetry.py: Serializes audio signals into token representations combining RMS vocal density, spectral contrast, percussion energy, and lyrical content.The agents communicate hierarchically:
.
βββ pyproject.toml # UV workspace root configuration
βββ semantic_msa/ # Core framework package
β βββ pyproject.toml
β βββ src/semantic_msa/
β βββ adapters/ # Demucs, Cue-DETR, WhisperX adapters
β βββ agents/ # Multi-agent implementations & pipeline runner
β β βββ core/ # LLM factory, schemas, rate limiter, synthesizer
β β βββ direct_audio.py # Multimodal raw-audio baseline agent
β β βββ pipeline.py # AgentsPipeline orchestrator
β βββ config/ # YAML configurations
β βββ main.py # Feature extraction CLI
βββ eval/ # Benchmark & Evaluation Suite
β βββ agents_inference/ # Batch experiment runner and YAML configs
β βββ dataset_loaders/ # SongFormBench HarmonixSet loader & split tagger
β βββ futga_inference/ # FUTGA baseline conversion and Kaggle inference
β βββ eval_clap_intra_track.py# Intra-track CLAP cross-modal evaluation
β βββ eval_clap_many_to_many.py# Many-to-many cross-track CLAP pool retrieval
β βββ generate_postprocess_json.py # Baseline post-processing & repair
β βββ plot_rq2_*.py # Publication-ready CMC & confusion matrix plots
β βββ to_msa_format.py # Exporter to standard SongFormer MSA format
β βββ eval_artifacts.tar.gz # Compressed reproduction bundle (7.4 MB)
This repository uses uv as its package and workspace manager.
git clone https://github.com/ApuMbett/tesi_msa.git
cd tesi_msa
# Create and synchronize workspace virtual environment
uv sync
Important Note on WhisperX: Upstream WhisperX requirements enforce conflicting PyTorch index URLs (
--extra-index-url cu128). To install WhisperX safely in your environment:uv pip install git+https://github.com/m-bain/whisperx.git@2cfd7b7c5c7bba144954364db747319b50e8232bRun commands with
uv run --no-syncwhen executing to prevent package resolution conflicts.
Create a .env file in semantic_msa/:
cp semantic_msa/.env.example semantic_msa/.env # or create manually
Add your provider API keys:
GEMINI_API_KEY="your-google-gemini-key"
# Optional secondary providers:
OPENROUTER_API_KEY="your-openrouter-key"
GROQ_API_KEY="your-groq-key"
HF_TOKEN="your-huggingface-token"
Extract physical telemetry, stems, beat grids, and transcribe lyrics into data/processed/<track_name>/LLM.json:
uv run --no-sync analyze-track --audio path/to/song.wav --output-dir data/processed/
Run the multi-agent pipeline on an extracted track to produce final.json:
uv run --no-sync run-agents \
--track data/processed/<track_name>/LLM.json \
--config semantic_msa/src/semantic_msa/config/pipeline.yaml \
--run-name evaluation_flash_v1
Run the agent pipeline over an entire directory of tracks:
python eval/agents_inference/run_agents_pipeline.py \
--processed-dir eval/eval_processed \
--config eval/agents_inference/evaluation_flash_lite.yaml \
--run-name flash_lite_run
The evaluation suite benchmarks Semantic MSA against human ground truth (HarmonixSet via SongFormBench) and baseline models across two core Research Questions:
Evaluates boundary precision ($F_{0.58}$, $F_{3.0}$) and functional label classification accuracy against HarmonixSet annotations:
# Convert final.json to standard MSA TXT format
python eval/to_msa_format.py --input-dir eval/eval_processed/ --run-name flash_lite_run
# Compute segment distribution and count statistics
python eval/calculate_average_segments.py
Evaluates whether generated token captions capture distinctive acoustic features using CLAP embeddings:
# Intra-track retrieval (discriminating sections within the same song)
python eval/eval_clap_intra_track.py
# Many-to-many pool retrieval across the full 50-track corpus (500+ segments)
python eval/eval_clap_many_to_many.py
# Generate publication-grade CMC curves and confusion matrices
python eval/plot_rq2_many_to_many.py
Interactive Jupyter notebooks are available in eval/ for running baselines and computing benchmark metrics:
SongFormerBatchInference.ipynb: Executes batch baseline inference for SongFormer across the evaluation corpus.SongFormerEvaluation.ipynb: Computes structural segmentation metrics ($F_{0.58}$, $F_{3.0}$, precision, recall) comparing model predictions against ground-truth annotations.futga_kaggle_inference.ipynb: Standalone Kaggle environment notebook for zero-shot audio captioning inference using FUTGA-7B.The system supports multiple LLM inference providers via LLMFactory:
google-genai): Recommended for speed, native Google Search grounding, and audio multimodal processing.openrouter/<model>): Third-party models.groq/<model>): Low-latency open-source models (Llama 3, Qwen).hf/<model>): Serverless inference.Client-side rate pacing is automatically handled via RateLimiter and exponential backoff retry mechanisms to respect provider RPM limits.
For further details regarding methodology, system evaluation, and theoretical background, please refer to tesi.pdf.