-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_spectrogram.py
75 lines (55 loc) · 1.73 KB
/
make_spectrogram.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
# Check version
# Python 2.7.12 on win32 (Windows version)
IN_DIR = 'wav'
OUT_DIR = 'spectrogram'
if not os.path.exists(OUT_DIR):
os.mkdir(OUT_DIR)
from getspecgram import GetSpecgram
# specify number of filter banks as num_banks
GetSpecgram1= GetSpecgram(num_banks=64)
from conv2image2 import *
# number letter
import re
pattern=r'([0-9]+)'
loop=0
xspec = np.array( [] )
mode=1 # 0: max, min search 1: image write out
# scan and copy to OUT_DIR via head letter
for f in (os.listdir(IN_DIR)):
# check head letter
if f[0:1].isdigit() :
source = os.path.join(IN_DIR, f)
bname, ext = os.path.splitext( f )
# reject some input wav file
# pick up number, second item
# reject area is
# xxx40 <= xxx260 >=
a=re.findall(pattern,bname)
b=map(int,a)
#print (b)
# Whole ?
# Only xxx40 select
if b[1] > 40 :
continue
#elif b[1] >= 260:
# continue
f2= bname + '.' + 'png'
dest = os.path.join(OUT_DIR, f2)
#print ( source, dest )
if mode == 1:
spec=GetSpecgram1.get(source)
conv2image2(spec, dest, Fshow=False)
else:
spec=GetSpecgram1.get(source)
print ("filename, max,min",f, np.max(spec), np.min(spec) )
xspec=np.append(xspec, np.max(spec))
xspec=np.append(xspec, np.min(spec))
loop+=1
# if loop >= 2850:
# break
if mode == 1:
pass
else:
print ("loop, max,min", loop, np.max(xspec), np.min(xspec) )
### ('loop, max,min', 2850, 44.381695791912605, -138.56194539669562)