-
Notifications
You must be signed in to change notification settings - Fork 34
/
test_mel_bank_options.py
executable file
·110 lines (75 loc) · 2.26 KB
/
test_mel_bank_options.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
#!/usr/bin/env python3
#
# Copyright (c) 2021 Xiaomi Corporation (authors: Fangjun Kuang)
import pickle
import kaldifeat
def test_default():
opts = kaldifeat.MelBanksOptions()
print(opts)
assert opts.num_bins == 25
assert opts.low_freq == 20
assert opts.high_freq == 0
assert opts.vtln_low == 100
assert opts.vtln_high == -500
assert opts.debug_mel is False
assert opts.htk_mode is False
def test_set_get():
opts = kaldifeat.MelBanksOptions(num_bins=100)
assert opts.num_bins == 100
opts.num_bins = 200
assert opts.num_bins == 200
opts.low_freq = 22
assert opts.low_freq == 22
opts.high_freq = 1
assert opts.high_freq == 1
opts.vtln_low = 101
assert opts.vtln_low == 101
opts.vtln_high = -100
assert opts.vtln_high == -100
opts.debug_mel = True
assert opts.debug_mel is True
opts.htk_mode = True
assert opts.htk_mode is True
def test_from_empty_dict():
opts = kaldifeat.MelBanksOptions.from_dict({})
opts2 = kaldifeat.MelBanksOptions()
assert str(opts) == str(opts2)
def test_from_dict_partial():
d = {"num_bins": 10, "debug_mel": True}
opts = kaldifeat.MelBanksOptions.from_dict(d)
opts2 = kaldifeat.MelBanksOptions()
assert str(opts) != str(opts2)
opts2.num_bins = 10
assert str(opts) != str(opts2)
opts2.debug_mel = True
assert str(opts) == str(opts2)
opts2.debug_mel = False
assert str(opts) != str(opts2)
def test_from_dict_full_and_as_dict():
opts = kaldifeat.MelBanksOptions()
opts.num_bins = 80
opts.vtln_high = 2
d = opts.as_dict()
for key, value in d.items():
assert value == getattr(opts, key)
opts2 = kaldifeat.MelBanksOptions.from_dict(d)
assert str(opts2) == str(opts)
d["htk_mode"] = True
opts3 = kaldifeat.MelBanksOptions.from_dict(d)
assert opts3.htk_mode is True
def test_pickle():
opts = kaldifeat.MelBanksOptions()
opts.num_bins = 100
opts.low_freq = 22
data = pickle.dumps(opts)
opts2 = pickle.loads(data)
assert str(opts) == str(opts2)
def main():
test_default()
test_set_get()
test_from_empty_dict()
test_from_dict_partial()
test_from_dict_full_and_as_dict()
test_pickle()
if __name__ == "__main__":
main()