Previously the vendored references/pre2015_jingle_variant_b.flac only
helped via _sibling_fallback's own DTW fallback, which is scoped to a
narrow +/-2 neighbour radius -- confirmed matches like hpr0908, hpr1117,
and hpr1467 are nowhere near hpr0900 or each other, so they'd never have
been found that way.
Adds detect._check_pre2015_variants: checks every vendored pre-2015
jingle variant directly against the episode being detected (fast
correlation first, DTW chroma matching as the per-variant fallback),
tried before falling back to neighbour-matching. This is the pre-2015
era's main-line reference check now, not just a neighbour-radius
fallback -- the old episodes are this tool's core use case, not an edge
case, and the ones most likely to have no official SRT and no other
usable signal.
Verified directly against real episodes outside any neighbour
relationship: hpr0908/hpr1117/hpr1467 resolve via fast correlation,
hpr0901/hpr0902 (tempo-drifted) via DTW, hpr0898 (confirmed no intro)
correctly finds nothing. hpr0899, previously assumed a non-match from
the old buggy correlation-only approach, now also resolves as a real
match -- consistent with that earlier label having been wrong.
Fixed-lag cross-correlation (even after the leading_anchor_windows fix)
cannot find every real match: hpr0901 and hpr0902 share hpr0900's
confirmed jingle (by ear, and by a matching ~34s intro-envelope duration
across all three) but never correlate above ~0.3-0.4 against it at any
single fixed lag or speed ratio, because the jingle has internal tempo
variation no global alignment can follow.
Adds audio.dtw_chroma_match: chroma-feature DTW against a reference
clip, which isn't defeated by that since it doesn't assume one global
alignment, and whose warping-path end position gives a real intro_end
estimate. Optional dependency (librosa), same philosophy as ASR -- a
missing import returns None, never an exception. Wired into
detect._sibling_fallback as a last resort, tried only when fixed-lag
correlation finds nothing, since it's far more expensive.
Calibrated on real episodes against the newly vendored
references/pre2015_jingle_variant_b.flac (hpr0900's jingle, confirmed
to recur in ~5% of a random sample): confirmed/likely matches scored
cost 0.09-0.17, a confirmed non-match (hpr0898, no intro at all) scored
0.94. Also tried and rejected for this purpose: generic chroma
classification (can't tell whose music it is, not just that it's music)
and chromaprint/pyacoustid fingerprinting (clean separation but no
tolerance for tempo drift). See docs/DESIGN.md for the full writeup,
including a screenshot showing the matching intro-envelope duration
that motivated this.
showwavespic/showspectrumpic render one summary frame for the whole
stream they're given; output-side seeking (-ss after -i, what the script
had) silently produces zero frames with them, rather than erroring.
Found directly: every prior use of this script happened to start at 0,
so a nonzero start offset was never actually exercised until now. Moved
-ss before -i (input-side seeking), which is both correct here and
normally faster since ffmpeg can seek without decoding up to that point.
leading_match_seconds's gap-tolerance rule treated any two consecutive
borderline-low correlation windows as fatal, even with a long, clean,
sustained match starting immediately after them. Found directly:
comparing hpr0900's own audio across two different codecs (mp3 vs opus)
-- identical underlying content -- a minor codec-boundary artifact in
the first ~0.75s made the old rule report 0.25s for what a full
non-windowed cross-correlation confirmed was actually a 0.9979 overall
match at zero lag. Replaced with the same qualifying-run logic
last_high_correlation_run_seconds already used (factored out via
_qualifying_runs()), taking the first run instead of the last.
This is a real, general fix, but it does not explain hpr0900 itself:
re-tested against 17 candidates spanning the whole pre-2015 range with
the fix applied, still found nothing. The user confirmed by ear that
hpr0900's ~15-20s intro is a real, recognizable station jingle, so there
appears to be a second distinct jingle variant in circulation that
episode-number proximity doesn't predict and no tested sample shares --
documented as an open item (a vendored reference-variant library is the
likely right fix, not a wider search radius).
Also revisited the earlier librosa dismissal in Open Items: the bug just
found is specifically a hard-threshold brittleness problem, which is a
different and stronger reason to reconsider a continuous multi-feature
score than the original evaluation considered.
New test: test_leading_match.py, using the exact corrs pattern observed.
- detect.py: _best_sibling_estimate() replaces a median/consensus across
neighbouring episodes with the best match found. Found directly on a
user-reported case (hpr0400): its three closest neighbours correlated
at ~0 since they don't share this episode's specific jingle variant,
but a fourth matched cleanly at 29.25s -- the median discarded that
real evidence because it was outvoted by neighbours that simply aren't
relevant, not because the intro genuinely doesn't match anything. Only
the case where nothing nearby correlates at all is still flagged
inconclusive.
- cli.py: trim --episode N with no prior detect for that episode used to
silently do nothing -- no output, no error, exit 0. Now errors clearly
and tells the user to run detect first; a batch trim over a range still
treats this as normal and reports a count instead. Also made trim's
metadata connection lazy, so the error path doesn't need network access
at all (a test that exercises it dropped from ~4s to instant).
- docs/DESIGN.md: documented both fixes, and the format-default/
--format/precision fixes from immediately before this round.
New tests: test_sibling_aggregation.py, test_cli_trim_errors.py.
The Cut-point detection strategy and Edge cases sections had accumulated
a lot of 'found via X, fixed in version Y, see test Z' narrative layered
into what should be a technical description of current behavior --
several entries were even describing bugs that are now fixed, misfiled
under 'known limitations.'
Rewrote both to state current behavior and real current limitations in
present tense. Consolidated the historical blow-by-blow (specific
episodes, before/after measurements, which bug was found by which test)
into one short 'Notable fixes along the way' section, with a pointer to
git history and tests/ for full detail rather than duplicating it inline.
Also fixed a stale claim in 'Fit with HPR's own ethos' that still said
the synopsis-text reproduction was 'not yet built' after it had become
the primary detection method.
No functional changes. 594 lines, down from 704.
markers.find_intro_end_via_synopsis sequence-aligns the ASR transcript
against metadata.synopsis_text()'s deterministic reconstruction of the
expected per-episode announcement text (the say.php reproduction from
earlier), rather than matching against a fixed phrase list. This was a
direct response to the pattern across the last several fixes: each one
patched a single new mis-hearing variant, with no ceiling on how many
exist. Sequence alignment tolerates scattered word-level ASR errors
throughout the transcript, not just at phrase boundaries someone thought
to special-case.
Applied to both the official-SRT and ASR-anchor paths (_resolve_intro_end
in detect.py), since wording drift and ASR mis-hearings affect both.
Falls back to the existing fixed-phrase matching when there's no
expected text to align against, and still defers to it entirely for the
sponsor-ad-read continuation, which has no deterministic per-episode
text of its own.
Live-verified: hpr2157 moved from 15.1s (old marker match) to 30.6s;
hpr3237 to 34.7s; hpr3009 (Linux Inlaws) extended further but stayed
correctly flagged rather than silently trusted; hpr4775 now resolves via
official_srt+synopsis_alignment+reference_xcorr_floor, composing all
three recent fixes. hpr1892 correctly still returns None -- its garbling
is concentrated in the first ~17 words, with no confident anchor near
the start, which the leading-anchor check is specifically designed to
catch rather than trust a coincidental later match.
Also fixes a real bug found while validating this: the sponsor-ad-read
continuation was filtering segments by end time instead of start time,
so a segment that merely ended near the anchor but started before it
broke the extension chain immediately, discarding a real extension
(caught on hpr2157's own sponsor read).
New test file test_synopsis_alignment.py (8 tests), plus two tests
locking in the earlier narrowly-scoped fuzzy-threshold exception for the
station-name marker (validated against both the real mis-hearing and the
original hpr0500 regression case before being enabled).
Logged for completeness, not as a planned feature: tested against
theme.flac and two real episodes, mixed results (chroma_stability alone
independently reproduced the hpr4775 gap boundary, but the one old-era
test that would actually matter -- no reference clip exists for that
era -- was inconclusive). Not adopted; would need real verified test
cases from the pre-2015 era before it's worth revisiting.
- 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.
- config.py/fetch.py: enforce a minimum gap between any requests to HPR's
servers (fetch._wait_for_politeness_gap()), regardless of which
function issues them. Not needed for someone who already understands
HPR's infrastructure, but a real consideration for a future user who
doesn't -- a sweep makes several requests per episode across thousands
of episodes.
- markers.json (version 3): found via the same random-sample-then-
visualize technique used for the earlier hpr4775 fix. hpr2157's era
apparently used the bare 'HPR episode' rather than 'Hacker Public Radio
episode', which fell all the way through to a much weaker sibling-
correlation fallback (3.25s) instead of a proper marker match (now
15.1s); Whisper tiny mis-hearing 'Today's' as 'To its' on hpr3356 broke
the same marker a different way (8.0s -> 26.6s). hpr3356 itself is an
unusual 282-minute special episode that remains correctly flagged for
manual review even after the fix.
- docs/DESIGN.md: corrected an overstated claim ('retry with backoff')
that was never actually implemented; documented the real smoke test
(SIGINT mid-episode, resumed, interrupted again, resumed to
completion -- no lost work, no stray subprocesses, no ledger
corruption) and a real full-corpus timing estimate (32.1s/episode
average on the hardest episode category, so on the order of 1-2 days
for the full archive, not weeks).
- New regression tests for the politeness delay and both marker fixes.
Fetches HPR's own metadata, audio, and official transcripts live; falls
back to local speech recognition (tiny model, matching HPR's own
hpr-get-and-transcribe.bash tooling) only when needed, and to
correlation against vendored reference clips or sibling episodes
otherwise. License-aware, resumable, and never guesses -- flags
anything it isn't confident about for manual review rather than
producing a plausible-looking wrong cut.