Fast in‑memory MP3 encode‑decode augmentation for audiomentations
Project description
fast-mp3-augment
A fast Python library for MP3 encoder + decoder data augmentation. Made for integration with audiomentations. Intentionally applying audio degradation by lossy compression help machine learning models learn to deal with audio that gets streamed from various internet services, which is commonly lossy/compressed.
Installation
$ pip install fast-mp3-augment
Code example
import numpy as np
import fast_mp3_augment
audio = np.random.uniform(-1, 1, (2, 2 * 48000)).astype("float32")
augmented_audio = fast_mp3_augment.compress_roundtrip(
audio, sample_rate=48000, bitrate_kbps=64, preserve_delay=False, quality=7
)
Features
- The output is perfectly aligned (no delay/offset and padding) with the input by default, but this trimming behavior can be disabled (with
preserve_delay=True) - Supports mono and stereo
- Supports standard MP3 bitrates (8-320 kbps)
- Supports common sample rates (8-48 kHz)
- Inputs and outputs float32 numpy array
- Adjustable
qualityparameter for various tradeoffs between speed and audio quality
Performance
This library is largely developed with Rust under the hood (via pyo3 & maturin), and applies a few nice little tricks for achieving speedy execution (which is important during large-scale audio ML training!), such as:
- Fast numpy array interop between Python and rust
- In-memory computations (no disk I/O)
- SIMD-optimized max abs calculation (for avoiding clipping distortion)
- Pipelining/streaming (LAME encoder and minimp3 decoder in separate threads)
A quick performance benchmark (based on demo.py in audiomentations), which augmented 3 short (~7-9 sec) audio snippets (2 mono, 1 stereo) on a laptop with i7-13700HX and a 2 TB Samsung PM9A1 NVMe shows that fast-mp3-augment is superior when it comes to speed:
Changelog
[0.2.0] - 2025-12-15
- Bump min Python version to 3.10
- Officially add support for Python 3.14
- Make builds slightly slimmer
For the complete changelog, go to CHANGELOG.md
Development setup
conda create --name fast-mp3-augment python=3.11conda activate fast-mp3-augmentpip install -r dev_requirements.txtmaturin developpytest
LAME note
fast_mp3_augment statically links libmp3lame 3.100 (LGPL-2.1-or-later). Full source is available here. To rebuild the wheel against a modified LAME, see mp3lame-sys
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_mp3_augment-0.2.0.tar.gz.
File metadata
- Download URL: fast_mp3_augment-0.2.0.tar.gz
- Upload date:
- Size: 639.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dae94a3abb7f8336d3d00b528f6132413cee72dfcdc91baf617f0a1d1bc8b8a9
|
|
| MD5 |
fff04f29fe8230d42d77c6e70f63d951
|
|
| BLAKE2b-256 |
17bdf4bd35409f5a304f6b71614c3bde63fbbab8bc12915c35387f6d1fa86df0
|
File details
Details for the file fast_mp3_augment-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fast_mp3_augment-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 454.8 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa99e21ada08dd4cbf3145a89f9c33947881e52a9b13c432740b064f5a3f53d0
|
|
| MD5 |
4ff19443fce807401257343e2caf168c
|
|
| BLAKE2b-256 |
94f214961e735518d7e341aa29a81dd4a30074664c9a5b94c80f210a5cfee3eb
|
File details
Details for the file fast_mp3_augment-0.2.0-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: fast_mp3_augment-0.2.0-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 362.9 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebd3c60b00e2fbd8f2f507d867dab150979df23ad07b6da31da1163a448e43d2
|
|
| MD5 |
4aa235f2b01f57fbb1d4766fb1b52ac9
|
|
| BLAKE2b-256 |
72ba1fd2bb82e59b2ef30c4846d5f40205d07f56cdd69746592d56414161ebef
|
File details
Details for the file fast_mp3_augment-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: fast_mp3_augment-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 680.8 kB
- Tags: CPython 3.9+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eda7af23231a657169f0f6f5be738e65b352e66b3a1b94dbd4d42b5e32825a31
|
|
| MD5 |
fd392dbcf8d8b3a48804832fa7f75d2b
|
|
| BLAKE2b-256 |
0cae32b96a043054edebd829b2ca43d38c9521b84f23db15eac717dfd2d19651
|
File details
Details for the file fast_mp3_augment-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: fast_mp3_augment-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 633.9 kB
- Tags: CPython 3.9+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef8c0d0253e0a2a69d7afdde1fdd707b7d6dc051f017a53732eb23eaaa59c27f
|
|
| MD5 |
4b4216d20bd8c504a72a13b68f2eda84
|
|
| BLAKE2b-256 |
ea7a48b940814cf28af0a7f2efb257379b5371b23b6b2173c6451328bea7fb8c
|
File details
Details for the file fast_mp3_augment-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fast_mp3_augment-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 460.1 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d55288625b052635defbb0ab627fb49734b52985eb6d3ef69c35237cd80e2075
|
|
| MD5 |
2c97ac5a3beb3b772ab236a8d8b5250c
|
|
| BLAKE2b-256 |
928e335515e06d3967191e5be393c8b8de72f6f43cd047f34ee271e3f60c74d7
|
File details
Details for the file fast_mp3_augment-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: fast_mp3_augment-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 447.1 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b404f8ca64505c9f35faf8c966af9a9877f44c060dcc492d90be47e32994724
|
|
| MD5 |
e17ff91042df12bb20c0f5489eecad51
|
|
| BLAKE2b-256 |
9f2473b9d6e2327c0a4fdbaace1d661bd2159b22e53252db196d50e52ebcfb54
|
File details
Details for the file fast_mp3_augment-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_mp3_augment-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 428.6 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
192a1193641253a3755bbe868a189cdf068e266a6a3b695f7e63daee5ee29eb0
|
|
| MD5 |
7902861b73f9175c66b8f7efabd378dd
|
|
| BLAKE2b-256 |
f2fbc4739734d151c022cddcb02650ab411e02906b3a00fd0ae23c9a07f50b67
|