Skip to content

Commit

Permalink
整理: tts_engine モジュール内のプライベートな関数をリネーム、テストを整理 (#1435)
Browse files Browse the repository at this point in the history
* refactor: `to_flatten_moras()` の docstring を簡略化

* refactor: `to_flatten_phonemes()` をプライベートへリネーム、テストを明確化

* refactor: `generate_silence_mora()` をプライベート化

* refactor: `_apply_interrogative_upspeak()` をプライベート化

* refactor: `apply_prepost_silence()` をプライベート化、テストを簡略化

* refactor: `apply_speed_scale()` をプライベート化、テストを簡略化

* refactor: `apply_pitch_scale()` をプライベート化、テストを整理

* refactor: `apply_intonation_scale()` をプライベート化、テストをフォーマット

* refactor: `apply_pause_length()` と `apply_pause_length_scale()` をプライベート化

* refactor: `apply_volume_scale()` をプライベート化、テストをフォーマット

* refactor: `apply_output_sampling_rate()` をプライベート化、テストをフォーマット

* refactor: `apply_output_stereo()` をプライベート化、テストをフォーマット

* refactor: `query_to_decoder_feature()` をプライベート化、テストを簡略化

* refactor: `count_frame_per_unit()` をプライベート化、テストを簡略化

* refactor: `calc_phoneme_lengths()` をプライベート化

* refactor: `notes_to_keys_and_phonemes()` をプライベート化

* refactor: `frame_query_to_sf_decoder_feature()` をプライベート化

* refactor: 定数 `T` を関数化

* fix: type

* fix: lint
  • Loading branch information
tarepan authored Jun 27, 2024
1 parent 09df944 commit 94c261c
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 145 deletions.
48 changes: 24 additions & 24 deletions test/unit/tts_pipeline/test_tts_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@
from voicevox_engine.tts_pipeline.text_analyzer import text_to_accent_phrases
from voicevox_engine.tts_pipeline.tts_engine import (
TTSEngine,
apply_interrogative_upspeak,
_apply_interrogative_upspeak,
_to_flatten_phonemes,
to_flatten_moras,
to_flatten_phonemes,
)

from .test_text_analyzer import stub_unknown_features_koxx
from .tts_utils import gen_mora
from .tts_utils import gen_mora, sec


def test_to_flatten_phonemes() -> None:
"""Test `to_flatten_phonemes`."""
"""Test `_to_flatten_phonemes()`."""
# Inputs
moras = [
gen_mora(" ", None, None, "sil", 2 * 0.01067, 0.0),
gen_mora("ヒ", "h", 2 * 0.01067, "i", 4 * 0.01067, 5.0),
gen_mora(" ", None, None, "sil", 6 * 0.01067, 0.0),
gen_mora(" ", None, None, "sil", sec(2), 0.0),
gen_mora("ヒ", "h", sec(2), "i", sec(4), 5.0),
gen_mora(" ", None, None, "sil", sec(6), 0.0),
]

# Expects
true_phonemes = ["pau", "h", "i", "pau"]

true_phoneme_strs = ["pau", "h", "i", "pau"]
# Outputs
phonemes = list(map(lambda p: p._phoneme, to_flatten_phonemes(moras)))
phonemes = _to_flatten_phonemes(moras)
phoneme_strs = list(map(lambda p: p._phoneme, phonemes))

assert true_phonemes == phonemes
# Test
assert true_phoneme_strs == phoneme_strs


def _gen_hello_hiho_accent_phrases() -> list[AccentPhrase]:
Expand Down Expand Up @@ -458,7 +458,7 @@ def test_upspeak_voiced_last_mora() -> None:
)
]
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand All @@ -469,7 +469,7 @@ def test_upspeak_voiced_last_mora() -> None:
expected = koreha_arimasuka_base_expected()
expected[-1].is_interrogative = True
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
outputs = _apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs

Expand All @@ -479,7 +479,7 @@ def test_upspeak_voiced_last_mora() -> None:
# Expects
expected = koreha_arimasuka_base_expected()
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand Down Expand Up @@ -510,7 +510,7 @@ def nn_base_expected() -> list[AccentPhrase]:
# Expects
expected = nn_base_expected()
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand All @@ -531,7 +531,7 @@ def nn_base_expected() -> list[AccentPhrase]:
)
]
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand All @@ -542,7 +542,7 @@ def nn_base_expected() -> list[AccentPhrase]:
expected = nn_base_expected()
expected[-1].is_interrogative = True
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
outputs = _apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs

Expand Down Expand Up @@ -573,7 +573,7 @@ def ltu_base_expected() -> list[AccentPhrase]:
# Expects
expected = ltu_base_expected()
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand All @@ -584,7 +584,7 @@ def ltu_base_expected() -> list[AccentPhrase]:
expected = ltu_base_expected()
expected[-1].is_interrogative = True
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand All @@ -595,7 +595,7 @@ def ltu_base_expected() -> list[AccentPhrase]:
expected = ltu_base_expected()
expected[-1].is_interrogative = True
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
outputs = _apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs

Expand Down Expand Up @@ -626,7 +626,7 @@ def su_base_expected() -> list[AccentPhrase]:
# Expects
expected = su_base_expected()
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand All @@ -647,7 +647,7 @@ def su_base_expected() -> list[AccentPhrase]:
)
]
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
outputs = _apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

Expand All @@ -658,6 +658,6 @@ def su_base_expected() -> list[AccentPhrase]:
expected = su_base_expected()
expected[-1].is_interrogative = True
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
outputs = _apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs
Loading

0 comments on commit 94c261c

Please sign in to comment.