mindspore.dataset.audio.GriffinLim
- class mindspore.dataset.audio.GriffinLim(n_fft=400, n_iter=32, win_length=None, hop_length=None, window_type=WindowType.HANN, power=2.0, momentum=0.99, length=None, rand_init=True)[source]
- Compute waveform from a linear scale magnitude spectrogram using the Griffin-Lim transformation. - About Griffin-Lim please refer to A fast Griffin-Lim algorithm and Signal estimation from modified short-time Fourier transform . - Parameters
- n_fft (int, optional) – Size of FFT. Default: - 400.
- n_iter (int, optional) – Number of iteration for phase recovery. Default: - 32.
- win_length (int, optional) – Window size for Griffin-Lim. Default: - None, will be set to n_fft .
- hop_length (int, optional) – Length of hop between STFT windows. Default: - None, will be set to win_length // 2 .
- window_type (WindowType, optional) – Window type for Griffin-Lim, which can be - WindowType.BARTLETT,- WindowType.BLACKMAN,- WindowType.HAMMING,- WindowType.HANNor- WindowType.KAISER. Default:- WindowType.HANN. Currently kaiser window is not supported on macOS.
- power (float, optional) – Exponent for the magnitude spectrogram. Default: - 2.0.
- momentum (float, optional) – The momentum for fast Griffin-Lim. Default: - 0.99.
- length (int, optional) – Length of the expected output waveform. Default: - None, will be set to the value of last dimension of the stft matrix.
- rand_init (bool, optional) – Flag for random phase initialization or all-zero phase initialization. Default: - True.
 
- Raises
- TypeError – If n_fft is not of type int. 
- ValueError – If n_fft is not positive. 
- TypeError – If n_iter is not of type int. 
- ValueError – If n_iter is not positive. 
- TypeError – If win_length is not of type int. 
- ValueError – If win_length is a negative number. 
- TypeError – If hop_length is not of type int. 
- ValueError – If hop_length is a negative number. 
- TypeError – If window_type is not of type - mindspore.dataset.audio.WindowType.
- TypeError – If power is not of type float. 
- ValueError – If power is not positive. 
- TypeError – If momentum is not of type float. 
- ValueError – If momentum is a negative number. 
- TypeError – If length is not of type int. 
- ValueError – If length is a negative number. 
- TypeError – If rand_init is not of type bool. 
- RuntimeError – If n_fft is not less than length . 
- RuntimeError – If win_length is not less than n_fft . 
 
 - 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, 201, 6]) # 5 samples >>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"]) >>> transforms = [audio.GriffinLim(n_fft=400)] >>> 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 (1000,) float64 >>> >>> # Use the transform in eager mode >>> waveform = np.random.random([201, 6]) # 1 sample >>> output = audio.GriffinLim(n_fft=400)(waveform) >>> print(output.shape, output.dtype) (1000,) float64 - Tutorial Examples: