maad.sound.resample

maad.sound.resample(s, fs, target_fs, res_type='kaiser_best', **kwargs)[source]

Changes the sample rate of an audio file or any time series.

Parameters:
snp.ndarray

Mono or stereo signal as NumPy array.

fsint

Time series sampling rate.

target_fsint

Target sampling rate.

res_typestr, optional

Resample method. By default ‘kaiser_best’. ‘kaiser_best’ method that applies a Kaiser windowed sinc interpolation. ‘kaiser_fast’ similar to kaiser_best, but faster. ‘scipy’ is a Fourier transform method implemented in scipy. ‘scipy_poly’ Resample using polyphase filtering and an FIR filter.

kwargsadditional keyword arguments

If res_type=’sinc_window’, additional keyword arguments to pass to resampy.resample.

Returns:
res_datanp.ndarray

Resampling time series.

See also

resampy.resample
scipy.signal.resample

Examples

Resample an audio file from sample rate of 44100 kHz to 22050.

>>> s, fs = sound.load('../data/spinetail.wav')
>>> s_resamp = sound.resample(s, fs, target_fs=fs/2)
>>> print('Number of samples - original audio:', s.shape[0],
...       'Number of samples - resampled audio:', s_resamp.shape[0])
>>> _ = sound.spectrogram(s, fs, display=True)
>>> _ = sound.spectrogram(s_resamp, fs/2, display=True)