soundmentations.OneOf¶
- class soundmentations.OneOf(transforms, p=1.0)[source]¶
Bases:
BaseComposeApply one transform from a list of transforms, chosen at random.
This class allows you to randomly select and apply one transform from a provided list. Each transform has an equal chance of being selected unless specified otherwise.
- Parameters:
Examples
Create a random augmentation pipeline:
>>> import soundmentations as S >>> >>> # Define individual transforms >>> pipeline = S.OneOf([ ... S.Gain(gain=6.0), ... S.FadeIn(duration=0.5), ... S.FadeOut(duration=0.5) ... ], p=0.9) >>> >>> # Apply to audio >>> augmented = pipeline(audio_samples, sample_rate=44100)
Randomized preprocessing pipeline:
>>> # ML training data preparation with randomness >>> ml_pipeline = S.OneOf([ ... S.RandomTrim(duration=(1.0, 3.0)), ... S.Pad(pad_length=44100), ... S.Gain(gain=3.0) ... ], p=0.8) >>> >>> # Process batch of audio files >>> for audio in audio_batch: ... processed = ml_pipeline(audio, sample_rate=16000)
Audio enhancement with random effects:
>>> # Clean up audio recordings with variability >>> enhance_pipeline = S.OneOf([ ... S.StartTrim(start_time=0.5), ... S.EndTrim(end_time=10.0), ... S.FadeIn(duration=0.2), ... S.FadeOut(duration=0.2) ... ], p=0.7) >>> >>> enhanced = enhance_pipeline(noisy_audio, sample_rate=44100)
Notes
Only one transform is applied per call, chosen at random
Probability parameter (p) controls likelihood of applying any transform - If not applied, input audio is returned unchanged