mindspore.dataset.audio.Flanger

class mindspore.dataset.audio.Flanger(sample_rate, delay=0.0, depth=2.0, regen=0.0, width=71.0, speed=0.5, phase=25.0, modulation=Modulation.SINUSOIDAL, interpolation=Interpolation.LINEAR)[源代码]

给音频施加镶边效果。

接口实现方式类似于 SoX库 。

参数:
  • sample_rate (int) - 波形采样频率,例如44100 (Hz)。

  • delay (float, 可选) - 期望的延迟时间,单位为毫秒,取值范围为[0, 30]。默认值: 0.0 。

  • depth (float, 可选) - 期望的延迟深度,单位为毫秒,取值范围为[0, 10]。默认值: 2.0 。

  • regen (float, 可选) - 期望的反馈增益,单位为dB,取值范围为[-95, 95]。默认值: 0.0 。

  • width (float, 可选) - 期望的延迟增益,单位为dB,取值范围为[0, 100]。默认值: 71.0 。

  • speed (float, 可选) - 调制速度,单位为Hz,取值范围为[0.1, 10]。默认值: 0.5 。

  • phase (float, 可选) - 各通道的相位偏移百分比,取值范围为[0, 100]。默认值: 25.0 。

  • modulation (Modulation, 可选) - 调制方法,可为 Modulation.SINUSOIDAL 或 Modulation.TRIANGULAR 。 默认值: Modulation.SINUSOIDAL 。

  • interpolation (Interpolation, 可选) - 插值方法,可为 Interpolation.LINEAR 或 Interpolation.QUADRATIC 。 默认值: Interpolation.LINEAR 。

异常:
  • TypeError - 当 sample_rate 的类型不为int。

  • ValueError - 当 sample_rate 为零。

  • TypeError - 当 delay 的类型不为float。

  • ValueError - 当 delay 取值不在[0, 30]范围内。

  • TypeError - 当 depth 的类型不为float。

  • ValueError - 当 depth 取值不在[0, 10]范围内。

  • TypeError - 当 regen 的类型不为float。

  • ValueError - 当 regen 取值不在[-95, 95]范围内。

  • TypeError - 当 width 的类型不为float。

  • ValueError - 当 width 取值不在[0, 100]范围内。

  • TypeError - 当 speed 的类型不为float。

  • ValueError - 当 speed 取值不在[0.1, 10]范围内。

  • TypeError - 当 phase 的类型不为float。

  • ValueError - 当 phase 取值不在[0, 100]范围内。

  • TypeError - 当 modulation 的类型不为 mindspore.dataset.audio.Modulation 。

  • TypeError - 当 interpolation 的类型不为 mindspore.dataset.audio.Interpolation 。

  • RuntimeError - 当输入音频的shape不为<…, channel, time>。

支持平台:

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