-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconvert.py
executable file
·51 lines (38 loc) · 1.44 KB
/
convert.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
#!/usr/bin/env python
import math
import numpy
import pickle
import sys
from stf import STF
from mfcc import MFCC
if __name__ == '__main__':
if len(sys.argv) < 6:
print 'Usage: %s [gmm_1] [gmm_2] [f0] [input] [output]' % sys.argv[0]
sys.exit()
gmm_file = open(sys.argv[1], 'rb')
gmm_first = pickle.load(gmm_file)[1]
gmm_file.close()
gmm_file = open(sys.argv[2], 'rb')
gmm_second = pickle.load(gmm_file)[0]
gmm_file.close()
f0_file = open(sys.argv[3], 'rb')
f0 = pickle.load(f0_file)
f0_file.close()
source = STF()
source.loadfile(sys.argv[4])
f0_data = []
for i in source.F0:
if i == 0:
f0_data.append(i)
else:
f0_data.append(math.e ** ((math.log(i) - math.log(f0[0][0])) * math.log(f0[1][1]) / math.log(f0[1][0]) + math.log(f0[0][1])))
source.F0 = numpy.array(f0_data)
mfcc = MFCC(source.SPEC.shape[1] * 2, source.frequency)
source_mfcc = numpy.array([mfcc.mfcc(source.SPEC[frame]) for frame in xrange(source.SPEC.shape[0])])
source_data = numpy.hstack([source_mfcc, mfcc.delta(source_mfcc)])
middle_mfcc = gmm_first.convert(source_data)
middle_data = numpy.hstack([middle_mfcc, mfcc.delta(middle_mfcc)])
output_mfcc = gmm_second.convert(middle_data)
output_spec = numpy.array([mfcc.imfcc(output_mfcc[frame]) for frame in xrange(output_mfcc.shape[0])])
source.SPEC = output_spec
source.savefile(sys.argv[5])