import math
import wave
import numpy as np
import pylab as pl
def ZeroCR(waveData,frameSize,overLap):
wlen = len(waveData)
step = frameSize - overLap
frameNum = math.ceil(wlen/step)
zcr = np.zeros((frameNum,1))
for i in range(frameNum):
curFrame = waveData[np.arange(i*step,min(i*step+frameSize,wlen))]
#To avoid DC bias, usually we need to perform mean subtraction on each frame
curFrame = curFrame - np.mean(curFrame) # zero-justified
zcr[i] = sum(curFrame[0:-1]*curFrame[1::]<=0)
# print(zcr[i])
return zcr
fw = wave.open(r'D:\Workspace\dejavu\preprocessing\tool\aim call wav file\guanji 4.wav','rb')
params = fw.getparams()
print(params)
nchannels, sampwidth, framerate, nframes = params[:4]
str_data = fw.readframes(nframes)
wave_data = np.fromstring(str_data, dtype=np.int16)
wave_data = wave_data*1.0/(max(abs(wave_
python wav文件过零率并plot出来
最新推荐文章于 2021-06-07 15:43:06 发布