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:
@ -295,9 +295,16 @@ def parse_ultrastar(file_path: Path) -> UltraStarSong:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Note line: : 10 4 2 text
|
# Note line: : 10 4 2 text
|
||||||
match = re.match(r"^([:*FR])\s+(-?\d+)\s+(\d+)\s+(-?\d+)\s*(.*)$", line)
|
# The lyric starts after exactly one separator space; further leading spaces mark a word start
|
||||||
|
# (leading-space convention) and are normalised to a trailing space on the previous note below.
|
||||||
|
match = re.match(r"^([:*FR])\s+(-?\d+)\s+(\d+)\s+(-?\d+)(?: (.*))?$", line)
|
||||||
if match:
|
if match:
|
||||||
ntype, s_beat, dur, pitch, text = match.groups()
|
ntype, s_beat, dur, pitch, text = match.groups()
|
||||||
|
text = text or ""
|
||||||
|
if text.startswith(" "):
|
||||||
|
text = text.lstrip(" ")
|
||||||
|
if current_line and not current_line[-1].text.endswith(" "):
|
||||||
|
current_line[-1].text += " "
|
||||||
note = UltraStarNote(
|
note = UltraStarNote(
|
||||||
note_type=ntype,
|
note_type=ntype,
|
||||||
start_beat=int(s_beat),
|
start_beat=int(s_beat),
|
||||||
|
|||||||
@ -196,3 +196,23 @@ E
|
|||||||
assert len(loaded.lines) == 2
|
assert len(loaded.lines) == 2
|
||||||
assert loaded.lines[0].syllables[2].type == "golden"
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user