TrackTrim is a Python library and CLI for trimming leading and trailing silence from MP3 songs.
It detects the first and last non-silent regions of a track, trims the file, writes MP3 output, and preserves common ID3 metadata.
- Detect leading and trailing silence
- MP3 input to MP3 output
- Preserve common metadata and cover art
- Stable bitrate policy for predictable output size
- Public Python API and command-line interface
pip install tracktrimpip install git+https://github.com/DrSopes/TrackTrim.gitfrom tracktrim import inspect_mp3, detect_content_bounds, trim_song
info = inspect_mp3("song.mp3")
print(info)
bounds = detect_content_bounds("song.mp3", top_db=35)
print(bounds)
result = trim_song("song.mp3", "song_trimmed.mp3", top_db=35)
print(result)tracktrim input.mp3 output.mp3 --top-db 35Optional bitrate override:
tracktrim input.mp3 output.mp3 --bitrate 320TrackTrim uses a stable default policy:
- source bitrate <= 192 kbps -> output 192 kbps
- source bitrate 193 to 288 kbps -> output 256 kbps
- source bitrate > 288 kbps -> output 320 kbps
python -m venv .venvWindows CMD:
.venv\Scripts\activateInstall in editable mode:
pip install -e .python -m pip install --upgrade build
python -m buildThis project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).