mindspore.dataset.audio.InverseSpectrogram

View Source On Gitee
class mindspore.dataset.audio.InverseSpectrogram(length=None, n_fft=400, win_length=None, hop_length=None, pad=0, window=WindowType.HANN, normalized=False, center=True, pad_mode=BorderType.REFLECT, onesided=True)[source]

Create an inverse spectrogram to recover an audio signal from a spectrogram.

Parameters
  • length (int, optional) – The output length of the waveform, must be non negative. Default: None, means to output the whole waveform.

  • n_fft (int, optional) – Size of FFT, creates n_fft // 2 + 1 bins, which should be greater than 0. Default: 400.

  • win_length (int, optional) – Window size, which should be greater than 0. Default: None, will be set to n_fft .

  • hop_length (int, optional) – Length of hop between STFT windows, which should be greater than 0. Default: None, will be set to win_length // 2 .

  • pad (int, optional) – Two sided padding of signal, cannot be less than 0. Default: 0.

  • window (WindowType, optional) – A function to create a window tensor that is applied/multiplied to each frame/window. Default: WindowType.HANN.

  • normalized (bool, optional) – Whether the spectrogram was normalized by magnitude after stft. Default: False.

  • center (bool, optional) – Whether the signal in spectrogram was padded on both sides. Default: True.

  • pad_mode (BorderType, optional) – Controls the padding method used when center is True, can be BorderType.REFLECT, BorderType.CONSTANT, BorderType.EDGE or BorderType.SYMMETRIC. Default: BorderType.REFLECT.

  • onesided (bool, optional) – Controls whether spectrogram was used to return half of results to avoid redundancy. Default: True.

Raises
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, 400 // 2 + 1, 30, 2])  # 5 samples
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"])
>>> transforms = [audio.InverseSpectrogram(1, 400, 400, 200)]
>>> 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
(1,) float64
>>>
>>> # Use the transform in eager mode
>>> waveform = np.random.random([400 // 2 + 1, 30, 2])  # 1 sample
>>> output = audio.InverseSpectrogram(1, 400, 400, 200)(waveform)
>>> print(output.shape, output.dtype)
(1,) float64
Tutorial Examples: