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()
如果本文对您有所帮助,请支持下本站哦!!!^_^