-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathacoustic_feature_extractor.py
112 lines (102 loc) · 2.26 KB
/
acoustic_feature_extractor.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
import numpy
class OjtPhoneme:
"""
OpenJTalkに含まれる音素群クラス
Attributes
----------
phoneme_list : Sequence[str]
音素のリスト
num_phoneme : int
音素リストの要素数
space_phoneme : str
読点に値する音素
"""
phoneme_list = (
"pau",
"A",
"E",
"I",
"N",
"O",
"U",
"a",
"b",
"by",
"ch",
"cl",
"d",
"dy",
"e",
"f",
"g",
"gw",
"gy",
"h",
"hy",
"i",
"j",
"k",
"kw",
"ky",
"m",
"my",
"n",
"ny",
"o",
"p",
"py",
"r",
"ry",
"s",
"sh",
"t",
"ts",
"ty",
"u",
"v",
"w",
"y",
"z",
)
num_phoneme = len(phoneme_list)
space_phoneme = "pau"
def __init__(
self,
phoneme: str,
start: float,
end: float,
):
# `sil`-to-`pau` (silent to space_phoneme) conversion
if "sil" in phoneme:
phoneme = self.space_phoneme
self.phoneme = phoneme
self.start = numpy.round(start, decimals=2)
self.end = numpy.round(end, decimals=2)
def __repr__(self):
return f"Phoneme(phoneme='{self.phoneme}', start={self.start}, end={self.end})"
def __eq__(self, o: object):
return isinstance(o, OjtPhoneme) and (
self.phoneme == o.phoneme and self.start == o.start and self.end == o.end
)
@property
def phoneme_id(self):
"""
phoneme_id (phoneme list内でのindex)を取得する
Returns
-------
id : int
phoneme_idを返す
"""
return self.phoneme_list.index(self.phoneme)
@property
def onehot(self):
"""
phoneme listの長さ分の0埋め配列のうち、phoneme id番目がTrue(1)の配列を返す
Returns
-------
onehot : numpu.ndarray
関数内で変更された配列を返す
"""
array = numpy.zeros(self.num_phoneme, dtype=bool)
array[self.phoneme_id] = True
return array