显示wav文件的级别

时间:2015-05-24 16:08:50

标签: python wav levels

我想阅读wav文件并显示它的级别。我知道如何在python中使用wave模块读取帧,但不知道如何处理它。任何想法都会有所帮助 感谢

import wave
import struct
import matplotlib.pyplot as plt

wrd = wave.open("albatros.wav")

display = []
display2=[]
x = []

(nchannels, sampwidth, framerate, nframes, comptype, compname) = wrd.getparams()

for i in range(0,int(nframes)):
    x.append(i)
    samplestring = wrd.readframes(1)
    display.append(struct.unpack('h',samplestring[:2])[0]);
    if(nchannels == 2):
        display2.append(struct.unpack('h',samplestring[2:4])[0])

plt.figure(1)
plt.plot(x,display, 'k')

if (nchannels == 2):
    plt.figure(2)
    plt.plot(x,display2, 'k')

plt.show()

print (len(display))

wrd.close()

0 个答案:

没有答案