目的是提取语音文件,并且画图
代码如下:
import wave
import numpy as np
from matplotlib import pyplot as plt
path = "E:/voice/1.wav"
f = wave.open(path, "rb") # 打开需要处理的内容
params = f.getparams()
nchannels, sampwidth, framerate, nframes = params[:4]
str_data = f.readframes(nframes)
wave_data = np.frombuffer(str_data, dtype=np.short)
print(len(wave_data))
print(wave_data)
print("len of wave_data:", len(wave_data))
f.close()
time = np.arange(0, nframes) * (1.0 / framerate)
print(len(time))
plt.plot(time, wave_data, "r-")
plt.xlabel('Time/s')
plt.ylabel('Ampltitude')
plt.title('waveform of voice')
plt.show()