feat(example): add synthetic demo song package and test suite
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -41,6 +41,9 @@ testdata/
|
|||||||
*.flac
|
*.flac
|
||||||
*.ogg
|
*.ogg
|
||||||
|
|
||||||
|
# Allow synthetic demo audio
|
||||||
|
!examples/demo_song/stems/*.wav
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|||||||
26
examples/demo_song/chords.json
Normal file
26
examples/demo_song/chords.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"schema_version": "1.0",
|
||||||
|
"generated_by": null,
|
||||||
|
"chords": [
|
||||||
|
{
|
||||||
|
"start_beat": 0.0,
|
||||||
|
"end_beat": 4.0,
|
||||||
|
"label": "Am",
|
||||||
|
"root": "A",
|
||||||
|
"quality": "min",
|
||||||
|
"bass": "A",
|
||||||
|
"confidence": 0.9,
|
||||||
|
"source": "auto"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start_beat": 4.0,
|
||||||
|
"end_beat": 6.0,
|
||||||
|
"label": "C",
|
||||||
|
"root": "C",
|
||||||
|
"quality": "maj",
|
||||||
|
"bass": "C",
|
||||||
|
"confidence": 0.88,
|
||||||
|
"source": "auto"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
53
examples/demo_song/meta.json
Normal file
53
examples/demo_song/meta.json
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"schema_version": "1.0",
|
||||||
|
"generated_by": null,
|
||||||
|
"title": "Demo Song",
|
||||||
|
"artist": "Synthetic Artist",
|
||||||
|
"language": "en",
|
||||||
|
"duration_sec": 3.0,
|
||||||
|
"source_file": {
|
||||||
|
"path": "examples/demo_song/stems/vocals.wav",
|
||||||
|
"sha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"size_bytes": 529200
|
||||||
|
},
|
||||||
|
"key": "Am",
|
||||||
|
"capo": 0,
|
||||||
|
"models_used": [
|
||||||
|
{
|
||||||
|
"stage": "s2_stems",
|
||||||
|
"name": "htdemucs",
|
||||||
|
"version": "v4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"stage": "s3_lyrics",
|
||||||
|
"name": "faster-whisper",
|
||||||
|
"version": "large-v3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"stage": "s4_pitch",
|
||||||
|
"name": "torchcrepe",
|
||||||
|
"version": "tiny"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"stage": "s5_tempo",
|
||||||
|
"name": "beat-this",
|
||||||
|
"version": "final0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"stage": "s6_chords",
|
||||||
|
"name": "chord-extractor",
|
||||||
|
"version": "0.2"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"created_at": "2026-11-02T12:00:00Z",
|
||||||
|
"stages_done": [
|
||||||
|
"s1_extract",
|
||||||
|
"s2_stems",
|
||||||
|
"s3_lyrics",
|
||||||
|
"s4_pitch",
|
||||||
|
"s5_tempo",
|
||||||
|
"s6_chords",
|
||||||
|
"s7_strumming"
|
||||||
|
],
|
||||||
|
"stages_failed": {}
|
||||||
|
}
|
||||||
10
examples/demo_song/song.txt
Normal file
10
examples/demo_song/song.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#TITLE:Demo Song
|
||||||
|
#ARTIST:Synthetic Artist
|
||||||
|
#MP3:stems/vocals.wav
|
||||||
|
#BPM:480.00
|
||||||
|
#GAP:500
|
||||||
|
#LANGUAGE:en
|
||||||
|
: 0 4 -3 Hel
|
||||||
|
: 4 4 -3 lo
|
||||||
|
: 8 8 0 world
|
||||||
|
E
|
||||||
BIN
examples/demo_song/stems/bass.wav
Normal file
BIN
examples/demo_song/stems/bass.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/drums.wav
Normal file
BIN
examples/demo_song/stems/drums.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/instrumental.wav
Normal file
BIN
examples/demo_song/stems/instrumental.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/other.wav
Normal file
BIN
examples/demo_song/stems/other.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/vocals.wav
Normal file
BIN
examples/demo_song/stems/vocals.wav
Normal file
Binary file not shown.
42
examples/demo_song/strumming.json
Normal file
42
examples/demo_song/strumming.json
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"schema_version": "1.0",
|
||||||
|
"generated_by": null,
|
||||||
|
"events": [
|
||||||
|
{
|
||||||
|
"beat": 0.0,
|
||||||
|
"direction": "down",
|
||||||
|
"strength": 0.9,
|
||||||
|
"confidence": 0.85,
|
||||||
|
"source": "auto"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"beat": 0.5,
|
||||||
|
"direction": "up",
|
||||||
|
"strength": 0.7,
|
||||||
|
"confidence": 0.8,
|
||||||
|
"source": "auto"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"beat": 1.0,
|
||||||
|
"direction": "down",
|
||||||
|
"strength": 0.85,
|
||||||
|
"confidence": 0.85,
|
||||||
|
"source": "auto"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"beat": 1.5,
|
||||||
|
"direction": "up",
|
||||||
|
"strength": 0.75,
|
||||||
|
"confidence": 0.82,
|
||||||
|
"source": "auto"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"start_beat": 0.0,
|
||||||
|
"end_beat": 4.0,
|
||||||
|
"pattern": "D U D U",
|
||||||
|
"grid": "8th"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
examples/demo_song/tempo.json
Normal file
16
examples/demo_song/tempo.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"schema_version": "1.0",
|
||||||
|
"generated_by": null,
|
||||||
|
"anchors": [
|
||||||
|
{
|
||||||
|
"sec": 0.0,
|
||||||
|
"beat": 0.0,
|
||||||
|
"bpm": 120.0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time_signature": {
|
||||||
|
"numerator": 4,
|
||||||
|
"denominator": 4
|
||||||
|
},
|
||||||
|
"downbeat_offset": 0
|
||||||
|
}
|
||||||
39
examples/demo_song/vocals.json
Normal file
39
examples/demo_song/vocals.json
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"schema_version": "1.0",
|
||||||
|
"generated_by": null,
|
||||||
|
"lines": [
|
||||||
|
{
|
||||||
|
"start": 0.5,
|
||||||
|
"end": 2.5,
|
||||||
|
"syllables": [
|
||||||
|
{
|
||||||
|
"text": "Hel",
|
||||||
|
"start": 0.5,
|
||||||
|
"end": 1.0,
|
||||||
|
"midi": 57.0,
|
||||||
|
"golden": false,
|
||||||
|
"confidence": 0.95,
|
||||||
|
"source": "auto"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "lo ",
|
||||||
|
"start": 1.0,
|
||||||
|
"end": 1.5,
|
||||||
|
"midi": 57.0,
|
||||||
|
"golden": false,
|
||||||
|
"confidence": 0.92,
|
||||||
|
"source": "auto"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "world",
|
||||||
|
"start": 1.5,
|
||||||
|
"end": 2.5,
|
||||||
|
"midi": 60.0,
|
||||||
|
"golden": false,
|
||||||
|
"confidence": 0.98,
|
||||||
|
"source": "auto"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
98
tests/test_demo_package.py
Normal file
98
tests/test_demo_package.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
"""Test the demo song package in examples/demo_song."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import soundfile as sf
|
||||||
|
|
||||||
|
from songsplit.export.ultrastar import parse_ultrastar
|
||||||
|
from songsplit.schema.chords import ChordsDocument
|
||||||
|
from songsplit.schema.meta import MetaDocument
|
||||||
|
from songsplit.schema.strumming import StrummingDocument
|
||||||
|
from songsplit.schema.tempo import TempoDocument
|
||||||
|
from songsplit.schema.vocals import VocalsDocument
|
||||||
|
|
||||||
|
|
||||||
|
def test_demo_package_structure():
|
||||||
|
demo_dir = Path("examples/demo_song")
|
||||||
|
assert demo_dir.is_dir()
|
||||||
|
|
||||||
|
required_files = [
|
||||||
|
"meta.json",
|
||||||
|
"tempo.json",
|
||||||
|
"vocals.json",
|
||||||
|
"chords.json",
|
||||||
|
"strumming.json",
|
||||||
|
"song.txt",
|
||||||
|
]
|
||||||
|
for rf in required_files:
|
||||||
|
p = demo_dir / rf
|
||||||
|
assert p.is_file(), f"Missing {rf} in demo package"
|
||||||
|
|
||||||
|
stems_dir = demo_dir / "stems"
|
||||||
|
assert stems_dir.is_dir()
|
||||||
|
for stem_name in ["vocals.wav", "instrumental.wav", "drums.wav", "bass.wav", "other.wav"]:
|
||||||
|
p = stems_dir / stem_name
|
||||||
|
assert p.is_file(), f"Missing stem {stem_name} in demo package"
|
||||||
|
|
||||||
|
|
||||||
|
def test_demo_package_schemas():
|
||||||
|
demo_dir = Path("examples/demo_song")
|
||||||
|
|
||||||
|
# Meta
|
||||||
|
meta_raw = json.loads((demo_dir / "meta.json").read_text(encoding="utf-8"))
|
||||||
|
meta = MetaDocument.model_validate(meta_raw)
|
||||||
|
assert meta.title == "Demo Song"
|
||||||
|
assert meta.schema_version == "1.0"
|
||||||
|
assert meta.duration_sec > 0
|
||||||
|
|
||||||
|
# Tempo
|
||||||
|
tempo_raw = json.loads((demo_dir / "tempo.json").read_text(encoding="utf-8"))
|
||||||
|
tempo = TempoDocument.model_validate(tempo_raw)
|
||||||
|
assert len(tempo.anchors) >= 1
|
||||||
|
assert tempo.anchors[0].bpm == 120.0
|
||||||
|
assert tempo.time_signature.numerator == 4
|
||||||
|
|
||||||
|
# Vocals
|
||||||
|
vocals_raw = json.loads((demo_dir / "vocals.json").read_text(encoding="utf-8"))
|
||||||
|
vocals = VocalsDocument.model_validate(vocals_raw)
|
||||||
|
assert len(vocals.lines) >= 1
|
||||||
|
assert len(vocals.lines[0].syllables) == 3
|
||||||
|
|
||||||
|
# Chords
|
||||||
|
chords_raw = json.loads((demo_dir / "chords.json").read_text(encoding="utf-8"))
|
||||||
|
chords = ChordsDocument.model_validate(chords_raw)
|
||||||
|
assert len(chords.chords) == 2
|
||||||
|
assert chords.chords[0].label == "Am"
|
||||||
|
|
||||||
|
# Strumming
|
||||||
|
strumming_raw = json.loads((demo_dir / "strumming.json").read_text(encoding="utf-8"))
|
||||||
|
strumming = StrummingDocument.model_validate(strumming_raw)
|
||||||
|
assert len(strumming.events) == 4
|
||||||
|
assert len(strumming.patterns) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_demo_package_audio_properties():
|
||||||
|
demo_dir = Path("examples/demo_song")
|
||||||
|
stems = ["vocals.wav", "instrumental.wav", "drums.wav", "bass.wav", "other.wav"]
|
||||||
|
|
||||||
|
for s in stems:
|
||||||
|
path = demo_dir / "stems" / s
|
||||||
|
info = sf.info(str(path))
|
||||||
|
assert info.samplerate == 44100
|
||||||
|
assert info.channels == 2
|
||||||
|
assert abs(info.duration - 3.0) < 0.01
|
||||||
|
|
||||||
|
|
||||||
|
def test_demo_package_ultrastar_roundtrip():
|
||||||
|
demo_dir = Path("examples/demo_song")
|
||||||
|
song_txt = demo_dir / "song.txt"
|
||||||
|
parsed = parse_ultrastar(song_txt)
|
||||||
|
|
||||||
|
assert parsed.title == "Demo Song"
|
||||||
|
assert parsed.artist == "Synthetic Artist"
|
||||||
|
assert len(parsed.lines) == 1
|
||||||
|
assert len(parsed.lines[0]) == 3
|
||||||
|
|
||||||
|
texts = [s.text for s in parsed.lines[0]]
|
||||||
|
assert texts == ["Hel", "lo ", "world"]
|
||||||
Reference in New Issue
Block a user