Skip to main content

Trim leading and trailing silence from MP3 songs.

Project description

TrackTrim

TrackTrim is a Python library for trimming leading and trailing silence from MP3 songs while preserving MP3 output and common ID3 metadata.

Features

  • Detects non-silent content at the beginning and end of a track
  • Trims MP3 files and writes MP3 output
  • Preserves common metadata and cover art through ID3 tag copying
  • Uses a stable bitrate policy for predictable output size and quality
  • Designed to be imported from other Python scripts

Installation

From GitHub

pip install git+https://github.com/DrSopes/tracktrim.git
pip install tracktrim

Usage

from tracktrim import trim_song, detect_content_bounds

info = detect_content_bounds("song.mp3", top_db=35)
print(info)

result = trim_song(
    "song.mp3",
    "song_trimmed.mp3",
    top_db=35,
)
print(result)

Bitrate policy

TrackTrim uses a simple stable output policy:

  • source bitrate <= 192 kbps -> output 192 kbps
  • source bitrate 193 to 288 kbps -> output 256 kbps
  • source bitrate > 288 kbps -> output 320 kbps

This avoids unpredictable VBR output and keeps file sizes consistent.

Development

Create a virtual environment and install the project in editable mode:

python -m venv .venv

On Windows CMD:

.venv\Scripts\activate

Then install:

pip install -e .

Build

python -m pip install --upgrade build
python -m build

This creates distribution files in dist/.

Publishing

This repository can publish to PyPI automatically through GitHub Actions using Trusted Publishing.

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tracktrim-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tracktrim-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file tracktrim-0.1.1.tar.gz.

File metadata

  • Download URL: tracktrim-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tracktrim-0.1.1.tar.gz
Algorithm Hash digest
SHA256 593c2367d153a9f4bfd275ba2212ff493bde840ec4a9c7e87c4aaf0038264096
MD5 fa3bf81d09936455281fd4de5cf10848
BLAKE2b-256 329747ba2cd3072e4648deb5ffa27275b6b3bf39fbf36318d4d4a74a964bc3a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracktrim-0.1.1.tar.gz:

Publisher: publish.yml on DrSopes/TrackTrim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracktrim-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tracktrim-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tracktrim-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb4e3bca46b561d33f185a5b8a04047cc46106b455d50d52cb5042420af4e7ec
MD5 132d94ba62b261c1efa1261702050e0d
BLAKE2b-256 89ded01fc13bae4de7d601b354f696b7e053edb320c74e0226116a78f4e61024

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracktrim-0.1.1-py3-none-any.whl:

Publisher: publish.yml on DrSopes/TrackTrim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page