-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_phn.py
37 lines (33 loc) · 930 Bytes
/
process_phn.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
from typing import List, Tuple
# Dict converting TIMIT monophthong codes to IPA
# Reference: https://en.wikipedia.org/wiki/ARPABET
phn_vowel_ipa = {
"iy": "i",
"ih": "ɪ",
"eh": "ɛ",
"ae": "æ",
"aa": "ɑ",
"ah": "ʌ",
"ao": "ɔ",
"uh": "ʊ",
"uw": "u",
"ux": "ʉ",
"er": "ɝ",
"ax": "ə",
"ix": "ɨ",
"axr": "ɚ"
}
ipa_class_index = {key: i for i, key in enumerate(phn_vowel_ipa.values())}
def extract_monophthong_times(phn_path: str) -> List[Tuple[str, int, int]]:
out = []
with open(phn_path) as phn:
lines = phn.readlines()
for line in lines:
vals = line.split()
if vals[-1] in phn_vowel_ipa.keys():
new = [phn_vowel_ipa[vals[-1]]]
new.extend([int(vals[0]), int(vals[1])])
out.append(tuple(new))
return out
def get_num_monophthongs():
return len(phn_vowel_ipa)