mindspore.dataset.audio.Spectrogram
- class mindspore.dataset.audio.Spectrogram(n_fft=400, win_length=None, hop_length=None, pad=0, window=WindowType.HANN, power=2.0, normalized=False, center=True, pad_mode=BorderType.REFLECT, onesided=True)[source]
Create a spectrogram from an audio signal.
- Parameters
n_fft (int, optional) – Size of FFT, creates n_fft // 2 + 1 bins. Default: 400.
win_length (int, optional) – Window size. Default: None, will use n_fft .
hop_length (int, optional) – Length of hop between STFT windows. Default: None, will use win_length // 2 .
pad (int, optional) – Two sided padding of signal. Default: 0.
window (WindowType, optional) – Window function that is applied/multiplied to each frame/window, can be WindowType.BARTLETT, WindowType.BLACKMAN, WindowType.HAMMING, WindowType.HANN or WindowType.KAISER. Currently, Kaiser window is not supported on macOS. Default: WindowType.HANN.
power (float, optional) – Exponent for the magnitude spectrogram, must be non negative, e.g., 1 for energy, 2 for power, etc. Default: 2.0.
normalized (bool, optional) – Whether to normalize by magnitude after stft. Default: False.
center (bool, optional) – Whether to pad waveform 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 to return half of results to avoid redundancy. Default: True.
- Raises
TypeError – If n_fft is not of type int.
ValueError – If n_fft is not a positive number.
TypeError – If win_length is not of type int.
ValueError – If win_length is not a positive number.
ValueError – If win_length is greater than n_fft .
TypeError – If hop_length is not of type int.
ValueError – If hop_length is not a positive number.
TypeError – If pad is not of type int.
ValueError – If pad is a negative number.
TypeError – If window is not of type
mindspore.dataset.audio.WindowType
.TypeError – If power is not of type float.
ValueError – If power is a negative number.
TypeError – If normalized is not of type bool.
TypeError – If center is not of type bool.
TypeError – If pad_mode is not of type
mindspore.dataset.audio.BorderType
.TypeError – If onesided is not of type bool.
RuntimeError – If input tensor is not in shape of <…, time>.
- Supported Platforms:
CPU
Examples
>>> import numpy as np >>> >>> waveform = np.random.random([5, 10, 20]) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"]) >>> transforms = [audio.Spectrogram()] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms, input_columns=["audio"])