mindspore.dataset.audio.Phaser

View Source On Gitee
class mindspore.dataset.audio.Phaser(sample_rate, gain_in=0.4, gain_out=0.74, delay_ms=3.0, decay=0.4, mod_speed=0.5, sinusoidal=True)[source]

Apply a phasing effect to the audio.

Similar to SoX implementation.

Parameters
  • sample_rate (int) – Sampling rate of the waveform, e.g. 44100 (Hz).

  • gain_in (float, optional) – Desired input gain at the boost (or attenuation) in dB, in range of [0.0, 1.0]. Default: 0.4.

  • gain_out (float, optional) – Desired output gain at the boost (or attenuation) in dB, in range of [0.0, 1e9]. Default: 0.74.

  • delay_ms (float, optional) – Desired delay in milliseconds, in range of [0.0, 5.0]. Default: 3.0.

  • decay (float, optional) – Desired decay relative to gain-in, in range of [0.0, 0.99]. Default: 0.4.

  • mod_speed (float, optional) – Modulation speed in Hz, in range of [0.1, 2.0]. Default: 0.5.

  • sinusoidal (bool, optional) – If True, use sinusoidal modulation (preferable for multiple instruments). If False, use triangular modulation (gives single instruments a sharper phasing effect). Default: True.

Raises
  • TypeError – If sample_rate is not of type int.

  • TypeError – If gain_in is not of type float.

  • ValueError – If gain_in is not in range of [0.0, 1.0].

  • TypeError – If gain_out is not of type float.

  • ValueError – If gain_out is not in range of [0.0, 1e9].

  • TypeError – If delay_ms is not of type float.

  • ValueError – If delay_ms is not in range of [0.0, 5.0].

  • TypeError – If decay is not of type float.

  • ValueError – If decay is not in range of [0.0, 0.99].

  • TypeError – If mod_speed is not of type float.

  • ValueError – If mod_speed is not in range of [0.1, 2.0].

  • TypeError – If sinusoidal is not of type bool.

  • 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, 12])  # 5 samples
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"])
>>> transforms = [audio.Phaser(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
(12,) float64
>>>
>>> # Use the transform in eager mode
>>> waveform = np.random.random([12])  # 1 sample
>>> output = audio.Phaser(44100)(waveform)
>>> print(output.shape, output.dtype)
(12,) float64
Tutorial Examples: