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 >>> >>> # Use the transform in dataset pipeline mode >>> waveform = np.random.random([5, 16, 30]) # 5 samples >>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"]) >>> transforms = [audio.Resample(orig_freq=48000, new_freq=16000, ... resample_method=audio.ResampleMethod.SINC_INTERPOLATION, ... lowpass_filter_width=6, rolloff=0.99, beta=None)] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms, input_columns=["audio"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["audio"].shape, item["audio"].dtype) ... break (16, 10) float64 >>> >>> # Use the transform in eager mode >>> waveform = np.random.random([16, 30]) # 1 sample >>> output = audio.Resample(orig_freq=48000, new_freq=16000, ... resample_method=audio.ResampleMethod.SINC_INTERPOLATION, ... lowpass_filter_width=6, rolloff=0.99, beta=None)(waveform) >>> print(output.shape, output.dtype) (16, 10) float64
- Tutorial Examples: