使用MFCC

时间:2019-01-12 13:39:45

标签: python-3.x mfcc

我想知道,如何使用MFCC提取音频(x.wav)信号,特征提取?我知道使用MFCC提取音频功能的步骤。我想知道使用Django框架进行Python的精细编码

1 个答案:

答案 0 :(得分:0)

这是构建语音识别器的最重要步骤,因为将语音信号转换到频域后,我们必须将其转换为特征向量的可用形式。

import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
from python_speech_features import mfcc, logfbank

frequency_sampling, audio_signal = 
wavfile.read("/home/user/Downloads/OSR_us_000_0010_8k.wav")

audio_signal = audio_signal[:15000]

features_mfcc = mfcc(audio_signal, frequency_sampling)

print('\nMFCC:\nNumber of windows =', features_mfcc.shape[0])
print('Length of each feature =', features_mfcc.shape[1])



features_mfcc = features_mfcc.T
plt.matshow(features_mfcc)
plt.title('MFCC')

filterbank_features = logfbank(audio_signal, frequency_sampling)

print('\nFilter bank:\nNumber of windows =', filterbank_features.shape[0])
print('Length of each feature =', filterbank_features.shape[1])

filterbank_features = filterbank_features.T
plt.matshow(filterbank_features)
plt.title('Filter bank')
plt.show()

或者您可以使用此代码提取功能

import numpy as np
from sklearn import preprocessing
import python_speech_features as mfcc

def extract_features(audio,rate):
"""extract 20 dim mfcc features from an audio, performs CMS and combines 
delta to make it 40 dim feature vector"""    

        mfcc_feature = mfcc.mfcc(audio,rate, 0.025, 0.01,20,nfft = 1200, appendEnergy = True)    
        mfcc_feature = preprocessing.scale(mfcc_feature)
        delta = calculate_delta(mfcc_feature)
        combined = np.hstack((mfcc_feature,delta)) 
        return combined