Created
February 17, 2014 01:33
-
-
Save leouieda/9043213 to your computer and use it in GitHub Desktop.
Python code to plot a .wav file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do i represent single channel with two different colors