使用wave 读取WAV 绘制声波图
2019-08-30 python 2300
import wave as we import numpy as np import matplotlib.pyplot as plt def wavread(path): wavfile = we.open(path, "rb") params = wavfile.getparams() framesra, frameswav = params[2], params[3] datawav = wavfile.readframes(frameswav) wavfile.close() datause = np.frombuffer(datawav, dtype=np.short) #print(datause) datause.shape = -1, 2 datause = datause.T time = np.arange(0, frameswav) * (1.0 / framesra) return datause, time def main(): #path = input("The Path is:") path = r"./test.wav" wavdata, wavtime = wavread(path) plt.title("Night.wav's Frames") plt.subplot(211) plt.plot(wavtime, wavdata[0], color='green') # plt.subplot(212) # plt.plot(wavtime, wavdata[1]) plt.show() main()
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论