Skip to main content

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

PyPI version python 3.9, 3.10, 3.11, 3.12, 3.13 os: Linux, macOS, Windows

$ 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 quality parameter 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:

images/perf_benchmark_results.png

Changelog

[0.1.0] - 2025-06-28

Initial release

For the complete changelog, go to CHANGELOG.md

Development setup

  • conda create --name fast-mp3-augment python=3.11
  • conda activate fast-mp3-augment
  • pip install -r dev_requirements.txt
  • maturin develop
  • pytest

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


Download files

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

Source Distribution

fast_mp3_augment-0.1.0.tar.gz (668.6 kB view details)

Uploaded Source

Built Distributions

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

fast_mp3_augment-0.1.0-cp39-abi3-win_amd64.whl (363.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

fast_mp3_augment-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl (635.8 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

fast_mp3_augment-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl (620.9 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

fast_mp3_augment-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (462.4 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

fast_mp3_augment-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (438.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

fast_mp3_augment-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (418.6 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file fast_mp3_augment-0.1.0.tar.gz.

File metadata

  • Download URL: fast_mp3_augment-0.1.0.tar.gz
  • Upload date:
  • Size: 668.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for fast_mp3_augment-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7a3d72c45288cf5df9e7579bdf671e898a1b2ef95610ba8ee7a61126b524409f
MD5 8153cb93dcd664de9d8b9a060d894ae8
BLAKE2b-256 a1f674d4090a579e4aec0dc6cb497d9b3af8bf099b6ff290a2fb29600625d930

See more details on using hashes here.

File details

Details for the file fast_mp3_augment-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for fast_mp3_augment-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dcce56d89258ba8b3a28e015bcdf2ab41e548f387fa949f092718990c499d2e0
MD5 c946cfcb4b93ee5f03f853857fd24578
BLAKE2b-256 d4cbb05a5de8197c5eda09c46de361a4d721f84e8edc3debc6487f93e242386f

See more details on using hashes here.

File details

Details for the file fast_mp3_augment-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for fast_mp3_augment-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7f884737cb2ae2cc08ec3e2a084518afdbe4991b7d87fe63dc0f1adda50e3c6a
MD5 7a4eef131e05158f46d56e8ca83ff12e
BLAKE2b-256 f24a3e1657ef44bc9828a7e42432a9c8ac33a378db2968b5962dedfee39e749a

See more details on using hashes here.

File details

Details for the file fast_mp3_augment-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for fast_mp3_augment-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5f74a2cbcecf9f563bfe0e1d87ae9385904d9e03c87244d1d1b8dddc68b91189
MD5 66c6e3eccc4d80387e2cdb9ffb66bf56
BLAKE2b-256 585a072ece43a34019c7d324a855b6d9f49fc73ca4321ae36315b35b3d9c4892

See more details on using hashes here.

File details

Details for the file fast_mp3_augment-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_mp3_augment-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 026b3734fe45982bca408fdf0f22380827a5ab65eea771edcf1c49d710c5cb44
MD5 40ec3d3ae67f3dc0e3b41297bea01d5f
BLAKE2b-256 26c36855f7382812205290ac444ccf34f6404e41748c5c7c8cbab115c3f73e35

See more details on using hashes here.

File details

Details for the file fast_mp3_augment-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_mp3_augment-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 88f2e719f5a8dc1cccc475623039fdc551eddb4bb9f6685f50a9311648a818e9
MD5 ee99c7e48662abbba7492f7ee890a24b
BLAKE2b-256 8d65612f8f7421a895d7f7d05c89f482ccc578afe449d2943c0a5eaccdf16bb3

See more details on using hashes here.

File details

Details for the file fast_mp3_augment-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast_mp3_augment-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 684d52620284419c73c7503775d3a6cd8fa4c54c880562a327518683dfa97ecf
MD5 883fdb0c25476ce75dfc93b4e637fab8
BLAKE2b-256 90efd86f26382df56d4061fa609ff213f3d665f05963f9de586419444d94c3c4

See more details on using hashes here.

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