Mel and MFCC Inversion

audio_samples.inverse estimates magnitude spectrograms and audio from mel spectrograms and MFCCs.

Inversion of mel spectrograms and MFCCs to spectrograms and audio.

audio_samples.inverse.mel_to_audio(M, *, sr, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant', power=2.0, n_iter=32, length=None, momentum=0.99, init='random', rng=0, fmin=0.0, fmax=None, htk=False, norm='slaney')

Estimates audio from a mel spectrogram: least squares, then fast Griffin-Lim.

Parameters:
  • M (array_like) – Mel spectrogram (n_mels, n_frames) or (channels, n_mels, n_frames).

  • sr (float) – Sample rate in Hz.

  • n_fft – STFT parameters.

  • hop_length – STFT parameters.

  • win_length – STFT parameters.

  • window – STFT parameters.

  • center – STFT parameters.

  • pad_mode – STFT parameters.

  • power (float) – Exponent that was applied to the magnitude. Default 2.

  • n_iter (int) – Griffin-Lim iterations. Default 32.

  • length (Optional[int]) – Exact output length.

  • momentum (float) – Fast Griffin-Lim momentum. Default 0.99.

  • init (Optional[str]) – "random" (default) or None (zero phase).

  • rng – Seed for init="random": an integer (default 0), None, or a NumPy generator, from which one seed is drawn.

  • fmin – The filterbank.

  • fmax – The filterbank.

  • htk – The filterbank.

  • norm – The filterbank.

Returns:

(n,), or (channels, n) for 3-D input, of M’s precision.

Return type:

numpy.ndarray

audio_samples.inverse.mel_to_stft(M, *, sr, n_fft=2048, power=2.0, fmin=0.0, fmax=None, htk=False, norm='slaney')

Estimates an STFT magnitude from a mel spectrogram by non-negative least squares.

Parameters:
  • M (array_like) – Mel spectrogram (n_mels, n_frames) or (channels, n_mels, n_frames).

  • sr (float) – Sample rate in Hz.

  • n_fft (int) – FFT size of the spectrogram to estimate. Default 2048.

  • power (float) – Exponent that was applied to the magnitude. Default 2.

  • fmin – The filterbank, as spectral.mel_filterbank.

  • fmax – The filterbank, as spectral.mel_filterbank.

  • htk – The filterbank, as spectral.mel_filterbank.

  • norm – The filterbank, as spectral.mel_filterbank.

Returns:

(1 + n_fft // 2, n_frames), with a leading channel axis for 3-D input, of M’s precision.

Return type:

numpy.ndarray

audio_samples.inverse.mfcc_to_audio(mfcc, *, sr, n_mels=128, dct_type=2, norm='ortho', ref=1.0, lifter=0.0, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant', power=2.0, n_iter=32, length=None, momentum=0.99, init='random', rng=0, fmin=0.0, fmax=None, htk=False, mel_norm='slaney')

Estimates audio from MFCCs: mfcc_to_mel(), then mel_to_audio().

n_mels, dct_type, norm, ref and lifter are as for mfcc_to_mel(). n_fft, hop_length, win_length, window, center, pad_mode, power, n_iter, length, momentum, init, rng, fmin, fmax, htk and mel_norm are as for mel_to_audio(), where mel_norm is its norm.

Parameters:
  • mfcc (array_like) – (n_mfcc, n_frames) or (channels, n_mfcc, n_frames).

  • sr (float) – Sample rate in Hz.

Returns:

(n,), or (channels, n) for 3-D input, of mfcc’s precision.

Return type:

numpy.ndarray

audio_samples.inverse.mfcc_to_mel(mfcc, *, n_mels=128, dct_type=2, norm='ortho', ref=1.0, lifter=0.0)

Recovers a mel power spectrogram from MFCCs.

Parameters:
  • mfcc (array_like) – (n_mfcc, n_frames) or (channels, n_mfcc, n_frames).

  • n_mels (int) – Mel bands to recover. Default 128.

  • dct_type (int) – 1, 2 or 3. Default 2.

  • norm (Optional[str]) – "ortho" or None. Default "ortho".

  • ref (float) – The reference of the decibel scale. Default 1.

  • lifter (float) – The liftering coefficient to undo. Default 0.

Returns:

(n_mels, n_frames), with a leading channel axis for 3-D input, of mfcc’s precision.

Return type:

numpy.ndarray