-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotWav.py
48 lines (38 loc) · 1.5 KB
/
PlotWav.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# PlotWav - Plots the wave amplitude (time domain) against the MFCCs.
#
# Usage:
# python PlotWav.py <wav-file-path>
from MfccWavLoader import MfccWavLoader
import matplotlib.pyplot as plt
import numpy
import sys
if len(sys.argv) < 2:
print('First param must be a wav file path')
exit(1)
mfccLoader = MfccWavLoader(sys.argv[1], produceFirstDerivative=True, produceSecondDerivative=True)
mfccWav = mfccLoader.generateMfccs().send(None)
plt.subplot(611)
plt.title('Amplitude by time')
plt.margins(0)
plt.plot(mfccWav.samples)
plt.subplot(612)
plt.title('1st derivative amplitude by time')
plt.margins(0)
plt.plot(mfccWav.sampleDeltas)
plt.subplot(613)
plt.title('2nd derivative amplitude by time')
plt.margins(0)
plt.plot(mfccWav.sampleDeltaDeltas)
plt.subplot(614)
plt.title('MFCC by time')
mfccTwoDMatrix = mfccWav.fullFeatureArray[:,:,0].T # Transpose to get MFCCs on Y axis
plt.matshow(mfccTwoDMatrix, fignum=False, cmap='bwr', aspect='auto') # cmap='coolwarm' pretty good too
plt.subplot(615)
plt.title('1st derivative MFCC by time')
firstDerivTwoDMatrix = mfccWav.fullFeatureArray[:,:,1].T # Transpose to get MFCCs on Y axis
plt.matshow(firstDerivTwoDMatrix, fignum=False, cmap='bwr', aspect='auto') # cmap='coolwarm' pretty good too
plt.subplot(616)
plt.title('2nd derivative MFCC by time')
secondDerivTwoDMatrix = mfccWav.fullFeatureArray[:,:,2].T # Transpose to get MFCCs on Y axis
plt.matshow(secondDerivTwoDMatrix, fignum=False, cmap='bwr', aspect='auto') # cmap='coolwarm' pretty good too
plt.show()