Files
hpr-intro-stripper/docs/DESIGN.md
T

548 lines
30 KiB
Markdown
Raw Normal View History

# Design
Detailed technical background for `hpr-intro-stripper`. For usage, see the
top-level [README.md](../README.md).
## Goals & non-goals
**Goals:**
- Given an HPR episode number (or a range), produce the "inner" audio — the
host's originally submitted recording, with HPR's own added intro and
outro removed — individually or in batch.
- Work unattended against the live HPR archive: fetch whatever
metadata/audio/transcript it needs itself, rather than assuming a
pre-populated local mirror.
- Run on modest hardware. No step requires a GPU or a specific speech-
recognition setup. Dependency weight is comparable to a repo that says "install these
packages from your distro" — `ffmpeg`, Python 3, `numpy`, `sqlite3`,
`awk`, optionally one CPU ASR tool — not a PyTorch/CUDA stack as a hard
requirement.
- Be safe by default: never silently produce or redistribute a trimmed
derivative of a No-Derivatives-licensed episode; never touch audio the
detector isn't confident about; always leave an audit trail (what was
cut, by which method, with what confidence) alongside trimmed output.
**Non-goals:**
- Not a bulk mirror of HPR's audio. No episode audio or bulk transcript
corpus lives in this repo — only code, a small marker-phrase library, and
a per-episode cut-point cache (gitignored).
- Not a replacement for HPR's own transcription pipeline. Where HPR already
publishes a transcript/SRT, this tool uses it rather than re-deriving it.
- Not an attempt to perfectly restore the exact original submitted file
byte-for-byte — the goal is the host's spoken content, cleanly bounded,
not bit-identical reconstruction.
## Why this is harder than "just trim N seconds"
The intro/outro have never been one fixed-length clip across HPR's
18-year history, and the boundary moved more than once:
- **Pre-~2015 (roughly episode <1700):** no spoken announcement at all —
just a shared, unchanging music jingle before the host's own cold open.
Confirmed by cross-correlating two episodes' openings sample-for-sample:
hpr0500 vs hpr0600 matched at r≥0.99 for exactly 15.0s, then diverged
sharply. This era is the one case where "fixed timing" really is
trivial, if you know the length.
- **~2015 onward:** HPR began auto-generating a spoken per-episode
metadata announcement (episode number, date, title, series, flag,
summary) read before the host's own greeting. Its *length is not
fixed* — it tracks how much text there is to read — and its exact
wording drifted at least twice more. ASR testing across 9 real episodes
(2008–2025) measured intro lengths from 13s to 48s depending on
title/summary length.
- **The outro turns out to be fixed after all** — but only once you know
which asset is current (see below): a single unchanging 40.0-second clip
in the current era, not something to measure per episode, but it has
presumably changed at least once already (branding, hosting-sponsor
wording) and will again.
So "trim N seconds" is right for the outro (per era) and wrong for the
intro (always, by construction) — any workable tool has to detect the
intro boundary per-episode, and detect the outro's *current* fixed length
rather than hard-coding one.
## What HPR's own pipeline already does
Read directly from `repo.anhonesthost.net/HPR/hpr-tools` (cloned locally
and read, not guessed):
- **`workflow/hpr-get-and-transcribe.bash`** runs, on each newly submitted
raw episode file, *before* intro/outro are ever added:
```
whisper --output_format srt --model tiny --language en --output_dir "${show_dir}" "${this_media}"
```
This is HPR's own standard: the smallest Whisper model, on the raw
submission, as routine janitor tooling — strong precedent for what this
project assumes is a reasonable dependency to ask of a contributor's
machine. This repo's own ASR fallback matches it exactly (see "ASR
dependency strategy" below).
- **`workflow/hpr-process_episode.bash`** assembles the final published
SRT by concatenating `intro.srt` (template) + the body SRT from the step
above (time-shifted by the real rendered intro duration, read via
`mediainfo`) + `outro.srt` (time-shifted again). The exact cut points are
computed server-side and deterministic — they're just not published as a
separate field anywhere.
- **`workflow/intro.srt`** (vendored into `references/intro.srt`) is a
5-line template with placeholders for: episode number + date, title,
series, flag + license, summary. Nominal total length 27.32s — but this
is a *default template*; the real TTS-rendered audio varies with actual
text length (matches the 13–48s range measured by ASR).
- **`workflow/outro.srt` + `workflow/outro.flac`** (vendored into
`references/`) are completely static — no per-episode substitution at
all. `outro.flac` measured via `ffprobe` at exactly **40.0 seconds**.
`theme.flac` (the intro music bed, vendored alongside it) measured at
40.52 seconds — the raw bed length available to loop/crop under the TTS
speech, not the per-episode intro duration.
- **`hpr_hub/cms/say.php`** builds the exact spoken announcement text —
the `synopsis` field — by plain string concatenation from the `eps`,
`hosts`, `licenses`, and `miniseries` tables (the same schema the
fetched `hpr.sql` gives this tool). `hpr-process_episode.bash`'s
`create_tts_summary()` then feeds that text verbatim into `piper --model
en_US-ljspeech-high.onnx` with no further processing, and
`generate_intro()` mixes the resulting speech with `theme.flac`
*additively* (`sox -m`, a mix, not a sequential splice) — so the real
intro audio is theme-plus-speech layered together for most of its
length, not theme-then-speech.
**Implication:** for the current era, the outro is not something to
*detect* per episode at all — it's a known, fixed-length clip, safe to
match directly against the vendored `outro.flac`. The intro is the only
part that genuinely requires per-episode detection, though the vendored
`theme.flac` still gives a useful independent boundary signal (see below).
**A documentation/code discrepancy worth noting plainly:**
`hpr_documentation/branding.md` states the intro "will always be 30
seconds long and in some edge cases may be slightly longer." The actual
generation code enforces no such cap (`create_tts_summary()` has no length
limit; `generate_intro()`'s `sox -m` just takes the longer of its two
inputs), and empirical ASR measurements (13–48s) match the code's
behaviour, not the documented policy. Treated here as a sign the docs lag
the implementation in places, not a sign the measurements are wrong.
## Data acquisition
**Audio and sibling files.** Confirmed working endpoint (verified
directly, not guessed):
```
https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hprNNNN/hprNNNN.{mp3,ogg,opus,txt,srt,json}
```
Episode number zero-padded to 4 digits, directory and filename both
`hprNNNN`. **HPR publishes every episode in `mp3`, `ogg`, and `opus`
simultaneously** — format is a configurable preference with fallback
(default order: opus → ogg → mp3), never hardcoded, since `ffmpeg`/
`ffprobe` handle all three natively at no extra dependency cost.
**Design rule, not just a bug workaround: never hardcode a storage backend
host.** The proxy has been observed redirecting to a DigitalOcean Spaces
bucket (`*.digitaloceanspaces.com`) — and hitting that bucket directly can
return an `AccessDenied` XML error even for files the proxy serves fine
(confirmed: `hpr0400`, `hpr1000`). HPR's hosting is explicitly designed to
be swappable (see the CCDN architecture doc's own multi-origin,
DNS-round-robin design), so a URL seen once in a redirect or an error
message is an observation, never a contract. This tool only ever
constructs URLs against `ccdn.php` and follows whatever it redirects to;
it never remembers or reconstructs a backend host itself. `AccessDenied`,
403, 404, and a 200-with-empty-body are all treated as the same outcome —
"not available right now, fall back to the next signal" — never
special-cased per status code.
**No public bulk endpoint exists.**
`HPR/hpr_documentation/ccdn/ccdn_architecture.md` documents HPR's CCDN as
a *private* origin-to-mirror-node design: volunteer-run edge nodes `rsync`
over SSH from a private origin, not open to the public, with directory
browsing explicitly disabled. The practical approach is a polite,
resumable, per-episode HTTP fetch loop — not an attempt to find or build a
bulk-sync path. Concretely: every request to HPR's servers goes through a
single gate (`fetch._wait_for_politeness_gap()`) enforcing a minimum
`config.REQUEST_DELAY_SECONDS` (default 0.5s) between requests, regardless
of which function issued them, and `fetch_audio`/`fetch_official_srt`
skip the network entirely once a file is cached. Retry-with-backoff on a
transient failure is not implemented — a failed request is currently
treated the same as "not available," falling through to the next
detection signal rather than being retried.
**Official transcripts/SRT exist, but coverage is patchy — confirmed by
direct testing, not assumed.** Even episodes from 2024–2025 sometimes
return a genuine transcript, sometimes a 200-with-empty-body placeholder,
and older ones sometimes 404 or 403. **The tool always fetches and checks
actual byte content, never infers availability from the episode page or
from era alone.**
**Metadata.** Fetched from the canonical source —
`https://www.hackerpublicradio.org/hpr.sql` — the exact URL
`hpr_generator`'s own `utils/lib_utils.sh` (`download_hpr_sql`) pulls
from, converted to SQLite with the same vendored `mysql2sqlite` AWK script
HPR's own `update-hpr.sh` uses. This repo ships no snapshot and assumes no
pre-existing local copy; a bootstrap step downloads the current dump and
refreshes it periodically, so every run reflects the live database.
## Cut-point detection strategy
Four layered signals, tried in order, cheapest/most-certain first. Every
episode gets whichever signal actually works for it, plus a record of
which one was used. A code-review pass found that an earlier version of
this document described this cross-checking as already real when it
wasn't yet implemented; `hpr_stripper/detect.py` now actually does what's
described below, not just the parts that were easy.
1. **Official SRT, when present and non-empty.** Gives the boundary for
free — but a present SRT that fails to yield an answer for *one* side
(e.g. only the intro marker matches, not the outro) doesn't suppress
the ASR-anchor fallback for the side it couldn't resolve; each side is
tracked and filled independently. Every accepted result is also
sanity-checked against whichever reference-correlation/metadata signal
is independently available — a disagreement surfaces as a flag on the
result rather than being silently resolved in either direction (see
`DISAGREEMENT_THRESHOLD_SECONDS` in `detect.py`). Caught a real bug
this way during review: see "Era wording drift" under Edge Cases.
2. **Metadata-duration arithmetic, as a cross-check for the modern era.**
The `eps.duration` field appears to represent the *raw submitted*
(pre-intro/outro) length — validated against three real test episodes
(hpr3700: 882s vs. 880.98s measured; hpr3900: 704s vs. 700.34s;
hpr4300: 1105s vs. 1101.7s), all within a few seconds. Does **not** hold
for older episodes (hpr2100: 280s vs. 333.23s measured, a 53s gap) —
likely because this exact invariant in `hpr-process_episode.bash` is
itself a newer part of the pipeline. Used only as corroboration for
recent episodes, never as sole truth for old ones.
3. **ASR-anchor phrase matching on short clips** (`hpr_stripper/detect.py`
+ `hpr_stripper/markers.py`). Extracts only the first ~120s and last
~70s via `ffmpeg` — never the whole episode — transcribes with Whisper,
and fuzzy-matches segments against `hpr_stripper/markers.json` to find
where the templated material starts/stops. Two real false-positive
bugs were found and fixed while building the original prototype this
is ported from (see the docstring in `markers.py` for the full story):
a too-loose fuzzy match once nearly truncated a host's own sign-off by
confusing it with a short outro marker, and a host's organic "this is
X and this is Hacker Public Radio" cold open was once briefly mistaken
for the start of the TTS announcement. Both are fixed by (a) requiring
markers to have ≥5 words before any fuzzy matching applies at all, and
(b) splitting intro markers into "strong" (exact-substring only,
impossible to say by coincidence) vs. "greeting" (can extend an
established run, never start one).
4. **Cross-correlation**, used three ways:
- **Against the vendored reference assets** (`references/theme.flac`,
`references/outro.flac`) — the cleanest signal for the current era.
`outro.flac` is the *complete* rendered outro; correlating it
directly against an episode's tail is simpler and more universal
than comparing to a sibling episode, and self-detects when HPR
changes the asset (correlation quality drops across the board,
signalling "go vendor the new one"). `theme.flac` is only the music
bed, additively mixed with speech in the real intro — correlating it
still works as a boundary detector (it stays high wherever the theme
is actually present underneath the speech, and drops sharply once
the bed ends and the host's own raw recording begins), and gives a
useful floor: if the theme-correlation run is longer than what the
ASR anchor found, the theme bed is still playing past the recognized
speech (short-text episodes), and the floor wins.
- **Against a sibling episode**, as the primary method for the intro in
the pre-~2015 fixed-jingle era (no reference asset exists for that
era yet) — e.g. hpr0500 vs hpr0600 matched at r≥0.99 for exactly 15.0s
before diverging.
- **As an anomaly flag**: when an episode's measured match length
against its neighbours is a big outlier, flag it rather than trust
it. This is exactly what caught Linux Inlaws correctly in testing —
hpr3009 vs. a normal sibling (hpr3010) matched for only 2.5s before
diverging. Their extra theme music plays *after* the standard HPR
greeting, as their own content, and must never be touched.
Nothing in this pipeline ever guesses: an episode with no usable signal at
all is flagged for manual review (`intro_flag` / `outro_flag` in the
result), never given a plausible-looking wrong answer.
## ASR dependency strategy
**Decided:** the shipped default is plain `openai-whisper --model tiny`,
not `whisper.cpp`. Rationale: consistency with tooling already in
people's workflows — this is literally what HPR's own
`hpr-get-and-transcribe.bash` already runs — and it's what the original
tested prototype already used. `whisper.cpp` remains a reasonable
pluggable alternative for anyone who wants an even smaller footprint
(`hpr_stripper/asr.py` is written as a one-engine-at-a-time dispatch
specifically so a second backend can be added without touching callers),
but it is not the default.
Real CPU benchmarks (openai-whisper, CPU-only, capped to 4 cores via
`taskset`, on a 90-second clip, on a modern desktop CPU — AMD Ryzen 9
3950X):
| Model | Wall time |
|-------|-----------|
| tiny | 11.7s |
| base | 23.0s |
| small | 57.0s |
A 2016 dual-core laptop would likely run 2–4× slower per the cores-and-
clock gap — plausibly 30–50s for `tiny` — but that's for a 90-second clip,
never the whole episode: this design only ever transcribes short head/tail
clips, when ASR is needed at all (i.e. when neither the official SRT nor
the metadata-arithmetic cross-check gave a usable answer).
## License handling
The HPR database has a real `licenses` table, not one blanket license —
confirmed directly from `hpr.db`:
| License | Episodes |
|-------------|--------------------------------|
| CC-BY-SA | 3,923 |
| CC-BY-NC-SA | 772 |
| CC-0 | 33 |
| CC-BY | 8 |
| CC-BY-NC-ND | 6 |
| CC-BY-NC | 5 |
| CC-BY-ND | (listed, 0 currently assigned) |
| MIT | (listed) |
The two No-Derivatives variants (`CC-BY-ND`, `CC-BY-NC-ND`) legally forbid
producing or redistributing a modified/derivative version of the work —
which a trimmed audio file is — without separate rightsholder permission.
6 episodes currently carry `CC-BY-NC-ND`.
**Every pipeline run reads the episode's license from metadata and
carries it through to the result and the trimmed output's sidecar file.**
By default, `hpr_stripper/trim.py`'s `should_trim()` refuses ND-licensed
episodes (`--force` overrides this, not recommended) — detection can still
run and show the cut points, but the trim step won't silently produce
output for distribution.
**This goes further than just the 6 ND episodes.** Per
`hpr_documentation/branding.md`, on the "Who?" segment of the intro: *"We
are required by the CC-BY-SA... license to credit our hosts, so we do."*
The intro is HPR's actual mechanism for satisfying CC-BY-SA host
attribution — so stripping it removes a legally required notice for
*every* CC-BY-SA/CC-BY episode, not only the ND-licensed ones. That's why
`trim.write_sidecar()` always writes a small JSON file alongside trimmed
output recording the host, episode number, date, license, and original
URL, regardless of which license applies — trimmed audio stays
self-documenting if it's ever shared separately from this tool.
Historical/ethos note: HPR dropped the CC-BY-NC license as an option in a
2025 policy change (see `hpr_documentation/policies.md`) and clarified
that contributions default to CC-BY-SA 4.0 unless otherwise stated — the
772 CC-BY-NC-SA / 5 CC-BY-NC episodes are a legacy category, not one
expected to keep growing.
## Repo structure & pipeline stages
```
hpr-intro-stripper/
├── README.md # minimal: usage, requirements, brief how-it-works
├── docs/
│ └── DESIGN.md # this file
├── references/ # vendored from HPR's own hpr-tools repo (CC0/CC-BY-SA, not this repo's code license)
│ ├── theme.flac
│ ├── outro.flac
│ ├── intro.srt
│ ├── outro.srt
│ ├── mysql2sqlite # the same AWK converter HPR's own tooling uses
│ └── LICENSE_NOTICE.md
├── hpr_stripper/
│ ├── config.py # the one place to change defaults
│ ├── markers.json # versioned, plain-text boilerplate phrase library
│ ├── markers.py # fuzzy matching against markers.json
│ ├── metadata.py # canonical hpr.sql fetch + sqlite conversion + queries
│ ├── fetch.py # audio/transcript/SRT fetch via ccdn.php only
│ ├── srt.py # minimal SRT parser (stdlib only)
│ ├── audio.py # ffmpeg/ffprobe wrappers, cross-correlation
│ ├── asr.py # pluggable ASR backend dispatch
│ ├── detect.py # the layered detection pipeline
│ ├── ledger.py # resumable per-episode progress tracking
│ ├── trim.py # atomic trim + license gating + sidecar metadata
│ └── cli.py # detect / sweep / random-sample / trim / report
├── tools/
│ └── visualize_clip.sh # renders a waveform/spectrogram for a clip, for inspecting a cut point directly
└── cache/ # gitignored: hpr.db, downloaded audio, transcripts, ledger.db, trimmed output
```
**What lives in git:** code, the marker-phrase library, the vendored
reference assets (small, clearly licensed), and this documentation.
**What never lives in git:** episode audio, bulk transcripts, the
metadata database, and trimmed output — all fetched or produced into
`cache/` on demand, so cloning the repo stays small regardless of how much
of the archive someone has processed.
**Config surface:** `hpr_stripper/config.py` — one file selecting the ASR
backend/model, audio format preference, fetch/clip sizes, and cache
location.
## Testing & resumability strategy
Two first-class test modes, not ad hoc spot checks:
- **Random-sample test** (`cli.py random-sample`): picks N episodes at
random, stratified across the three known eras (pre-2015, ~2016–2020,
~2020+) so a lucky or unlucky sample can't hide an era-specific
regression. Fast, for day-to-day development checks.
- **Full-corpus sweep test** (`cli.py sweep`): runs detection (not
trimming) across every episode in the archive. Slow — a real,
continuous run of 21 episodes from the hardest category (pre-2015, no
official transcript, full ASR + sibling-correlation fallback) averaged
32.1 seconds/episode on the hardware this was developed on; scaled to
the full ~4,750-episode archive that's on the order of a day or two of
continuous wall-clock time, not weeks, though a weaker CPU or the
politeness delay (see "Data acquisition") would push it higher — and
explicitly designed to be interrupted.
- **Interrupt/resume was smoke-tested for real, not just unit-tested**:
a `sweep` was started, sent a real `SIGINT` mid-episode, resumed (and
confirmed it skipped the already-completed episodes rather than
reprocessing them), interrupted again, and resumed to completion. No
lost work, no stray subprocesses left running after either interrupt,
no corrupted ledger state.
**Resumability is a hard requirement**, because a half-hour-plus batch run
*will* get interrupted (Ctrl+C, laptop sleep, SSH drop):
- **Idempotent, per-episode units of work.** Every stage treats one
episode as the atomic unit (`ledger.is_done()` checked before any work
starts).
- **Atomic writes, never partial files.** `fetch.py` and `trim.py` both
write to a `.tmp` path and `os.replace()` into place only on success.
- **A persistent progress ledger** (`hpr_stripper/ledger.py`, SQLite):
one durable, committed row per episode, written immediately after that
episode finishes. Ctrl+C at minute 29 of a 30-minute `sweep` costs at
most the one in-flight episode.
- **Safe to re-run after changing settings.** The ledger stamps each row
with the marker-library version and ASR engine/model that produced it
(`config.MARKERS_VERSION`); `ledger.is_done()` only returns true if
those still match the current settings, so bumping the marker version
or switching ASR models re-processes exactly the episodes affected, not
everything.
## Fit with HPR's own ethos & principles
Read directly from `hpr_documentation` (`branding.md`, `policies.md`) and
from the generation code itself, not inferred:
- **The intro's spoken metadata exists partly for accessibility, not just
branding.** `branding.md`: "We started to do it because some of our
Visually Impaired users appreciated knowing what show is playing."
Stripping it removes a real accessibility aid for listeners who rely on
audio cues rather than a visual player UI. This tool is an optional
alternate listening format for people who've chosen to opt out of that
cue — never a claim that HPR's own intro design is a defect to fix.
- **The intro is also how HPR satisfies its CC-BY-SA attribution
requirement** — see "License handling" above.
- **A documentation/code discrepancy, flagged rather than smoothed
over** — see "What HPR's own pipeline already does" above (the "30
seconds" claim vs. the actual uncapped generation code).
- **The exact spoken text is fully reconstructable from the database** —
`hpr_hub/cms/say.php`'s plain string concatenation, reproduced (not
required for the primary detection path) in
`metadata.synopsis_text()`, as a foundation for a possible future
deterministic, zero-ASR intro-alignment spike: resynthesize the
expected text with the same Piper voice
(`en_US-ljspeech-high.onnx`) and correlate the result against the real
episode, rather than relying on ASR at all. Not yet built — the
ASR-anchor path already works and shipped first.
- **The project is careful, consensus-driven, and averse to touching
canonical identifiers.** `policies.md`: "The janitors really do not
like to move shows around once they are posted" — doing so breaks RSS
readers and CCDN sync. This tool stays strictly read-only against the
official archive: it never proposes renaming, renumbering, or
otherwise modifying HPR's own canonical releases, and names its own
output so it can never be confused with the original (`hprNNNN.
trimmed.ext`, never literally `hprNNNN.mp3`).
- **Harm is handled by response episodes and janitor review, not
unilateral editing.** `policies.md`: the remedy for a problematic show
is a *response episode* or raising it with the janitors — never
silently altering what's published. This tool's framing matches that
norm.
- **General ethos match.** The CCDN architecture doc's explicit
preference for minimal, boring, FLOSS, Debian-stable tooling over
frameworks ("The system intentionally avoids: Databases, PHP, Python
web applications, Kubernetes, Redis...") lines up with the
dependency-weight goal here — `ffmpeg` + Python stdlib + `numpy`, no
heavy framework, ASR optional.
## Edge cases & known limitations
- **Shows with their own bonus intro music** (Linux Inlaws and similar).
Their extra theme plays *after* the standard HPR greeting — it's the
hosts' own content, not station boilerplate, and must never be
stripped. The cross-correlation anomaly check catches this
automatically (see "Cut-point detection strategy" above); the
ASR-anchor method independently stops at the right place anyway,
because it only recognizes station-specific metadata phrases.
- **Episodes with no usable signal at all** — flagged for manual review,
never guessed. Confirmed in testing: of 9 sample episodes, 2 correctly
fell back to "no reliable signal" rather than a plausible-looking but
wrong cut (one of them, hpr0500, for the same reason described in the
`markers.py` docstring — an organic cold open that merely echoes the
greeting pattern).
- **Era wording drift.** The marker-phrase library
(`hpr_stripper/markers.json`) is not a fixed constant — it's already
been through at least 4 generations of wording and will keep drifting.
Extend it there, not in code, the same way a spam-filter rule file gets
maintained. Concretely caught once already: a code-review pass flagged a
`metadata_arithmetic`-vs-marker-match disagreement on hpr4775
(40.0s vs 16.4s); rendering the clip with `tools/visualize_clip.sh` and
comparing the resulting waveform/spectrogram against the real official
SRT showed it had moved to a newer phrasing — "the host is X and the
duration is Y" / "the flag is Y, and the license is Z" — that the marker
set didn't recognize yet, so matching stopped two segments early. Fixed
in `markers.json` (bumped to version 2); see `tests/test_markers.py`'s
`test_2026_wording_variant_is_recognized` for the locked-in regression
test. The same technique (a `random-sample` run flagging a
`metadata_arithmetic` disagreement, then rendering the clip to check
which side was actually right) found two more gaps in one pass:
hpr2157's era apparently used the bare abbreviation "HPR episode" rather
than "Hacker Public Radio episode" (intro_end was landing at 3.25s via
the much weaker sibling-correlation fallback, instead of a proper
marker match), and Whisper `tiny` mis-hearing "Today's" as "To its" on
hpr3356 broke the same marker a different way. Both fixed in
`markers.json` (version 3). hpr3356 itself (a 282-minute New Year's Eve
marathon episode) remains an open case even after the fix — its
structure doesn't cleanly match the standard template, and it's still
correctly flagged for manual review rather than given a confident wrong
answer.
- **The theme-correlation fallback can't bridge a genuine silence gap** —
also found via the hpr4775 waveform inspection above, and still open.
`generate_intro()` mixes TTS speech additively onto `theme.flac`
(`sox -m`), so correlating the vendored reference against a real episode
predictably drops once speech starts masking it — expected, and *not*
treated as a disagreement (see the comment in `detect.py` next to
`theme_xcorr`). But the current "leading contiguous run" correlation
algorithm also can't recover once it legitimately resumes: hpr4775 has
real TTS speech from 0–27.3s, then an honest ~13s silence/instrumental
gap before the host's own greeting at ~40s (visually confirmed; matches
`theme.flac`'s own 40.52s length closely). The detector currently stops
at 27.3s — correct for the spoken-template boundary, but it leaves
roughly 13 seconds of pure station music unstripped at the front of
"trimmed" output for episodes with this gap. A fix would need the
correlation to search for the *last* high-correlation window in the
probe range rather than only count a single contiguous run from the
start; not yet implemented.
- **Official SRT segment timing may not always be trustworthy even when
present** — the checked-in `intro.srt` template's timestamps are
nominal defaults, not necessarily exact for every real episode's
rendered TTS audio (observed variance: true intro lengths 13–48s
against a 27.32s nominal template).
- **The `duration`-field arithmetic cross-check is era-limited** — matched
real ASR-measured boundaries within a few seconds for three modern test
episodes, but was off by 53 seconds for an older one. Corroboration
only, for recent episodes.
## Open items
- **Deterministic, zero-ASR intro alignment** — substantiated (see "Fit
with HPR's own ethos & principles" above) but not yet built. A
reasonable follow-up once the ASR-anchor path has been exercised
against more of the archive.
- **Sidecar metadata format** — currently a JSON file alongside each
trimmed output (`trim.write_sidecar()`); ID3 tags are a reasonable
addition if trimmed files are likely to circulate without their
sidecar.