forked from MontrealCorpusTools/Montreal-Forced-Aligner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helper.py
101 lines (96 loc) · 1.89 KB
/
test_helper.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
import yaml
from montreal_forced_aligner.data import CtmInterval
from montreal_forced_aligner.helper import align_phones, mfa_open
def test_align_phones(basic_corpus_dir, basic_dict_path, temp_dir, eval_mapping_path):
with mfa_open(eval_mapping_path) as f:
mapping = yaml.safe_load(f)
reference_phoneset = set()
for v in mapping.values():
if isinstance(v, str):
reference_phoneset.add(v)
else:
reference_phoneset.update(v)
reference_sequence = [
"HH",
"IY0",
"HH",
"AE1",
"D",
"Y",
"ER0",
"G",
"R",
"IY1",
"S",
"IY0",
"S",
"UW1",
"T",
"IH0",
"N",
"D",
"ER1",
"T",
"IY0",
"W",
"AA1",
"SH",
"W",
"AO1",
"T",
"ER0",
"AO1",
"L",
"sil",
"Y",
"IH1",
"R",
]
reference_sequence = [CtmInterval(i, i + 1, x) for i, x in enumerate(reference_sequence)]
comparison_sequence = [
"ç",
"i",
"h",
"æ",
"d",
"j",
"ɚ",
"ɟ",
"ɹ",
"iː",
"s",
"i",
"s",
"ʉː",
"t",
"sil",
"ɪ",
"n",
"d",
"ɝ",
"ɾ",
"i",
"w",
"ɑː",
"ʃ",
"w",
"ɑː",
"ɾ",
"ɚ",
"ɑː",
"ɫ",
"sil",
"j",
"ɪ",
"ɹ",
]
comparison_sequence = [CtmInterval(i, i + 1, x) for i, x in enumerate(comparison_sequence)]
score, phone_errors = align_phones(
reference_sequence,
comparison_sequence,
silence_phone="sil",
custom_mapping=mapping,
debug=True,
)
assert score < 1
assert phone_errors < 1