soundmentations.Compose¶
- class soundmentations.Compose(transforms)[source]¶
Bases:
BaseCompose
Compose multiple audio transforms into a sequential pipeline.
This class allows you to chain multiple transforms together into a single callable object. Transforms are applied in the order they appear in the list, with each transform receiving the output of the previous one.
- Parameters:
transforms (list) – List of transform objects to apply sequentially. Each transform must implement __call__(samples, sample_rate).
Examples
Create a basic augmentation pipeline:
>>> import soundmentations as S >>> >>> # Define individual transforms >>> pipeline = S.Compose([ ... S.RandomTrim(duration=(1.0, 3.0), p=0.8), ... S.Pad(pad_length=44100, p=0.6), ... S.Gain(gain=6.0, p=0.5) ... ]) >>> >>> # Apply to audio >>> augmented = pipeline(audio_samples, sample_rate=44100)
Complex preprocessing pipeline:
>>> # ML training data preparation >>> ml_pipeline = S.Compose([ ... S.CenterTrim(duration=2.0), # Extract 2s from center ... S.PadToLength(pad_length=88200), # Normalize to exactly 2s ... S.Gain(gain=3.0, p=0.7), # Boost volume 70% of time ... S.FadeIn(duration=0.1, p=0.5), # Smooth start 50% of time ... S.FadeOut(duration=0.1, p=0.5) # Smooth end 50% of time ... ]) >>> >>> # Process batch of audio files >>> for audio in audio_batch: ... processed = ml_pipeline(audio, sample_rate=16000)
Audio enhancement pipeline:
>>> # Clean up audio recordings >>> enhance_pipeline = S.Compose([ ... S.StartTrim(start_time=0.5), # Remove first 0.5s ... S.EndTrim(end_time=10.0), # Keep max 10s ... S.Gain(gain=6.0), # Boost volume ... S.FadeIn(duration=0.2), # Smooth fade-in ... S.FadeOut(duration=0.2) # Smooth fade-out ... ]) >>> >>> enhanced = enhance_pipeline(noisy_audio, sample_rate=44100)
Notes
Transforms are applied in order: first transform in list is applied first
Each transform receives the output of the previous transform
Probability parameters (p) in individual transforms are respected
The pipeline preserves mono audio format throughout
All transforms must accept (samples, sample_rate) parameters
See also
Individual
,Trim
,Pad
,RandomTrim
,FadeIn
,FadeOut