feat(pitch): end lines at the end of the strictly voiced run after the last word
Line ends follow CREPE periodicity >= 0.7 after the last syllable. Gaps up to 0.1 s are always bridged, gaps up to 0.3 s only if voicing resumes for >= 0.3 s (held note with dropout, not breath or consonant). Capped at the next line start. Line-end hit rate (<= 0.3 s) over 5 songs: 31% -> 41%, MAE 1.12 s -> 0.98 s. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -39,3 +39,37 @@ def test_no_correction_for_legitimate_contour():
|
||||
]
|
||||
corrected = correct_octave_errors(syllables)
|
||||
assert corrected[1]["midi"] == 64.0
|
||||
|
||||
|
||||
def test_voiced_run_end_bridges_short_gaps():
|
||||
import numpy as np
|
||||
|
||||
from unmix.pipeline.s4_pitch import voiced_run_end
|
||||
|
||||
hop = 0.01
|
||||
v = np.zeros(300, dtype=bool)
|
||||
v[100:150] = True # 1.00-1.50 s
|
||||
v[155:200] = True # gap of 0.05 s, then voiced until 2.00 s
|
||||
v[260:290] = True # separate run after a 0.6 s gap
|
||||
|
||||
assert voiced_run_end(v, 1.0, hop, max_gap_sec=0.1, cap_t=5.0) == pytest.approx(2.0)
|
||||
assert voiced_run_end(v, 1.0, hop, max_gap_sec=0.0, cap_t=5.0) == pytest.approx(1.5)
|
||||
# cap stops the run
|
||||
assert voiced_run_end(v, 1.0, hop, max_gap_sec=0.1, cap_t=1.3) <= 1.31
|
||||
|
||||
|
||||
def test_voiced_run_end_bridges_longer_gap_only_if_voicing_resumes():
|
||||
import numpy as np
|
||||
|
||||
from unmix.pipeline.s4_pitch import voiced_run_end
|
||||
|
||||
hop = 0.01
|
||||
v = np.zeros(400, dtype=bool)
|
||||
v[100:150] = True # 1.00-1.50 s
|
||||
v[170:230] = True # gap 0.20 s, then a long run (0.60 s) until 2.30 s
|
||||
v[250:260] = True # gap 0.20 s, then a short run (0.10 s)
|
||||
|
||||
kwargs = {"resume_max_gap_sec": 0.3, "resume_min_run_sec": 0.3}
|
||||
assert voiced_run_end(v, 1.0, hop, 0.1, 5.0, **kwargs) == pytest.approx(2.3)
|
||||
# without the resume rule the 0.2 s gap ends the run
|
||||
assert voiced_run_end(v, 1.0, hop, 0.1, 5.0) == pytest.approx(1.5)
|
||||
|
||||
Reference in New Issue
Block a user