soundmentations.EndTrim

class soundmentations.EndTrim(end_time: float, p: float = 1.0)[source]

Bases: BaseTrim

Trim audio to keep only the portion from the start to end_time.

This removes the end of the audio after end_time, keeping everything before that point.

Parameters:
  • end_time (float) – End time in seconds to stop keeping audio. Must be positive.

  • p (float, optional) – Probability of applying the transform, by default 1.0.

Examples

Keep only first part of audio:

>>> import numpy as np
>>> from soundmentations.transforms.time import EndTrim
>>>
>>> # Keep first 5 seconds only
>>> trim_transform = EndTrim(end_time=5.0)
>>> trimmed = trim_transform(audio, sample_rate=44100)

Use for consistent audio lengths:

>>> import soundmentations as S
>>>
>>> # Ensure maximum 10 seconds
>>> limit_length = S.Compose([
...     S.EndTrim(end_time=10.0, p=1.0),
...     S.Gain(gain=3.0, p=0.3)
... ])
>>>
>>> limited = limit_length(long_audio, sample_rate=44100)