feat: version song analysis contract and preserve lyric lines

This commit is contained in:
2026-11-01 11:24:21 +01:00
parent cd72278c88
commit 914f9ecfef
17 changed files with 401 additions and 74 deletions

View File

@ -0,0 +1,54 @@
# Song Analysis v2 Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Publish a v2 analysis contract with lyric provenance, stable timeline and correct metadata updates.
**Architecture:** Python writes v2 JSON while Rust reads both versions. Chord data remains raw; supplied lyrics use timed draft phrases to bound line alignment.
**Tech Stack:** Python 3.11, jsonschema, WhisperX, Rust serde.
**Spec:** `docs/superpowers/specs/2026-11-01-song-analysis-v2-design.md`
## Global Constraints
- Preserve existing v1 files and manually edited outputs without `--force`.
- All stored times use seconds from the normalized source origin.
- Do not invent calibrated chord confidence.
## Review Focus
- v1 folder with strict Rust deserialization still loads.
- Supplied lyric section and line boundaries survive.
- Unmatched lyric line does not get an invented timestamp.
- Automatic BPM changes when beat file changes.
- Manual BPM survives a rerun.
---
### Task 1: Contract and metadata
**Files:** `schemas/song-analysis-v2/*`, `src/song_analysis.rs`, `tests/song_analysis_contract.rs`, `tools/song_analysis/cli.py`, `tools/test_song_analysis.py`
- [ ] Write failing Python and Rust tests for v2 fields and v1 compatibility.
- [ ] Run tests and confirm expected failures.
- [ ] Add v2 schemas, version-aware validation and metadata source handling, plus `--title`.
- [ ] Run tests and confirm they pass.
### Task 2: Lyric sections and alignment
**Files:** `tools/song_analysis/{core.py,backends.py,cli.py}`, `tools/test_song_analysis.py`
- [ ] Write failing tests for line parsing, sections, quality and bounded alignment.
- [ ] Run tests and confirm expected failures.
- [ ] Implement line-aware alignment and quality fields.
- [ ] Run tests and confirm they pass.
### Task 3: Reproducibility and guidance
**Files:** `tools/song_analysis/{requirements.txt,README.md}`, `.github/workflows/song-analysis.yml`, `tools/test_song_analysis.py`
- [ ] Pin madmom-infer to the installed commit.
- [ ] Document timeline, unverified drafts, raw chords, time signature support and observed resource costs.
- [ ] Add lightweight CI and opt-in audio smoke test.
- [ ] Run Python tests, Rust contract test, schema validation and `git diff --check`.

View File

@ -0,0 +1,9 @@
# Song Analysis v2 Design
The Python tool keeps raw chord times and `N` spans. Display consumers may snap boundaries to beats and flag spans shorter than 0.5 s; stored times remain unchanged. Chordino's `simplechord` output has no calibrated confidence, so `conf` remains null.
New runs write schema v2. The Rust loader accepts v1 and v2. V2 adds `meta.bpm_source` (`automatic` or `manual`), `meta.source_offset_s` (0), and optional `lyrics.lines[].source_line`, `section`, and `alignment_conf`. With supplied lyrics, input lines and section headings are preserved. WhisperX first transcribes the song to obtain timed phrases, then aligns each supplied line in its own matched phrase window. If matching fails, the line stays unaligned rather than receiving invented timing. A line confidence is the mean of aligned word scores; absent scores yield null. Without supplied lyrics, the output remains a draft with `verified=false`.
`--title` sets the title explicitly. BPM follows `beats.json` unless marked manual, including on reruns. Existing v1 folders remain readable and are not silently rewritten unless a new run writes metadata. The ffmpeg normalization keeps the input timeline origin, so `source_offset_s=0.0`. This does not compensate for encoder delay already present in the decoded source.
Tests cover metadata refresh, v1/v2 loading, lyric structure and windowing. Lightweight CI installs only jsonschema. The optional backend smoke test runs on generated audio in the full environment. CPU timing and observed peak memory are documented as measurements of the one 216 s run, not general guarantees.