mindspore.dataset.audio.PhaseVocoder

class mindspore.dataset.audio.PhaseVocoder(rate, phase_advance)[源代码]

对给定的STFT频谱,在不改变音高的情况下以一定比率进行加速。

参数:
  • rate (float) - 加速比率。

  • phase_advance (numpy.ndarray) - 每个频段的预期相位提前量,shape为<freq, 1>。

异常:
  • TypeError - 当 rate 的类型不为float。

  • ValueError - 当 rate 不为正数。

  • TypeError - 当 phase_advance 的类型不为 numpy.ndarray

  • RuntimeError - 当输入音频的shape不为<…, freq, num_frame, complex=2>。

支持平台:

CPU

样例:

>>> 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, 44, 10, 2])  # 5 samples
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"])
>>> transforms = [audio.PhaseVocoder(rate=2, phase_advance=np.random.random([44, 1]))]
>>> 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
(44, 5, 2) float64
>>>
>>> # Use the transform in eager mode
>>> waveform = np.random.random([44, 10, 2])  # 1 sample
>>> output = audio.PhaseVocoder(rate=2, phase_advance=np.random.random([44, 1]))(waveform)
>>> print(output.shape, output.dtype)
(44, 5, 2) float64
教程样例: