-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
executable file
·41 lines (32 loc) · 949 Bytes
/
project.py
File metadata and controls
executable file
·41 lines (32 loc) · 949 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
32
33
34
35
36
37
38
39
40
#!./python
import sys
import numpy as np
from common import *
def main():
if len(sys.argv) != 2:
sys.stderr.write('USAGE: project.py [input mfcc file]\n')
sys.exit(1)
makeX = xmaker('pca')
X = []
L = dict()
with oread(sys.argv[1]) as in_file:
for packet in MFCCReader(in_file):
if isinstance(packet, FramePacket):
label = packet.group_header.label
if not label in L:
L[label] = []
L[label].append(len(X))
X.append(makeX(packet))
X = np.vstack(X)
#idcs = xrange(X.shape[0])
#if True:
s = min(map(len, L.itervalues()))
for label, idcs in L.iteritems():
idcs = np.random.choice(idcs, s, replace=False)
print '"%s"' % label
for i in idcs:
print '%f %f %f' % (X[i,0],X[i,1],X[i,2])
print
print
if __name__ == '__main__':
main()