No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Erick Ruiz de Chavez 43cadb9a1d Initial commit: trim_splices
Detects and trims the ~1s next-track splice left at the end of mp3s
recorded from internet radio, with docs for users (README) and future
Claude Code sessions (CLAUDE.md).

Assisted-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158NqVQ3KKvKin4cQogXHX1
2026-08-21 10:30:36 +00:00
CLAUDE.md Initial commit: trim_splices 2026-08-21 10:30:36 +00:00
README.md Initial commit: trim_splices 2026-08-21 10:30:36 +00:00
trim_splices Initial commit: trim_splices 2026-08-21 10:30:36 +00:00

trim_splices

Fixes a common artifact in mp3s recorded from internet radio streams: the recording/splitting software sometimes leaves about a second of the next track's audio tacked onto the end of a file. trim_splices scans a folder of mp3s, detects files with that splice, and trims it off in place.

How it works

A spliced file fades/decays to near-silence near the end, then a burst of different audio kicks in and the file just cuts off abruptly while still loud. A cleanly-ended file decays to silence and stays quiet through EOF. The script measures the audio energy over the last few seconds of each file, finds the last silence gap, and checks whether the audio becomes active again after it and stays active to the end. If so, it trims the file back to the end of that silence gap.

Files that end "hot" with no silence gap at all (could be a legitimate cold ending, or a splice with no gap between tracks) are only flagged, never auto-trimmed — the script isn't confident enough to guess. Same for the rarer case of the previous track's tail being prepended to the start of a file: it's flagged as a candidate but not auto-trimmed, since that check false-positives on normal song intros (a dramatic pause or a quiet pickup note before the beat drops looks the same to it as a splice).

Trimming is done with ffmpeg -c copy (no re-encoding, no quality loss, ID3 tags preserved), and only after checking the result's duration looks right — nothing gets overwritten unless that check passes.

Requirements

  • uv — installs and caches this script's Python dependencies (numpy, scipy, soundfile, librosa) automatically, no separate install step needed.
  • ffmpeg (which also provides ffprobe) on PATH:
    • macOS: brew install ffmpeg
    • Debian/Ubuntu: sudo apt install ffmpeg
    • Fedora: sudo dnf install ffmpeg
    • Arch: sudo pacman -S ffmpeg

If ffmpeg/ffprobe are missing, the script tells you so (with the install command for your OS) instead of failing with a cryptic error.

Usage

./trim_splices /path/to/music        # scan a folder, trim any new splices found
./trim_splices                       # scan the current directory
./trim_splices /path/to/music --dry-run     # report what would be trimmed, change nothing
./trim_splices /path/to/music --rescan-all  # ignore saved history, re-check every file

Put the script somewhere on your PATH (e.g. ~/.local/bin/) and point it at your music folder — it never writes anything there besides the trimmed mp3s themselves. Re-running it after adding new recordings only analyzes files that are new or changed since the last run; everything else is skipped instantly. This history is kept in ~/.local/state/trim_splices/, one file per folder you scan, not in the music folder itself.

Limitations

  • No backups are made — a trimmed file is overwritten in place (after a sanity check on the result).
  • Detection is heuristic, tuned on radio-recorded pop/electronic/Latin ballad tracks. It can be adjusted with --silence-db and --active-db if it's over- or under-firing on your library.
  • The "previous track's tail at the start" check is informational only — always listen before trusting it.