mindspore.dataset.audio.Resample
- class mindspore.dataset.audio.Resample(orig_freq=16000, new_freq=16000, resample_method=ResampleMethod.SINC_INTERPOLATION, lowpass_filter_width=6, rolloff=0.99, beta=None)[source]
Resample a signal from one frequency to another. A resample method can be given.
- Parameters
orig_freq (float, optional) – The original frequency of the signal, must be positive. Default:
16000
.new_freq (float, optional) – The desired frequency, must be positive. Default:
16000
.resample_method (ResampleMethod, optional) – The resample method to use, can be
ResampleMethod.SINC_INTERPOLATION
orResampleMethod.KAISER_WINDOW
. Default:ResampleMethod.SINC_INTERPOLATION
.lowpass_filter_width (int, optional) – Controls the sharpness of the filter, more means sharper but less efficient, must be positive. Default:
6
.rolloff (float, optional) – The roll-off frequency of the filter, as a fraction of the Nyquist. Lower values reduce anti-aliasing, but also reduce some of the highest frequencies, in range of (0, 1]. Default:
0.99
.beta (float, optional) – The shape parameter used for kaiser window. Default:
None
, will use14.769656459379492
.
- Raises
TypeError – If orig_freq is not of type float.
ValueError – If orig_freq is not a positive number.
TypeError – If new_freq is not of type float.
ValueError – If new_freq is not a positive number.
TypeError – If resample_method is not of type
mindspore.dataset.audio.ResampleMethod
.TypeError – If lowpass_filter_width is not of type int.
ValueError – If lowpass_filter_width is not a positive number.
TypeError – If rolloff is not of type float.
ValueError – If rolloff is not in range of (0, 1].
RuntimeError – If input tensor is not in shape of <…, time>.
- Supported Platforms:
CPU
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.audio as audio >>> from mindspore.dataset.audio import ResampleMethod >>> >>> waveform = np.random.random([1, 30]) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"]) >>> transforms = [audio.Resample(orig_freq=48000, new_freq=16000, ... resample_method=ResampleMethod.SINC_INTERPOLATION, ... lowpass_filter_width=6, rolloff=0.99, beta=None)] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms, input_columns=["audio"])
- Tutorial Examples: