-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_wave.py
More file actions
29 lines (26 loc) · 798 Bytes
/
plot_wave.py
File metadata and controls
29 lines (26 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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()