Skip to content

Commit 75210a0

Browse files
authored
refactor: モーラと音素長に関する docstring を明確化 (#1680)
1 parent db24169 commit 75210a0

File tree

7 files changed

+27
-54
lines changed

7 files changed

+27
-54
lines changed

test/e2e/__snapshots__/test_openapi/test_OpenAPIの形が変わっていないことを確認.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

voicevox_engine/app/routers/tts_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def accent_phrases(
212212
@router.post(
213213
"/mora_data",
214214
tags=["クエリ編集"],
215-
summary="アクセント句から音高・音素長を得る",
215+
summary="アクセント句から音素の長さと音高を得る",
216216
)
217217
def mora_data(
218218
accent_phrases: list[AccentPhrase],
@@ -226,7 +226,7 @@ def mora_data(
226226
@router.post(
227227
"/mora_length",
228228
tags=["クエリ編集"],
229-
summary="アクセント句から音素長を得る",
229+
summary="アクセント句から音素の長さを得る",
230230
)
231231
def mora_length(
232232
accent_phrases: list[AccentPhrase],

voicevox_engine/core/core_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ def predict_sing_consonant_length_forward(
786786
style_id: NDArray[np.int64],
787787
) -> NDArray[np.int64]:
788788
"""
789-
子音・母音列から音素ごとの長さを求める
789+
子音列の各子音の長さを求める
790790
791791
Parameters
792792
----------
@@ -804,7 +804,7 @@ def predict_sing_consonant_length_forward(
804804
Returns
805805
-------
806806
output : NDArray[np.int64]
807-
子音長
807+
子音の長さ
808808
"""
809809
if self.api_exists["predict_sing_consonant_length_forward"]:
810810
output = np.zeros((length,), dtype=np.int64)

voicevox_engine/tts_pipeline/kana_converter.py

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,9 @@ def _text_to_accent_phrase(phrase: str) -> AccentPhrase:
7070
"""
7171
単一アクセント句に相当するAquesTalk 風記法テキストからアクセント句オブジェクトを生成する。
7272
73-
longest matchによりモーラ化。入力長Nに対し計算量O(N^2)。
74-
75-
Parameters
76-
----------
77-
phrase : str
78-
単一アクセント句に相当するAquesTalk 風記法テキスト
79-
80-
Returns
81-
-------
82-
accent_phrase : AccentPhrase
83-
アクセント句
73+
音素長と音高は0で初期化する。
8474
"""
75+
# NOTE: longest matchによりモーラ化。入力長Nに対し計算量O(N^2)。
8576
# NOTE: ポーズと疑問形はこの関数内で処理しない
8677

8778
accent_index: int | None = None
@@ -135,17 +126,9 @@ def _text_to_accent_phrase(phrase: str) -> AccentPhrase:
135126

136127
def parse_kana(text: str) -> list[AccentPhrase]:
137128
"""
138-
AquesTalk 風記法テキストからアクセント句系列を生成
129+
AquesTalk 風記法テキストからアクセント句系列を生成する。
139130
140-
Parameters
141-
----------
142-
text : str
143-
AquesTalk 風記法テキスト
144-
145-
Returns
146-
-------
147-
parsed_results : list[AccentPhrase]
148-
アクセント句(音素・モーラ音高 0初期化)系列を生成
131+
音素長と音高は0で初期化する。
149132
"""
150133
parsed_results: list[AccentPhrase] = []
151134
phrase_base = 0
@@ -193,19 +176,7 @@ def parse_kana(text: str) -> list[AccentPhrase]:
193176

194177

195178
def create_kana(accent_phrases: list[AccentPhrase]) -> str:
196-
"""
197-
アクセント句系列からAquesTalk 風記法テキストを生成
198-
199-
Parameters
200-
----------
201-
accent_phrases : list[AccentPhrase]
202-
アクセント句系列
203-
204-
Returns
205-
-------
206-
text : str
207-
AquesTalk 風記法テキスト
208-
"""
179+
"""アクセント句系列からAquesTalk 風記法テキストを生成する。"""
209180
text = ""
210181
# アクセント句を先頭から逐次パースし、`text`末尾にAquesTalk 風記法の文字を都度追加(ループ)
211182
for i, phrase in enumerate(accent_phrases):

voicevox_engine/tts_pipeline/model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ class Mora(BaseModel):
2323
default=None, description="子音の音素"
2424
)
2525
consonant_length: float | SkipJsonSchema[None] = Field(
26-
default=None, description="子音の音長"
26+
default=None, description="子音の長さ"
2727
)
2828
vowel: str = Field(description="母音の音素")
29-
vowel_length: float = Field(description="母音の音長")
30-
pitch: float = Field(
31-
description="音高"
32-
) # デフォルト値をつけるとts側のOpenAPIで生成されたコードの型がOptionalになる
29+
vowel_length: float = Field(description="母音の長さ")
30+
pitch: float = Field(description="音高")
3331

3432
def __hash__(self) -> int:
3533
"""内容に対して一意なハッシュ値を返す。"""

voicevox_engine/tts_pipeline/text_analyzer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ def mora_to_text(mora_phonemes: str) -> str:
353353

354354

355355
def _mora_labels_to_moras(mora_labels: list[MoraLabel]) -> list[Mora]:
356-
"""MoraLabel系列をMora系列へキャストする。音素長と音高は 0 初期化"""
356+
"""
357+
MoraLabel系列をMora系列へキャストする。
358+
359+
音素長と音高は0で初期化する。
360+
"""
357361
return [
358362
Mora(
359363
text=mora_to_text("".join([label.phoneme for label in mora.labels])),

voicevox_engine/tts_pipeline/tts_engine.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _create_one_hot(accent_phrase: AccentPhrase, index: int) -> NDArray[np.int64
7070

7171

7272
def _generate_silence_mora(length: float) -> Mora:
73-
"""無音モーラの生成"""
73+
"""音の長さを指定して無音モーラを生成する。"""
7474
return Mora(text=" ", vowel="sil", vowel_length=length, pitch=0.0)
7575

7676

@@ -246,7 +246,7 @@ def supported_devices(self) -> DeviceSupport | None:
246246
def update_length(
247247
self, accent_phrases: list[AccentPhrase], style_id: StyleId
248248
) -> list[AccentPhrase]:
249-
"""アクセント句系列に含まれるモーラの音素長属性をスタイルに合わせて更新する"""
249+
"""アクセント句系列に含まれる音素の長さをスタイルに合わせて更新する。"""
250250
# モーラ系列を抽出する
251251
moras = to_flatten_moras(accent_phrases)
252252

@@ -256,10 +256,10 @@ def update_length(
256256
# 音素クラスから音素IDスカラへ表現を変換する
257257
phoneme_ids = np.array([p.id for p in phonemes], dtype=np.int64)
258258

259-
# コアを用いて音素長を生成する
259+
# 音素ごとの長さを生成する
260260
phoneme_lengths = self._core.safe_yukarin_s_forward(phoneme_ids, style_id)
261261

262-
# 生成結果でモーラ内の音素長属性を置換する
262+
# 生成された音素長でモーラの音素長を更新する
263263
vowel_indexes = [i for i, p in enumerate(phonemes) if p.is_mora_tail()]
264264
for i, mora in enumerate(moras):
265265
if mora.consonant is None:
@@ -273,7 +273,7 @@ def update_length(
273273
def update_pitch(
274274
self, accent_phrases: list[AccentPhrase], style_id: StyleId
275275
) -> list[AccentPhrase]:
276-
"""アクセント句系列に含まれるモーラの音高属性をスタイルに合わせて更新する"""
276+
"""アクセント句系列に含まれるモーラの音高をスタイルに合わせて更新する。"""
277277
# 後続のnumpy.concatenateが空リストだとエラーになるので別処理
278278
if len(accent_phrases) == 0:
279279
return []
@@ -340,7 +340,7 @@ def update_pitch(
340340
def update_length_and_pitch(
341341
self, accent_phrases: list[AccentPhrase], style_id: StyleId
342342
) -> list[AccentPhrase]:
343-
"""アクセント句系列の音素長・モーラ音高をスタイルIDに基づいて更新する"""
343+
"""アクセント句系列に含まれる音素の長さとモーラの音高をスタイルに合わせて更新する。"""
344344
accent_phrases = self.update_length(accent_phrases, style_id)
345345
accent_phrases = self.update_pitch(accent_phrases, style_id)
346346
return accent_phrases

0 commit comments

Comments
 (0)