# Visualize wav file by matplotlib # Load the required libraries: # * scipy # * numpy # * matplotlib from scipy.io import wavfile from matplotlib import pyplot as plt import sys import numpy as np if len(sys.argv) < 2: print("Plays a wave file.\n\nUsage: %s filename.wav" % sys.argv[0]) sys.exit(-1) # Load the data and calculate the time of each sample samplerate, data = wavfile.read(sys.argv[1]) 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, 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()