Package: audiomentations
AudiomentationsA Python library for audio data augmentation. Inspired byalbumentations. 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 outtorch-audiomentations!Setuppip install audiomentationsUsage examplefromaudiomentationsimportCompose,AddGaussianNoise,TimeStretch,PitchShift,Shiftimportnumpyasnpaugment=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 examplesamples=np.random.uniform(low=-0.2,high=0.2,size=(32000,)).astype(np.float32)# Augment/transform/perturb the audio dataaugmented_samples=augment(samples=samples,sample_rate=16000)DocumentationThe API documentation, along with guides, example code, illustrations and example sounds, is available athttps://iver56.github.io/audiomentations/TransformsAddBackgroundNoise: Mixes in another sound to add background noiseAddGaussianNoise: Adds gaussian noise to the audio samplesAddGaussianSNR: Injects gaussian noise using a randomly chosen signal-to-noise ratioAddShortNoises: Mixes in various short noise soundsAdjustDuration: Trims or pads the audio to fit a target durationAirAbsorption: Applies frequency-dependent attenuation simulating air absorptionApplyImpulseResponse: Convolves the audio with a randomly chosen impulse responseBandPassFilter: Applies band-pass filtering within randomized parametersBandStopFilter: Applies band-stop (notch) filtering within randomized parametersClip: Clips audio samples to specified minimum and maximum valuesClippingDistortion: Distorts the signal by clipping a random percentage of samplesGain: Multiplies the audio by a random gain factorGainTransition: Gradually changes the gain over a random time spanHighPassFilter: Applies high-pass filtering within randomized parametersHighShelfFilter: Applies a high shelf filter with randomized parametersLambda: Applies a user-defined transformLimiter: Applies dynamic range compression limiting the audio signalLoudnessNormalization: Applies gain to match a target loudnessLowPassFilter: Applies low-pass filtering within randomized parametersLowShelfFilter: Applies a low shelf filter with randomized parametersMp3Compression: Compresses the audio to lower the qualityNormalize: Applies gain so that the highest signal level becomes 0 dBFSPadding: Replaces a random part of the beginning or end with paddingPeakingFilter: Applies a peaking filter with randomized parametersPitchShift: Shifts the pitch up or down without changing the tempoPolarityInversion: Flips the audio samples upside down, reversing their polarityRepeatPart: Repeats a subsection of the audio a number of timesResample: Resamples the signal to a randomly chosen sampling rateReverse: Reverses the audio along its time axisRoomSimulator: Simulates the effect of a room on an audio sourceSevenBandParametricEQ: Adjusts the volume of 7 frequency bandsShift: Shifts the samples forwards or backwardsSpecChannelShuffle: Shuffles channels in the spectrogramSpecFrequencyMask: Applies a frequency mask to the spectrogramTanhDistortion: Applies tanh distortion to distort the signalTimeMask: Makes a random part of the audio silentTimeStretch: Changes the speed without changing the pitchTrim: Trims leading and trailing silence from the audioChangelog[0.34.1] - 2023-11-24ChangedBump min numpy version from 1.18 to 1.21Use numpy.typing in type hintsOptimize max abs calculations in terms of memory and speed. This makesNormalize,Mp3CompressionandLimiterslightly faster.FixedCorrect some wrong type hintsFor the full changelog, including older versions, seehttps://iver56.github.io/audiomentations/changelog/AcknowledgementsThanks toNomonofor backing audiomentations.Thanks toall contributorswho help improving audiomentations.