该程序可以读取单个wav以进行MFCC功能提取,我需要可以读取多个wav并提供MFCC功能的程序

时间:2018-11-20 04:54:29

标签: python numpy

此程序可以读取单个wav以进行MFCC功能提取,我需要可以读取多个wav并提供MFCC功能的程序

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

(rate,sig) = wav.read("67_P.wav")
mfcc_feat = mfcc(sig,rate)
d_mfcc_feat = delta(mfcc_feat, 2)
fbank_feat = logfbank(sig,rate)

print(fbank_feat[1:3,:])

2 个答案:

答案 0 :(得分:0)

我不确定您想要什么,但我猜您需要类似的东西。

假设您已存储.wav文件的文件夹名称为“数据”,

from python_speech_features import mfcc
from python_speech_features import delta
from python_speech_features import logfbank
import scipy.io.wavfile as wav
import os

data_path = "data/"

for filename in os.listdir(data_path):
    (rate,sig) = wav.read(data_path + filename)
    mfcc_feat = mfcc(sig,rate)
    d_mfcc_feat = delta(mfcc_feat, 2)
    fbank_feat = logfbank(sig,rate)
    print filename
    print(fbank_feat[1:3,:]) 

这将一一读取数据文件夹中的所有.wav文件,并提取所需的功能。

答案 1 :(得分:0)

for filename in os.listdir(directoryName):
    if filename.endswith('.wav'): # only get MFCCs from .wavs
        # read in our file
        (rate,sig) = wav.read(directoryName + "/" +filename)
        # get mfcc
        mfcc_feat = mfcc(sig,rate)
        # get filterbank energies
        fbank_feat = logfbank(sig,rate)
        # create a file to save our results in
        
        outputFile = resultsDirectory + "/" + "op.csv"
        file = open(outputFile, 'a+') 
        
        numpy.savetxt(file, fbank_feat, delimiter=",") #save MFCCs as .csv
        file.close() 

此代码不会为每个 .wav 文件创建单独的 csv 文件。