Audiomentations is a Python library for audio data augmentation, inspired by `albumentations`. It provides a fast and easy-to-use API for applying various transformations to audio data, useful for machine learning and deep learning tasks. It runs on CPU, supports both mono and multichannel audio, and integrates well into training pipelines for frameworks like TensorFlow/Keras or PyTorch. The library is actively maintained, with frequent releases, and is currently at version 0.43.1.
pip install audiomentationsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a composition of several common waveform-based audio augmentations and apply them to a dummy audio signal. The `Compose` object allows chaining multiple transformations, each with its own probability `p`.
Upgrade your Python environment to 3.10 or newer. If using `LoudnessNormalization` or `Mp3Compression`, install the new optional dependencies (`loudness` and `fast-mp3-augment`) and update any code relying on specific backend implementations or `pydub`.
Review and update usage of `TimeMask` to reflect the removed `fade` parameter, new `mask_location` parameter, and changed default values.
Always use keyword arguments when instantiating `AddBackgroundNoise` to ensure future compatibility, especially when updating across minor versions.
Ensure your audio data is preprocessed to `np.float32` and normalized to the range `[-1.0, 1.0]` before passing it to `audiomentations` transforms. Use transforms like `Normalize` or `Clip` if needed.
For GPU acceleration, install `torch-audiomentations` (`pip install torch-audiomentations`) and adapt your code to use its PyTorch-compatible transforms.
Consult the official documentation for specific guidance on using `AddBackgroundNoise` and `AddShortNoises` with multichannel audio, or test thoroughly with your specific multichannel data.
If you were importing internal utility functions, update their import paths, e.g., `from audiomentations.core.utils import calculate_rms` instead of `from audiomentations import calculate_rms`.