Skip to content

Instantly share code, notes, and snippets.

@leouieda
Created February 17, 2014 01:33
Show Gist options
  • Save leouieda/9043213 to your computer and use it in GitHub Desktop.
Save leouieda/9043213 to your computer and use it in GitHub Desktop.
Python code to plot a .wav file
# Load the required libraries:
# * scipy
# * numpy
# * matplotlib
from scipy.io import wavfile
from matplotlib import pyplot as plt
import numpy as np
# Load the data and calculate the time of each sample
samplerate, data = wavfile.read('Clapping.wav')
times = np.arange(len(data))/float(samplerate)
# Make the plot
# You can tweak the figsize (width, height) in inches
plt.figure(figsize=(30, 4))
plt.fill_between(times, data[:,0], data[:,1], color='k')
plt.xlim(times[0], times[-1])
plt.xlabel('time (s)')
plt.ylabel('amplitude')
# You can set the format by changing the extension
# like .pdf, .svg, .eps
plt.savefig('plot.png', dpi=100)
plt.show()
@andrewphillipdoss
Copy link

I'm getting:

OverflowError: Allocated too many blocks

@amrapali2801
Copy link

how do i represent single channel with two different colors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment