import librosa
y,sr = librosa.load(file, sr=None)
#y is the amplitude
#sr is the sampling rate
fig, ax = plt.subplots(figsize = (16, 2))
fig.suptitle('Sound Waves', fontsize=16)
librosa.display.waveplot(y = y, color = "b")
y = librosa.feature.melspectrogram(y,n_mels=256)
#Calculation of Mel frequency coefficient
y = librosa.power_to_db(y).astype(np.float32)
# dB(Decibel, sound pressure)Conversion to
plt.figure(figsize=(12, 4))
librosa.display.specshow(y)
plt.title('mel power spectrogram')
plt.colorbar(format='%02.0f dB')
plt.tight_layout()
Recommended Posts