import wave
import numpy as np
import matplotlib.pyplot as plt
def get_audio_data(file_path):
f = wave.open(file_path, "rb")
params = f.getparams()
nchannels, sampwidth, framerate, nframes = params[:4]
str_data = f.readframes(nframes)
f.close()
audio_data = np.frombuffer(str_data, dtype=np.short)
audio_data = audio_data*1.0/(max(abs(audio_data)))
time = np.arange(0, nframes) * (1.0 / framerate)
return time, audio_data
def cut_signal(sig, nw=512, inc=128):
signal_length = len(sig) # 信号总长度
if signal_length <= nw: # 如果信号长度小于一帧的长度,则帧数定义为1
nf = 1 # nf表示帧数量
else:
nf = int(np.ceil((1.0 * signal_length - nw + inc) / inc)) # 处理后,所有帧的数量,不要最后一帧
pad_length = int
python对语音进行分帧,过零率、短时能量、FTT计算,端点监测
最新推荐文章于 2022-11-02 10:00:00 发布