maad.sound.trim

maad.sound.trim(s, fs, min_t, max_t, pad=False, pad_constant=0)[source]

Slices a time series, from a initial time min_t to an ending time max_t. If the target duration duration = is larger than the original duration and pad = True, the time series is padded with a constant value pad_constant = 0.

Parameters:
snp.ndarray

Mono or stereo signal as NumPy array.

fsint

Time series sampling rate.

min_tfloat

Initial time. If initial time min_t < 0 and pad=True, this time is added to the beginning of the audio slice.

max_tfloat

Ending time of the audio slice.

padbool, optional

If true, the time series is padded with a constant value pad_constant. Default is False.

pad_constant

It is the constant with which the time series is padded.

Returns:
s_slicenp.ndarray

Time series with duration duration = max_t - min_t.

See also

numpy.pad

Examples

Slice an audio file from 5 to 8 seconds.

>>> from maad import sound
>>> s, fs = sound.load('../data/spinetail.wav') 
>>> s_slice = sound.trim(s, fs, min_t = 5, max_t = 8)
>>> _ = sound.spectrogram(s_slice, fs, display=True, figsize=(4,6))
>>> s_slice.shape[0]/fs
3.0