forked from swharden/Spectrogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsffDemo.py
More file actions
31 lines (24 loc) · 740 Bytes
/
sffDemo.py
File metadata and controls
31 lines (24 loc) · 740 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
31
import sffLib
import os
import matplotlib.pyplot as plt
import numpy as np
np.set_printoptions(precision=3)
def plotSFF(filePath, show=False):
# access SFF details and data like this
sf = sffLib.SpectrogramFile(filePath)
print(sf.getDescription())
print(sf.values)
# rotate values for display as a pseudocolor mesh
rotatedValues = np.rot90(sf.values, 1)[::-1]
# plot the spectrogram
plt.figure()
plt.pcolormesh(rotatedValues)
plt.colorbar()
plt.title(f"{os.path.basename(filePath)} Spectrogram")
plt.savefig(os.path.basename(filePath)+".png")
if show:
plt.show()
plt.close()
if __name__ == "__main__":
plotSFF("../hal.sff", True)
plotSFF("../halMel.sff", True)