soundmentations.PadToMultiple¶
- class soundmentations.PadToMultiple(pad_length: int, p: float = 1.0)[source]¶
Bases:
BasePadPad audio to make its length a multiple of the specified value.
This is useful for STFT operations where frame sizes must be multiples of certain values. Only adds padding at the end, never trims.
- Parameters:
Examples
Pad for STFT-friendly lengths:
>>> import numpy as np >>> from soundmentations.transforms.time import PadToMultiple >>> >>> # Audio with length 2050 samples >>> audio = np.random.randn(2050) >>> >>> # Pad to multiple of 1024 (STFT frame size) >>> pad_transform = PadToMultiple(pad_length=1024) >>> result = pad_transform(audio) >>> print(len(result)) # 3072 (3 * 1024)
Use in spectral processing pipeline:
>>> import soundmentations as S >>> >>> # Prepare audio for spectral analysis >>> spectral_prep = S.Compose([ ... S.PadToMultiple(pad_length=512, p=1.0), # STFT-friendly ... S.Gain(gain=(-3, 3), p=0.5) ... ]) >>> >>> stft_ready_audio = spectral_prep(raw_audio)