deffbank(signal,samplerate=16000,winlen=0.025,winstep=0.01,
nfilt=26,nfft=512,lowfreq=0,highfreq=None,preemph=0.97,
winfunc=lambda x:numpy.ones((x,))):"""计算一语音信号的梅尔滤波器能量特征
signal: 待计算特征的语音信号, N*1 数组;
samplerate: 信号采样率;
winlen: 以秒为单位的分析窗窗长,默认为25ms;
winstep: 以秒为单位的连续窗之间步长,默认10ms;
nfilt: 滤波器组的滤波器个数,默认26;
nfft: FFT的长度,默认512;
lowfreq: 以赫兹为单位的梅尔滤波器最低频率,默认为0;
highfreq:以赫兹为单位的梅尔滤波器最低频率,默认为采样率的一半;
preemph: 预加重滤波器系数,默认0.97;
winfunc: 每一帧的分析窗函数,如:汉明窗;
返回两个值:第一个是帧数✖滤波器个数的包含特征的numpy数组,每一行是一个特征向量,第二个是每帧信号的能量。
"""
highfreq= highfreq or samplerate/2
signal = sigproc.preemphasis(signal,preemph)
frames = sigproc.framesig(signal, winlen*samplerate, winstep*samplerate, winfunc)
pspec = sigproc.powspec(frames,nfft)
energy = numpy.sum(pspec,1)# this stores the total energy in each frame
energy = numpy.where(energy ==0,numpy.finfo(float).eps,energy)# if energy is zero, we get problems with log
fb = get_filterbanks(nfilt,nfft,samplerate,lowfreq,highfreq)
feat = numpy.dot(pspec,fb.T)# compute the filterbank energies
feat = numpy.where(feat ==0,numpy.finfo(float).eps,feat)# if feat is zero, we get problems with logreturn feat,energy