Differences with torchaudio.transforms.Resample
torchaudio.transforms.Resample
class torchaudio.transforms.Resample(orig_freq: int = 16000, new_freq: int = 16000, resampling_method: str = 'sinc_interpolation')
For more information, see torchaudio.transforms.Resample.
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)
For more information, see mindspore.dataset.audio.Resample.
Differences
PyTorch: Resample a signal from one frequency to another.
MindSpore: Resample a signal from one frequency to another. Extra filter option is supported.
Categories |
Subcategories |
PyTorch |
MindSpore |
Difference |
---|---|---|---|---|
Parameter |
Parameter1 |
orig_freq |
orig_freq |
- |
Parameter2 |
new_freq |
new_freq |
- |
|
Parameter3 |
resampling_method |
resample_method |
- |
|
Parameter4 |
- |
lowpass_filter_width |
Sharpness of the filter |
|
Parameter5 |
- |
rolloff |
The roll-off frequency of the filter |
|
Parameter6 |
- |
beta |
The shape parameter used for kaiser window |
Code Example
import numpy as np
fake_input = np.array([[[[-0.2197528, 0.3821656]]],
[[[0.57418776, 0.46741104]]],
[[[0.76986176, -0.5793846]]]]).astype(np.float32)
# PyTorch
import torch
import torchaudio.transforms as T
transformer = T.Resample(orig_freq=16000, new_freq=24000)
torch_result = transformer(torch.from_numpy(fake_input))
print(torch_result)
# Out: tensor([[[[-0.2140, 0.2226, 0.3510]]],
# [[[ 0.5728, 0.6145, 0.2789]]],
# [[[ 0.7568, -0.1601, -0.6101]]]])
# MindSpore
import mindspore.dataset.audio as audio
transformer = audio.Resample(orig_freq=16000, new_freq=24000)
ms_result = transformer(fake_input)
print(ms_result)
# Out: [[[[-0.21398525 0.22255361 0.35099414]]]
# [[[ 0.5728122 0.614469 0.2788692 ]]]
# [[[ 0.75675076 -0.16008556 -0.61005235]]]]