I am trying to figure out how to plot the audio visually of a wav file. In my code if I do a wavefile.readframe(-1)
I get the whole wav file plotted, the way my code works now is I just get a silver (one frame!) I'd like to show 24 frames of audio on each image plot from the wave file so I can animate it. Hopefully this is clear.
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import wave , sys , os , struct
waveFile = wave.open('mono.wav','r')
length = waveFile.getnframes()
for i in range(0,length):
print i # so we know where we are at.
waveData = waveFile.readframes(i)
fs = waveFile.getframerate()
signal = np.fromstring(waveData, 'Int16')
Time=np.linspace(0, len(signal)/fs, num=len(signal))
plt.axis('off')
plt.plot(Time,signal , 'w')
plt.savefig('signal' + str(i) + '.png' , facecolor='none', edgecolor='none', transparent=True, frameon=False)
plt.close