soundmentations.CenterPad¶
- class soundmentations.CenterPad(pad_length: int, p: float = 1.0)[source]¶
Bases:
BasePadPad audio to minimum length by adding zeros symmetrically on both sides.
If the input audio is shorter than pad_length, zeros are added equally to both sides. For odd padding amounts, the extra zero goes to the right.
- Parameters:
Examples
Apply symmetric padding:
>>> import numpy as np >>> from soundmentations.transforms.time import CenterPad >>> >>> audio = np.array([1, 2, 3]) >>> pad_transform = CenterPad(pad_length=7) >>> result = pad_transform(audio) >>> print(result) # [0 0 1 2 3 0 0]
Use for centering audio in fixed-length windows:
>>> # Center audio in 5-second windows (44.1kHz) >>> center_pad = CenterPad(pad_length=220500) >>> centered_audio = center_pad(audio_sample)