Lee Hanken fcfa1f1c6c Fix gap-bridging correlation, a marker-normalization bug, and add sponsor ad-read markers
- 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.
2026-11-22 11:51:46 +00:00

hpr-intro-stripper

Extracts the "inner" audio from a Hacker Public Radio episode — the host's originally submitted recording, with HPR's own added intro and outro removed — for one episode or in batch.

It never ships or assumes a local copy of the HPR archive: it fetches whatever metadata, audio, and transcripts it needs from the live HPR site itself, and never touches the original files.

For the full technical background (why this isn't trivial, how HPR's own pipeline works, the detection strategy, benchmarks, and known limitations), see docs/DESIGN.md.

Motivation

From Ken Fallon's comment on hpr4761 :: HPR Community News for October 2026 (transcript, lightly corrected for clarity):

That had me thinking, actually Lee — a lot of the original episodes on HPR have the HPR intro and outro on them, and I was just wondering: would there be a way where we could get the original source material and strip out the old intro and outro, so that we just have the audio for that, and then update them as time goes on?

Requirements

  • Python 3.9+
  • ffmpeg / ffprobe
  • sqlite3 and awk (for fetching/converting HPR's metadata dump)
  • numpy (pip install numpy)
  • Optional, only used as a fallback when HPR hasn't published an official transcript for an episode: openai-whisper (pip install openai-whisper), run with the tiny model on short clips only — never a whole episode, never requires a GPU.

No step requires a GPU or a specific speech-recognition setup.

How it works, briefly

HPR's intro is a per-episode, auto-generated spoken announcement (title, host, date, summary) over a music bed; the outro is a single fixed clip. Detection tries, in order: HPR's own official transcript/subtitle file (if published for that episode), a metadata-duration cross-check, local speech recognition on a short clip, then audio correlation against known reference clips — whichever signal actually works for a given episode, recorded alongside the result. Episodes with no reliable signal, or an unusual/No-Derivatives license, are flagged for manual review rather than guessed at. See docs/DESIGN.md for the full reasoning.

Usage

pip install numpy openai-whisper   # openai-whisper only needed for the ASR fallback

# Detect cut points for one episode (fetches audio/metadata as needed, caches in ./cache)
python -m hpr_stripper.cli detect --episode 3700

# Detect a range
python -m hpr_stripper.cli detect --range 3700-3720

# Produce trimmed output for everything detected so far with a usable result
python -m hpr_stripper.cli trim --out-dir ./trimmed

# Random, era-stratified spot check
python -m hpr_stripper.cli random-sample --n 12

# Full-archive detection pass -- safe to interrupt (Ctrl+C) and resume by re-running
python -m hpr_stripper.cli sweep

# Summary of what's been processed so far
python -m hpr_stripper.cli report

All intermediate state (downloaded audio, the metadata database, transcripts, detection results, trimmed output) lives under ./cache/ and ./trimmed/ by default, both gitignored. Nothing here is uploaded or shared anywhere by this tool.

License handling

Every episode's own Creative Commons (or other) license is read from HPR's metadata and carried through to the output. Episodes under a No-Derivatives license are never trimmed for distribution by default (see docs/DESIGN.md). Trimmed output is accompanied by a small JSON sidecar recording the host, episode number, date, and license, since the intro being removed is also HPR's mechanism for crediting hosts under CC-BY-SA.

S
Description
Internal tool to extract the "inner" audio from an episode — the host's originally submitted recording, with HPR's own added intro and outro removed — for one episode or in batch.
Readme AGPL-3.0
6 MiB
0 Stars 1 Watchers 0 Forks
Languages
Python 90.1%
Awk 6.9%
Shell 3%