pythonのwaveモジュールを用いて,waveファイルの情報抽出,読み込みを行う.なお,1行目のfrom __future__ import divisionは整数と整数を小数で出力するおまじない.
from __future__ import division import wave from pylab import * from numpy import * def printWaveInfo(wf): print "Number of channels: ", wf.getnchannels() print "Sampel width: ", wf.getsampwidth() print "Sampling frequency: ", wf.getframerate() print "Number of frames: ", wf.getnframes() print "Parameters: ", wf.getparams() def wavread(wf): buffer = wf.readframes(wf.getnframes()) data = frombuffer(buffer, dtype="int16") return data if __name__ == '__main__': wf = wave.open("./wave/guitar_A4.wav", "r") printWaveInfo(wf) x = arange(wf.getnframes()) y = wavread(wf) fs = wf.getframerate() x = x / fs plot(x, y) xlabel("Time [sec]", fontsize = 20, fontname = 'serif') ylabel("Amplitude", fontsize = 20, fontname = 'serif') xticks(fontsize = 16) yticks(fontsize = 16) show()