A Python library for audio data augmentation. Inspired by albumentations. Useful for machine learning.
pip install audiomentations
from audiomentations import Compose, AddGaussianNoise, TimeStretch, PitchShift, Shift
import numpy as np
SAMPLE_RATE = 16000
augmenter = Compose([
AddGaussianNoise(min_amplitude=0.001, max_amplitude=0.015, p=0.5),
TimeStretch(min_rate=0.8, max_rate=1.25, p=0.5),
PitchShift(min_semitones=-4, max_semitones=4, p=0.5),
Shift(min_fraction=-0.5, max_fraction=0.5, p=0.5),
])
samples = np.zeros((20,), dtype=np.float32)
samples = augmenter(samples=samples, sample_rate=SAMPLE_RATE)
Go to audiomentations/augmentations/transforms.py to see which transforms you can apply.
- Breaking change: AddImpulseResponse, AddBackgroundNoise and AddShortNoises now include subfolders when searching for files. This is useful when your sound files are organized in subfolders.
- AddImpulseResponse, AddBackgroundNoise and AddShortNoises now support aiff files in addition to flac, mp3, ogg and wav
- Fix filter instability bug in FrequencyMask. Thanks to kvilouras.
- Disregard non-audio files when looking for impulse response files
- Remember randomized/chosen effect parameters. This allows for freezing the parameters and applying the same effect to multiple sounds. Use transform.freeze_parameters() and transform.unfreeze_parameters() for this.
- Fix a bug in ClippingDistortion where the min_percentile_threshold was not respected as expected.
- Implement transform.serialize_parameters(). Useful for when you want to store metadata on how a sound was perturbed.
- Switch to a faster convolve implementation. This makes AddImpulseResponse significantly faster.
- Add a rollover parameter to Shift. This allows for introducing silence instead of a wrapped part of the sound.
- Expand supported range of librosa versions
- Add support for flac in AddImpulseResponse
- Implement AddBackgroundNoise transform. Useful for when you want to add background noise to all of your sound. You need to give it a folder of background noises to choose from.
- Implement AddShortNoises. Useful for when you want to add (bursts of) short noise sounds to your input audio.
- Improve handling of empty input
- Add shuffle parameter in Composer
- Add Resample transformation
- Add ClippingDistortion transformation
- Add SmoothFadeTimeMask as alternative to TimeMask
Thanks to askskro
Add new transforms:
- AddImpulseResponse
- FrequencyMask
- TimeMask
- AddGaussianSNR
Thanks to karpnv
- Implement peak normalization
- Implement Shift transform
- Ensure p is within bounds
- Implement PitchShift transform
- Fix output dtype of AddGaussianNoise
Implement leave_length_unchanged
in TimeStretch
- Add TimeStretch transform
- Parametrize AddGaussianNoise
Initial release. Includes only one transform: AddGaussianNoise
Install the dependencies specified in requirements.txt
Format the code with black
pytest
python -m demo.demo