-
Notifications
You must be signed in to change notification settings - Fork 79
/
test_mgcep.py
226 lines (149 loc) · 5.42 KB
/
test_mgcep.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# coding: utf-8
import numpy as np
import pysptk
from warnings import warn
from nose.tools import raises
def windowed_dummy_data(N):
np.random.seed(98765)
return pysptk.hanning(N) * np.random.randn(N)
def test_mcep():
x = windowed_dummy_data(1024)
def __test(order, alpha):
mc = pysptk.mcep(x, order, alpha)
assert np.all(np.isfinite(mc))
for order in [15, 20, 25]:
for alpha in [0.0, 0.35, 0.41]:
yield __test, order, alpha
def test_mcep_invalid_args():
x = windowed_dummy_data(1024)
def __test_itype(itype=0):
pysptk.mcep(x, itype=itype)
yield raises(ValueError)(__test_itype), -1
yield raises(ValueError)(__test_itype), 5
def __test_eps(etype=0, eps=0.0):
pysptk.mcep(x, etype=etype, eps=eps)
yield raises(ValueError)(__test_eps), 0, -1.0
yield raises(ValueError)(__test_eps), -1
yield raises(ValueError)(__test_eps), -3
yield raises(ValueError)(__test_eps), 1, -1.0
yield raises(ValueError)(__test_eps), 2, 0.0
yield raises(ValueError)(__test_eps), 2, 1.0
def __test_min_det(min_det):
pysptk.mcep(x, min_det=min_det)
yield raises(ValueError)(__test_min_det), -1.0
@raises(RuntimeError)
def test_mcep_failure():
pysptk.mcep(np.ones(256), 40, 0.41)
def test_gcep():
x = windowed_dummy_data(1024)
def __test(order, gamma):
gc = pysptk.gcep(x, order, gamma)
assert np.all(np.isfinite(gc))
for order in [15, 20, 25]:
for gamma in [0.0, -0.25, -0.5]:
yield __test, order, gamma
def test_gcep_invalid_args():
x = windowed_dummy_data(1024)
def __test_gamma(gamma):
pysptk.gcep(x, gamma=gamma)
yield raises(ValueError)(__test_gamma), 0.1
yield raises(ValueError)(__test_gamma), -2.1
def __test_itype(itype=0):
pysptk.gcep(x, itype=itype)
yield raises(ValueError)(__test_itype), -1
yield raises(ValueError)(__test_itype), 5
def __test_eps(etype=0, eps=0.0):
pysptk.gcep(x, etype=etype, eps=eps)
yield raises(ValueError)(__test_eps), 0, -1.0
yield raises(ValueError)(__test_eps), -1
yield raises(ValueError)(__test_eps), -3
yield raises(ValueError)(__test_eps), 1, -1.0
yield raises(ValueError)(__test_eps), 2, -1.0
def __test_min_det(min_det):
pysptk.gcep(x, min_det=min_det)
yield raises(ValueError)(__test_min_det), -1.0
@raises(RuntimeError)
def test_gcep_failure():
pysptk.gcep(np.ones(256), 40, 0.0)
def test_mgcep():
x = windowed_dummy_data(1024)
def __test(order, alpha, gamma):
mgc = pysptk.mgcep(x, order, alpha, gamma)
assert np.all(np.isfinite(mgc))
for order in [15, 20, 25]:
for alpha in [0.0, 0.35, 0.41]:
for gamma in [0.0, -0.25, -0.5]:
yield __test, order, alpha, gamma
def test_mgcep_invalid_args():
x = windowed_dummy_data(1024)
def __test_gamma(gamma):
pysptk.mgcep(x, gamma=gamma)
yield raises(ValueError)(__test_gamma), 0.1
yield raises(ValueError)(__test_gamma), -2.1
def __test_itype(itype=0):
pysptk.mgcep(x, itype=itype)
yield raises(ValueError)(__test_itype), -1
yield raises(ValueError)(__test_itype), 5
def __test_eps(etype=0, eps=0.0):
pysptk.mgcep(x, etype=etype, eps=eps)
yield raises(ValueError)(__test_eps), 0, -1.0
yield raises(ValueError)(__test_eps), -1
yield raises(ValueError)(__test_eps), -3
yield raises(ValueError)(__test_eps), 1, -1.0
yield raises(ValueError)(__test_eps), 2, -1.0
def __test_min_det(min_det):
pysptk.mgcep(x, min_det=min_det)
yield raises(ValueError)(__test_min_det), -1.0
def __test_otype(otype=0):
pysptk.mgcep(x, otype=otype)
yield raises(ValueError)(__test_otype), -1
yield raises(ValueError)(__test_otype), 6
@raises(RuntimeError)
def test_mgcep_failure():
pysptk.mgcep(np.ones(256))
def test_uels():
x = windowed_dummy_data(1024)
def __test(order):
c = pysptk.uels(x, order)
assert np.all(np.isfinite(c))
for order in [15, 20, 25]:
yield __test, order
def test_uels_invalid_args():
x = windowed_dummy_data(1024)
def __test_itype(itype=0):
pysptk.uels(x, itype=itype)
yield raises(ValueError)(__test_itype), -1
yield raises(ValueError)(__test_itype), 5
def __test_eps(etype=0, eps=0.0):
pysptk.uels(x, etype=etype, eps=eps)
yield raises(ValueError)(__test_eps), 0, -1.0
yield raises(ValueError)(__test_eps), -1
yield raises(ValueError)(__test_eps), -3
yield raises(ValueError)(__test_eps), 1, -1.0
yield raises(ValueError)(__test_eps), 2, -1.0
@raises(RuntimeError)
def test_uels_failure():
pysptk.uels(np.ones(256), 40)
def test_fftcep():
x = windowed_dummy_data(1024)
logsp = np.log(np.abs(np.fft.rfft(x)) + 1.0e-6)
def __test(order):
c = pysptk.fftcep(logsp, order)
assert np.all(np.isfinite(c))
for order in [15, 20, 25]:
yield __test, order
def test_lpc():
x = windowed_dummy_data(1024)
def __test(order):
a = pysptk.lpc(x, order)
assert np.all(np.isfinite(a))
for order in [15, 20, 25]:
yield __test, order
def test_lpc_invalid_args():
x = windowed_dummy_data(1024)
def __test_min_det(min_det):
pysptk.lpc(x, min_det=min_det)
yield raises(ValueError)(__test_min_det), -1.0
@raises(RuntimeError)
def test_lpc_failure():
pysptk.lpc(np.zeros(256), 40)