-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaveform.py
More file actions
30 lines (26 loc) · 996 Bytes
/
waveform.py
File metadata and controls
30 lines (26 loc) · 996 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
30
import matplotlib.pyplot as plt
import numpy as np
import wave
import sys
import contextlib
# Give filename without extension
def generatePng(filename):
with contextlib.closing(wave.open(filename + '.wav', 'r')) as spf:
signal = spf.readframes(-1)
signal = np.fromstring(signal, 'Int16')
fs = spf.getframerate()
if spf.getnchannels() == 2:
print('Just mono files')
# sys.exit(0) # Running this in pyhcharm
# In seconds (Algorithm taken from online)
# Timing is extended.... test with more
Time = np.linspace(0, len(signal)/fs, num=len(signal))
plt.gcf().clear()
plt.figure(1)
plt.title(filename)
plt.tick_params(axis='y', which='both', left='off',labelleft='off', bottom='off', labelbottom='off')
plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
plt.axis('off')
plt.plot(Time,signal)
plt.tight_layout(pad=0)
plt.savefig(filename + '.png', pad_inches=0)