test: add end-to-end integration test for M2 vocals pipeline and eval

This commit is contained in:
2026-11-02 10:42:10 +01:00
parent f1736caff5
commit cdc47bc85a
3 changed files with 909 additions and 128 deletions

View File

@ -9,9 +9,15 @@ dependencies = [
"typer>=0.12.0",
"rich>=13.7.0",
"demucs>=4.0.0",
"torch>=2.0.0",
"torch>=2.4.0",
"torchaudio>=2.4.0",
"soundfile>=0.12.0",
"julius>=0.2.7",
"pyphen>=0.14.0",
"torchcrepe>=0.0.23",
"faster-whisper>=1.0.0",
"scipy>=1.12.0",
"jiwer>=3.0.0",
]
[project.optional-dependencies]
@ -38,6 +44,15 @@ markers = [
"integration: marks tests as integration tests",
]
[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
[tool.uv.sources]
torch = { index = "pytorch-cpu" }
torchaudio = { index = "pytorch-cpu" }
[tool.ruff]
line-length = 120
target-version = "py312"

98
tests/test_pipeline_m2.py Normal file
View File

@ -0,0 +1,98 @@
"""End-to-end integration test for Milestone 2 (Lyrics, Pitch, UltraStar export, and Eval runner)."""
import json
from pathlib import Path
import numpy as np
import soundfile as sf
from songsplit.eval.metrics import evaluate_vocals
from songsplit.export.ultrastar import export_ultrastar, parse_ultrastar
from songsplit.pipeline import PipelineContext
from songsplit.pipeline.s4_pitch import PitchStage
from songsplit.schema.meta import MetaDocument, SourceFileInfo
from songsplit.schema.vocals import VocalsDocument
def test_m2_pitch_ultrastar_and_eval(tmp_path: Path):
song_dir = tmp_path / "song_pkg"
stems_dir = song_dir / "stems"
cache_dir = song_dir / ".cache"
stems_dir.mkdir(parents=True, exist_ok=True)
cache_dir.mkdir(parents=True, exist_ok=True)
# 1. Create a 2.0s 440 Hz (A4 = MIDI 69) test vocal stem
sr = 16000
t = np.linspace(0, 2.0, int(sr * 2.0), endpoint=False)
sine_wave = 0.5 * np.sin(2 * np.pi * 440.0 * t).astype(np.float32)
vocals_wav = stems_dir / "vocals.wav"
sf.write(str(vocals_wav), sine_wave, sr)
# 2. Write mock lyrics in .cache/lyrics_raw.json (two syllables)
lyrics_data = {
"language": "de",
"lines": [
{
"start": 0.2,
"end": 1.8,
"text": "Hal-lo ",
"syllables": [
{"text": "Hal-", "start": 0.2, "end": 0.9},
{"text": "lo ", "start": 0.9, "end": 1.8},
],
}
],
}
(cache_dir / "lyrics_raw.json").write_text(json.dumps(lyrics_data, indent=2))
# 3. Write meta.json
meta = MetaDocument(
title="Integration Song",
artist="Test Singer",
language="de",
duration_sec=2.0,
source_file=SourceFileInfo(path=str(vocals_wav), sha256="fakehash", size_bytes=len(sine_wave)),
created_at="2026-11-02T10:00:00Z",
)
(song_dir / "meta.json").write_text(meta.model_dump_json(indent=2))
# 4. Run PitchStage (CREPE) with crepe_model="tiny" for fast test execution
ctx = PipelineContext(
source_file=vocals_wav,
output_dir=song_dir,
quality="fast", # uses tiny crepe model
)
pitch_stage = PitchStage()
pitch_stage.run(ctx)
vocals_json = song_dir / "vocals.json"
assert vocals_json.exists()
with open(vocals_json, encoding="utf-8") as f:
doc = VocalsDocument.model_validate(json.load(f))
assert len(doc.lines) == 1
sylls = doc.lines[0].syllables
assert len(sylls) == 2
# Sine wave is at 440 Hz -> MIDI 69.0
assert 68.0 <= sylls[0].midi <= 70.0
assert 68.0 <= sylls[1].midi <= 70.0
assert sylls[0].confidence > 0.5
# 5. Export UltraStar song.txt
txt_path = export_ultrastar(song_dir)
assert txt_path.exists()
song = parse_ultrastar(txt_path)
assert song.title == "Integration Song"
assert len(song.lines) == 1
assert len(song.lines[0]) == 2
# Pitch relative to C4 (60) -> 69 - 60 = 9
assert song.lines[0][0].pitch == 9
# 6. Evaluate predicted vocals against ground truth UltraStar song
metrics = evaluate_vocals(doc, song)
assert metrics["mae_timing_ms"] <= 50.0
assert metrics["strict_pitch_accuracy"] >= 0.99
assert metrics["octave_equiv_pitch_accuracy"] >= 0.99
assert metrics["wer"] == 0.0

922
uv.lock generated

File diff suppressed because it is too large Load Diff