fix(ultrastar): keep word boundaries of the leading-space convention

parse_ultrastar swallowed the leading space that marks a word start in some files
(e.g. Uriah Heep - Lady In Black), gluing a whole line into one 'word' and inflating
the WER (4.42 -> 0.43). Leading spaces are now normalised to a trailing space on the
previous note.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 13:29:25 +01:00
parent 904ce6253f
commit 861f6a29f2
2 changed files with 28 additions and 1 deletions

View File

@ -196,3 +196,23 @@ E
assert len(loaded.lines) == 2
assert loaded.lines[0].syllables[2].type == "golden"
def test_parse_ultrastar_leading_space_word_convention(tmp_path):
from unmix.eval.metrics import extract_text_from_reference
from unmix.export.ultrastar import parse_ultrastar
f = tmp_path / "lead.txt"
f.write_text(
"#TITLE:T\n#ARTIST:A\n#BPM:120\n#GAP:0\n"
": 0 4 4 She\n: 8 6 9 came\n: 18 2 9 to\n: 22 4 9 ~r\n- 30\n: 32 4 2 me\nE\n",
encoding="utf-8",
)
song = parse_ultrastar(f)
assert extract_text_from_reference(song) == "She came to~r me"
assert song.lines[0][0].text == "She "
assert song.lines[0][1].text == "came "
# trailing-space convention is unchanged
g = tmp_path / "trail.txt"
g.write_text("#BPM:120\n#GAP:0\n: 0 4 4 We \n: 5 4 4 do \nE\n", encoding="utf-8")
assert extract_text_from_reference(parse_ultrastar(g)) == "We do"