mindspore.dataset.audio.DCShift

class mindspore.dataset.audio.DCShift(shift, limiter_gain=None)[source]

Apply a DC shift to the audio. This can be useful to remove DC offset from audio.

Parameters
  • shift (float) – The amount to shift the audio, the value must be in the range [-2.0, 2.0].

  • limiter_gain (float, optional) – Used only on peaks to prevent clipping, the value should be much less than 1, such as 0.05 or 0.02. Default: None, will be set to shift .

Raises
  • TypeError – If shift is not of type float.

  • ValueError – If shift is not in range [-2.0, 2.0].

  • TypeError – If limiter_gain is not of type float.

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