提取梅爾倒頻譜系數(MFCCs) Python 實例


1. 安裝庫

 pip install python_speech_features

2. 代碼:

#!/usr/bin/env python
from python_speech_features import logfbank
from python_speech_features import mfcc
from python_speech_features import delta
import scipy.io.wavfile as wav
import matplotlib.pyplot as plt
import numpy as np


(rate, sig) = wav.read("example.wav")
# log energy 
fbank_feat = logfbank(sig,rate)
# mfcc
mfcc_feat = mfcc(sig, rate)
# delta
d_mfcc_feat = delta(mfcc_feat, 2)
# delta-delta
dd_mfcc_feat = delta(d_mfcc_feat,2)

x = np.linspace(1, 4096, 4096)
plt.figure('original signal')
plt.plot(x,sig[0:4096])
plt.show()

mfcc_colunm1 = mfcc_feat[:,0]
mfcc_row1 = mfcc_feat[0]
d_mfcc_feat_column1 = d_mfcc_feat[0]
dd_mfcc_feat_column1 = dd_mfcc_feat[0]

plt.figure()
plt.plot(mfcc_colunm1)
plt.show()

plt.figure()
plt.plot(mfcc_row1)
plt.show()

plt.figure()
plt.plot(d_mfcc_feat_column1)
plt.show()

plt.figure()
plt.plot(dd_mfcc_feat_column1)
plt.show()

f1

f2

f3

f4

f5

3.更多設置

這里用到4個函數分別求mfcc,delta和delta-delta系數。
(1) 函數 fbank
這個函數用來求經過梅爾濾波器組后的能量
定義如下:

def fbank(signal,samplerate=16000,winlen=0.025,winstep=0.01, nfilt=26,nfft=512,lowfreq=0,highfreq=None,preemph=0.97

有9個參數,默認值如下表,實際應用中需要根據實際的輸入決定輸入參數。
f1para

(2) 函數 mfcc
用來求MFCC
定義如下:

mfcc(signal,samplerate=16000,winlen=0.025,winstep=0.01,numcep=13,
                 nfilt=26,nfft=512,lowfreq=0,highfreq=None,preemph=0.97,
     ceplifter=22,appendEnergy=True)

有12個參數參數,默認參數值,實際應用中需要根據實際的輸入決定輸入參數。
f2para
(3) 函數 delta
求速度系數和加速度系數

4.如何求mfcc,delta 和 delta-delta系數

可以參考:
https://blog.csdn.net/qq_23869697/article/details/79280182


參考Github: https://github.com/jameslyons/python_speech_features


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM