Plot Mel Spectrogram

The code to plot mel spectrogram using librosa:

import librosa
import numpy as np
import librosa.display
import matplotlib.pyplot as plt

y, sr = librosa.load("xxx.wav")
S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128, fmax=8000)

plt.figure(figsize=(10, 4))
librosa.display.specshow(librosa.power_to_db(S, ref=np.max), y_axis='mel', fmax=8000, x_axis='time')
plt.colorbar(format='%+2.0f dB')
plt.title('Mel spectrogram')

The figure will be as follows:


Librosa Documentation