Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot MFCC in Python?

I'm just a beginner here in signal processing. Here is my code so far on extracting MFCC feature from an audio file (.WAV):

from python_speech_features import mfcc
import scipy.io.wavfile as wav

(rate,sig) = wav.read("AudioFile.wav")
mfcc_feat = mfcc(sig,rate)

print(mfcc_feat)

I just wanted to plot the mfcc features to know what it looks like.

like image 852
E. Alicaya Avatar asked Apr 19 '17 21:04

E. Alicaya


2 Answers

Initially I read the wav file using librosa and fed with inbuilt function

import librosa
audio_path='../.../../../combo.wav' #location
(xf, sr) = librosa.load(audio_path)    
mfccs = librosa.feature.mfcc(y=xf, sr=sr, n_mfcc=4)
librosa.display.specshow(mfccs, x_axis='time')
plt.colorbar()
plt.tight_layout()
plt.title('mfcc')
plt.show

I used librosa

like image 134
santhosh bandaru Avatar answered Sep 21 '22 08:09

santhosh bandaru


This will plot the MFCC as colors, which is a more popular way

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
fig, ax = plt.subplots()
mfcc_data= np.swapaxes(mfcc_data, 0 ,1)
cax = ax.imshow(mfcc_data, interpolation='nearest', cmap=cm.coolwarm, origin='lower')
ax.set_title('MFCC')

plt.show()
like image 36
itai ariel Avatar answered Sep 19 '22 08:09

itai ariel