soundmentations.Pad¶
- class soundmentations.Pad(pad_length: int, p: float = 1.0)[source]¶
Bases:
BasePadPad audio to minimum length by adding zeros at the end.
If the input audio is shorter than pad_length, zeros are appended to reach the minimum length. If already longer or equal, returns unchanged.
- Parameters:
Examples
Apply end padding to ensure minimum length:
>>> import numpy as np >>> from soundmentations.transforms.time import Pad >>> >>> # Create short audio sample >>> audio = np.array([0.1, 0.2, 0.3]) >>> >>> # Pad to minimum 1000 samples >>> pad_transform = Pad(pad_length=1000) >>> padded = pad_transform(audio) >>> print(len(padded)) # 1000
Use in a pipeline:
>>> import soundmentations as S >>> >>> # Ensure all audio is at least 2 seconds (44.1kHz) >>> augment = S.Compose([ ... S.Pad(pad_length=88200, p=1.0), ... S.Gain(gain=3.0, p=0.5) ... ]) >>> >>> result = augment(audio)