- audio.py: last_high_correlation_run_seconds() replaces a simple leading-run count for the theme.flac correlation specifically. The TTS speech is mixed additively onto the theme bed (sox -m), so correlation predictably drops once speech masks it even though the theme is still playing underneath; the old algorithm couldn't recover once correlation legitimately resumed afterwards (a genuine silence/instrumental gap before the host's own content). Requires the first qualifying run to start near the beginning, so a later island of coincidental correlation is never trusted without a confirmed anchor. Verified live: hpr4775 now resolves to 40.5s, matching the real boundary (confirmed by waveform inspection) almost exactly, instead of 27.3s. - markers.py: fixed fuzzy_contains() comparing a raw (un-normalized) marker string against normalized text -- a marker containing punctuation, like 'archive.org', could never match. Found by a failing test, not by inspection. - markers.json (version 4): enumerated the two sponsor ad-read scripts observed so far (anhonesthost.com, archive.org/Internet Archive) as markers, the same way outro_markers are -- not a generic 'small gap after a match still counts' heuristic, which was considered and rejected since it would swallow a host's own content whenever they talk immediately after the TTS block with no gap, which is the common case. - docs/DESIGN.md: marked the silence-gap limitation resolved, documented the normalize bug, and added a short discussion of why general music/audio detection wouldn't have solved the sponsor-ad-read problem (it's audio-feature-identical to host speech) even though it was and remains the right tool for the music-bed boundary specifically. - New regression tests for the correlation fix and both marker additions.
44 lines
2.0 KiB
Python
44 lines
2.0 KiB
Python
import unittest
|
|
|
|
from hpr_stripper.audio import last_high_correlation_run_seconds
|
|
|
|
|
|
class TestLastHighCorrelationRun(unittest.TestCase):
|
|
def test_bridges_a_masked_gap_like_hpr4775(self):
|
|
# Modelled on the real hpr4775 pattern: high correlation from the
|
|
# start (theme bed, unmasked), a long masked stretch while TTS
|
|
# speech dominates (correlation drops but the theme is still
|
|
# legitimately playing underneath), then a genuine quiet/
|
|
# instrumental-only tail where correlation climbs back up before
|
|
# the host's own content begins. The old leading-run algorithm
|
|
# would have stopped at the first dip; this must bridge it.
|
|
corrs = [0.99] * 24 + [0.2] * 80 + [0.95] * 20 + [0.1] * 20
|
|
win_sec = 0.25
|
|
result = last_high_correlation_run_seconds(corrs, win_sec)
|
|
self.assertAlmostEqual(result, (24 + 80 + 20) * win_sec, places=4)
|
|
|
|
def test_pure_leading_run_with_no_gap_still_works(self):
|
|
corrs = [0.99] * 60 + [0.1] * 40
|
|
result = last_high_correlation_run_seconds(corrs, 0.25)
|
|
self.assertAlmostEqual(result, 60 * 0.25, places=4)
|
|
|
|
def test_no_leading_anchor_returns_zero(self):
|
|
# The reference isn't correlated from the start at all -- a later
|
|
# coincidental high-correlation island must not be trusted as a
|
|
# real boundary, since there's no confirmed anchor to bridge from.
|
|
corrs = [0.1] * 50 + [0.95] * 10 + [0.1] * 10
|
|
result = last_high_correlation_run_seconds(corrs, 0.25)
|
|
self.assertEqual(result, 0.0)
|
|
|
|
def test_single_window_noise_spike_is_ignored(self):
|
|
# A lone high-correlation window inside an otherwise-uncorrelated
|
|
# stretch shouldn't extend the boundary -- only runs of at least
|
|
# min_run_windows count.
|
|
corrs = [0.99] * 10 + [0.1] * 30 + [0.97] + [0.1] * 10
|
|
result = last_high_correlation_run_seconds(corrs, 0.25)
|
|
self.assertAlmostEqual(result, 10 * 0.25, places=4)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|