# Audiomentations
[](https://circleci.com/gh/iver56/audiomentations)
[](https://codecov.io/gh/iver56/audiomentations)
[](https://github.com/psf/black)
[](https://github.com/iver56/audiomentations/blob/main/LICENSE)
[](https://doi.org/10.5281/zenodo.15056865)
A Python library for audio data augmentation. Inspired by
[albumentations](https://github.com/albu/albumentations). Useful for deep learning. Runs on
CPU. Supports mono audio and multichannel audio. Can be
integrated in training pipelines in e.g. Tensorflow/Keras or Pytorch. Has helped people get
world-class results in Kaggle competitions. Is used by companies making next-generation audio
products.
Need a Pytorch-specific alternative with GPU support? Check out [torch-audiomentations](https://github.com/asteroid-team/torch-audiomentations)!
# Setup

[](https://pypi.org/project/audiomentations/)
[](https://pypi.org/project/audiomentations/)

`pip install audiomentations`
# Usage example
```python
from audiomentations import Compose, AddGaussianNoise, TimeStretch, PitchShift, Shift
import numpy as np
augment = 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(p=0.5),
])
# Generate 2 seconds of dummy audio for the sake of example
samples = np.random.uniform(low=-0.2, high=0.2, size=(32000,)).astype(np.float32)
# Augment/transform/perturb the audio data
augmented_samples = augment(samples=samples, sample_rate=16000)
```
# Documentation
The API documentation, along with guides, example code, illustrations and example sounds, is available at [https://iver56.github.io/audiomentations/](https://iver56.github.io/audiomentations/)
# Transforms
* [AddBackgroundNoise](https://iver56.github.io/audiomentations/waveform_transforms/add_background_noise/): Mixes in another sound to add background noise
* [AddColorNoise](https://iver56.github.io/audiomentations/waveform_transforms/add_color_noise/): Adds noise with specific color
* [AddGaussianNoise](https://iver56.github.io/audiomentations/waveform_transforms/add_gaussian_noise/): Adds gaussian noise to the audio samples
* [AddGaussianSNR](https://iver56.github.io/audiomentations/waveform_transforms/add_gaussian_snr/): Injects gaussian noise using a randomly chosen signal-to-noise ratio
* [AddShortNoises](https://iver56.github.io/audiomentations/waveform_transforms/add_short_noises/): Mixes in various short noise sounds
* [AdjustDuration](https://iver56.github.io/audiomentations/waveform_transforms/adjust_duration/): Trims or pads the audio to fit a target duration
* [AirAbsorption](https://iver56.github.io/audiomentations/waveform_transforms/air_absorption/): Applies frequency-dependent attenuation simulating air absorption
* [Aliasing](https://iver56.github.io/audiomentations/waveform_transforms/aliasing/): Produces aliasing artifacts by downsampling without low-pass filtering and then upsampling
* [ApplyImpulseResponse](https://iver56.github.io/audiomentations/waveform_transforms/apply_impulse_response/): Convolves the audio with a randomly chosen impulse response
* [BandPassFilter](https://iver56.github.io/audiomentations/waveform_transforms/band_pass_filter/): Applies band-pass filtering within randomized parameters
* [BandStopFilter](https://iver56.github.io/audiomentations/waveform_transforms/band_stop_filter/): Applies band-stop (notch) filtering within randomized parameters
* [BitCrush](https://iver56.github.io/audiomentations/waveform_transforms/bit_crush/): Applies bit reduction without dithering
* [Clip](https://iver56.github.io/audiomentations/waveform_transforms/clip/): Clips audio samples to specified minimum and maximum values
* [ClippingDistortion](https://iver56.github.io/audiomentations/waveform_transforms/clipping_distortion/): Distorts the signal by clipping a random percentage of samples
* [Gain](https://iver56.github.io/audiomentations/waveform_transforms/gain/): Multiplies the audio by a random gain factor
* [GainTransition](https://iver56.github.io/audiomentations/waveform_transforms/gain_transition/): Gradually changes the gain over a random time span
* [HighPassFilter](https://iver56.github.io/audiomentations/waveform_transforms/high_pass_filter/): Applies high-pass filtering within randomized parameters
* [HighShelfFilter](https://iver56.github.io/audiomentations/waveform_transforms/high_shelf_filter/): Applies a high shelf filter with randomized parameters
* [Lambda](https://iver56.github.io/audiomentations/waveform_transforms/lambda/): Applies a user-defined transform
* [Limiter](https://iver56.github.io/audiomentations/waveform_transforms/limiter/): Applies dynamic range compression limiting the audio signal
* [LoudnessNormalization](https://iver56.github.io/audiomentations/waveform_transforms/loudness_normalization/): Applies gain to match a target loudness
* [LowPassFilter](https://iver56.github.io/audiomentations/waveform_transforms/low_pass_filter/): Applies low-pass filtering within randomized parameters
* [LowShelfFilter](https://iver56.github.io/audiomentations/waveform_transforms/low_shelf_filter/): Applies a low shelf filter with randomized parameters
* [Mp3Compression](https://iver56.github.io/audiomentations/waveform_transforms/mp3_compression/): Compresses the audio to lower the quality
* [Normalize](https://iver56.github.io/audiomentations/waveform_transforms/normalize/): Applies gain so that the highest signal level becomes 0 dBFS
* [Padding](https://iver56.github.io/audiomentations/waveform_transforms/padding/): Replaces a random part of the beginning or end with padding
* [PeakingFilter](https://iver56.github.io/audiomentations/waveform_transforms/peaking_filter/): Applies a peaking filter with randomized parameters
* [PitchShift](https://iver56.github.io/audiomentations/waveform_transforms/pitch_shift/): Shifts the pitch up or down without changing the tempo
* [PolarityInversion](https://iver56.github.io/audiomentations/waveform_transforms/polarity_inversion/): Flips the audio samples upside down, reversing their polarity
* [RepeatPart](https://iver56.github.io/audiomentations/waveform_transforms/repeat_part/): Repeats a subsection of the audio a number of times
* [Resample](https://iver56.github.io/audiomentations/waveform_transforms/resample/): Resamples the signal to a randomly chosen sampling rate
* [Reverse](https://iver56.github.io/audiomentations/waveform_transforms/reverse/): Reverses the audio along its time axis
* [RoomSimulator](https://iver56.github.io/audiomentations/waveform_transforms/room_simulator/): Simulates the effect of a room on an audio source
* [SevenBandParametricEQ](https://iver56.github.io/audiomentations/waveform_transforms/seven_band_parametric_eq/): Adjusts the volume of 7 frequency bands
* [Shift](https://iver56.github.io/audiomentations/waveform_transforms/shift/): Shifts the samples forwards or backwards
* [SpecChannelShuffle](https://iver56.github.io/audiomentations/spectrogram_transforms/): Shuffles channels in the spectrogram
* [SpecFrequencyMask](https://iver56.github.io/audiomentations/spectrogram_transforms/): Applies a frequency mask to the spectrogram
* [TanhDistortion](https://iver56.github.io/audiomentations/waveform_transforms/tanh_distortion/): Applies tanh distortion to distort the signal
* [TimeMask](https://iver56.github.io/audiomentations/waveform_transforms/time_mask/): Makes a random part of the audio silent
* [TimeStretch](https://iver56.github.io/audiomentations/waveform_transforms/time_stretch/): Changes the speed without changing the pitch
* [Trim](https://iver56.github.io/audiomentations/waveform_transforms/trim/): Trims leading and trailing silence from the audio
# Changelog
## [0.40.0] - 2025-03-20
### Added
* Add support for numpy 2.x
* Add support for scipy>=1.13
### Changed
* Speed up `LoudnessNormalization` by ~20%
* Improve test coverage and documentation
* Bump min `python-stretch` version and remove the limitation on the number of channels in `PitchShift`
* Bump min numpy version to 1.22
* Bump min pyroomacoustics version to 0.7.4
### Fix
* Fix a bug where `TimeMask` could raise an exception if the fade length became 0
* Disallow `min_cutoff_freq` <= 0 in `HighPassFilter`
* Make `AdjustDuration` picklable (useful for multiprocessing)
### Removed
* Remove support for Python 3.8
For the full changelog, including older versions, see [https://iver56.github.io/audiomentations/changelog/](https://iver56.github.io/audiomentations/changelog/)
# Acknowledgements
Thanks to [Nomono](https://nomono.co/) for backing audiomentations.
Thanks to [all contributors](https://github.com/iver56/audiomentations/graphs/contributors) who help improving audiomentations.
Raw data
{
"_id": null,
"home_page": "https://github.com/iver56/audiomentations",
"name": "audiomentations",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.13,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Iver Jordal",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/76/bb/858a5770376c21d501be0f505f212114d3720f5f1cd80d11dc5a5ccadf6b/audiomentations-0.40.0.tar.gz",
"platform": null,
"description": "# Audiomentations\r\n\r\n[](https://circleci.com/gh/iver56/audiomentations)\r\n[](https://codecov.io/gh/iver56/audiomentations)\r\n[](https://github.com/psf/black)\r\n[](https://github.com/iver56/audiomentations/blob/main/LICENSE)\r\n[](https://doi.org/10.5281/zenodo.15056865)\r\n\r\nA Python library for audio data augmentation. Inspired by\r\n[albumentations](https://github.com/albu/albumentations). Useful for deep learning. Runs on\r\nCPU. Supports mono audio and multichannel audio. Can be\r\nintegrated in training pipelines in e.g. Tensorflow/Keras or Pytorch. Has helped people get\r\nworld-class results in Kaggle competitions. Is used by companies making next-generation audio\r\nproducts.\r\n\r\nNeed a Pytorch-specific alternative with GPU support? Check out [torch-audiomentations](https://github.com/asteroid-team/torch-audiomentations)!\r\n\r\n# Setup\r\n\r\n\r\n[](https://pypi.org/project/audiomentations/)\r\n[](https://pypi.org/project/audiomentations/)\r\n\r\n\r\n`pip install audiomentations`\r\n\r\n# Usage example\r\n\r\n```python\r\nfrom audiomentations import Compose, AddGaussianNoise, TimeStretch, PitchShift, Shift\r\nimport numpy as np\r\n\r\naugment = Compose([\r\n AddGaussianNoise(min_amplitude=0.001, max_amplitude=0.015, p=0.5),\r\n TimeStretch(min_rate=0.8, max_rate=1.25, p=0.5),\r\n PitchShift(min_semitones=-4, max_semitones=4, p=0.5),\r\n Shift(p=0.5),\r\n])\r\n\r\n# Generate 2 seconds of dummy audio for the sake of example\r\nsamples = np.random.uniform(low=-0.2, high=0.2, size=(32000,)).astype(np.float32)\r\n\r\n# Augment/transform/perturb the audio data\r\naugmented_samples = augment(samples=samples, sample_rate=16000)\r\n```\r\n\r\n# Documentation\r\n\r\nThe API documentation, along with guides, example code, illustrations and example sounds, is available at [https://iver56.github.io/audiomentations/](https://iver56.github.io/audiomentations/)\r\n\r\n# Transforms\r\n\r\n* [AddBackgroundNoise](https://iver56.github.io/audiomentations/waveform_transforms/add_background_noise/): Mixes in another sound to add background noise\r\n* [AddColorNoise](https://iver56.github.io/audiomentations/waveform_transforms/add_color_noise/): Adds noise with specific color\r\n* [AddGaussianNoise](https://iver56.github.io/audiomentations/waveform_transforms/add_gaussian_noise/): Adds gaussian noise to the audio samples\r\n* [AddGaussianSNR](https://iver56.github.io/audiomentations/waveform_transforms/add_gaussian_snr/): Injects gaussian noise using a randomly chosen signal-to-noise ratio\r\n* [AddShortNoises](https://iver56.github.io/audiomentations/waveform_transforms/add_short_noises/): Mixes in various short noise sounds\r\n* [AdjustDuration](https://iver56.github.io/audiomentations/waveform_transforms/adjust_duration/): Trims or pads the audio to fit a target duration\r\n* [AirAbsorption](https://iver56.github.io/audiomentations/waveform_transforms/air_absorption/): Applies frequency-dependent attenuation simulating air absorption\r\n* [Aliasing](https://iver56.github.io/audiomentations/waveform_transforms/aliasing/): Produces aliasing artifacts by downsampling without low-pass filtering and then upsampling\r\n* [ApplyImpulseResponse](https://iver56.github.io/audiomentations/waveform_transforms/apply_impulse_response/): Convolves the audio with a randomly chosen impulse response\r\n* [BandPassFilter](https://iver56.github.io/audiomentations/waveform_transforms/band_pass_filter/): Applies band-pass filtering within randomized parameters\r\n* [BandStopFilter](https://iver56.github.io/audiomentations/waveform_transforms/band_stop_filter/): Applies band-stop (notch) filtering within randomized parameters\r\n* [BitCrush](https://iver56.github.io/audiomentations/waveform_transforms/bit_crush/): Applies bit reduction without dithering\r\n* [Clip](https://iver56.github.io/audiomentations/waveform_transforms/clip/): Clips audio samples to specified minimum and maximum values\r\n* [ClippingDistortion](https://iver56.github.io/audiomentations/waveform_transforms/clipping_distortion/): Distorts the signal by clipping a random percentage of samples\r\n* [Gain](https://iver56.github.io/audiomentations/waveform_transforms/gain/): Multiplies the audio by a random gain factor\r\n* [GainTransition](https://iver56.github.io/audiomentations/waveform_transforms/gain_transition/): Gradually changes the gain over a random time span\r\n* [HighPassFilter](https://iver56.github.io/audiomentations/waveform_transforms/high_pass_filter/): Applies high-pass filtering within randomized parameters\r\n* [HighShelfFilter](https://iver56.github.io/audiomentations/waveform_transforms/high_shelf_filter/): Applies a high shelf filter with randomized parameters\r\n* [Lambda](https://iver56.github.io/audiomentations/waveform_transforms/lambda/): Applies a user-defined transform\r\n* [Limiter](https://iver56.github.io/audiomentations/waveform_transforms/limiter/): Applies dynamic range compression limiting the audio signal\r\n* [LoudnessNormalization](https://iver56.github.io/audiomentations/waveform_transforms/loudness_normalization/): Applies gain to match a target loudness\r\n* [LowPassFilter](https://iver56.github.io/audiomentations/waveform_transforms/low_pass_filter/): Applies low-pass filtering within randomized parameters\r\n* [LowShelfFilter](https://iver56.github.io/audiomentations/waveform_transforms/low_shelf_filter/): Applies a low shelf filter with randomized parameters\r\n* [Mp3Compression](https://iver56.github.io/audiomentations/waveform_transforms/mp3_compression/): Compresses the audio to lower the quality\r\n* [Normalize](https://iver56.github.io/audiomentations/waveform_transforms/normalize/): Applies gain so that the highest signal level becomes 0 dBFS\r\n* [Padding](https://iver56.github.io/audiomentations/waveform_transforms/padding/): Replaces a random part of the beginning or end with padding\r\n* [PeakingFilter](https://iver56.github.io/audiomentations/waveform_transforms/peaking_filter/): Applies a peaking filter with randomized parameters\r\n* [PitchShift](https://iver56.github.io/audiomentations/waveform_transforms/pitch_shift/): Shifts the pitch up or down without changing the tempo\r\n* [PolarityInversion](https://iver56.github.io/audiomentations/waveform_transforms/polarity_inversion/): Flips the audio samples upside down, reversing their polarity\r\n* [RepeatPart](https://iver56.github.io/audiomentations/waveform_transforms/repeat_part/): Repeats a subsection of the audio a number of times\r\n* [Resample](https://iver56.github.io/audiomentations/waveform_transforms/resample/): Resamples the signal to a randomly chosen sampling rate\r\n* [Reverse](https://iver56.github.io/audiomentations/waveform_transforms/reverse/): Reverses the audio along its time axis\r\n* [RoomSimulator](https://iver56.github.io/audiomentations/waveform_transforms/room_simulator/): Simulates the effect of a room on an audio source\r\n* [SevenBandParametricEQ](https://iver56.github.io/audiomentations/waveform_transforms/seven_band_parametric_eq/): Adjusts the volume of 7 frequency bands\r\n* [Shift](https://iver56.github.io/audiomentations/waveform_transforms/shift/): Shifts the samples forwards or backwards\r\n* [SpecChannelShuffle](https://iver56.github.io/audiomentations/spectrogram_transforms/): Shuffles channels in the spectrogram\r\n* [SpecFrequencyMask](https://iver56.github.io/audiomentations/spectrogram_transforms/): Applies a frequency mask to the spectrogram\r\n* [TanhDistortion](https://iver56.github.io/audiomentations/waveform_transforms/tanh_distortion/): Applies tanh distortion to distort the signal\r\n* [TimeMask](https://iver56.github.io/audiomentations/waveform_transforms/time_mask/): Makes a random part of the audio silent\r\n* [TimeStretch](https://iver56.github.io/audiomentations/waveform_transforms/time_stretch/): Changes the speed without changing the pitch\r\n* [Trim](https://iver56.github.io/audiomentations/waveform_transforms/trim/): Trims leading and trailing silence from the audio\r\n\r\n# Changelog\r\n\r\n## [0.40.0] - 2025-03-20\r\n\r\n### Added\r\n\r\n* Add support for numpy 2.x\r\n* Add support for scipy>=1.13\r\n\r\n### Changed\r\n\r\n* Speed up `LoudnessNormalization` by ~20%\r\n* Improve test coverage and documentation\r\n* Bump min `python-stretch` version and remove the limitation on the number of channels in `PitchShift`\r\n* Bump min numpy version to 1.22\r\n* Bump min pyroomacoustics version to 0.7.4\r\n\r\n### Fix\r\n\r\n* Fix a bug where `TimeMask` could raise an exception if the fade length became 0\r\n* Disallow `min_cutoff_freq` <= 0 in `HighPassFilter`\r\n* Make `AdjustDuration` picklable (useful for multiprocessing)\r\n\r\n### Removed\r\n\r\n* Remove support for Python 3.8\r\n\r\nFor the full changelog, including older versions, see [https://iver56.github.io/audiomentations/changelog/](https://iver56.github.io/audiomentations/changelog/)\r\n\r\n# Acknowledgements\r\n\r\nThanks to [Nomono](https://nomono.co/) for backing audiomentations.\r\n\r\nThanks to [all contributors](https://github.com/iver56/audiomentations/graphs/contributors) who help improving audiomentations.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python library for audio data augmentation. Inspired by albumentations. Useful for machine learning.",
"version": "0.40.0",
"project_urls": {
"Changelog": "https://iver56.github.io/audiomentations/changelog/",
"Documentation": "https://iver56.github.io/audiomentations/",
"Homepage": "https://github.com/iver56/audiomentations",
"Issue Tracker": "https://github.com/iver56/audiomentations/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "914011065c4482d5b65d1c3837ed6f5365e40b15ca07cd5513eca6331c524a46",
"md5": "466ff29380038550c2191cc5f0a5bdef",
"sha256": "e16e518cf9997d679415bad4117fb7a89a2cd9fd85d38d36da988194ccdcb990"
},
"downloads": -1,
"filename": "audiomentations-0.40.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "466ff29380038550c2191cc5f0a5bdef",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.13,>=3.9",
"size": 83575,
"upload_time": "2025-03-20T12:11:32",
"upload_time_iso_8601": "2025-03-20T12:11:32.766875Z",
"url": "https://files.pythonhosted.org/packages/91/40/11065c4482d5b65d1c3837ed6f5365e40b15ca07cd5513eca6331c524a46/audiomentations-0.40.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "76bb858a5770376c21d501be0f505f212114d3720f5f1cd80d11dc5a5ccadf6b",
"md5": "b60a054ad06f8d084197f5b59812b456",
"sha256": "3f82557d00ffc9ad4b1fa3c0e324a3a4b00601721ce45014de1b4a0f405b961f"
},
"downloads": -1,
"filename": "audiomentations-0.40.0.tar.gz",
"has_sig": false,
"md5_digest": "b60a054ad06f8d084197f5b59812b456",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.13,>=3.9",
"size": 82106,
"upload_time": "2025-03-20T12:11:33",
"upload_time_iso_8601": "2025-03-20T12:11:33.904996Z",
"url": "https://files.pythonhosted.org/packages/76/bb/858a5770376c21d501be0f505f212114d3720f5f1cd80d11dc5a5ccadf6b/audiomentations-0.40.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-20 12:11:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "iver56",
"github_project": "audiomentations",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"circle": true,
"lcname": "audiomentations"
}