Python绘制语谱图(修改版)
1 """Python绘制语谱图""" 2 3 # 导入相应的包 4 import matplotlib.pyplot as plt 5 import matplotlib.mlab as mlab 6 import numpy as np 7 import wave 8 import os 9 10 11 filepath = 'E:/普米/2/' # 添加路径 12 for root, dirs, files in os.walk(filepath): 13 for i in range(len(files)): 14 label = np.array(int(files[i].split('-')[0][3:])) 15 Time = np.array(int(files[i].split('-')[1][:1])) 16 17 f = wave.open(root + "/" + files[i], 'rb') # 调用wave模块中的open函数,打开语音文件。 18 params = f.getparams() # 得到语音参数 19 nchannels, sampwidth, framerate, nframes = params[:4] # nchannels:音频通道数,sampwidth:每个音频样本的字节数,framerate:采样率,nframes