Skip to content

Commit

Permalink
整理: apply_interrogative_upspeak() のテストを整理 (VOICEVOX#1429)
Browse files Browse the repository at this point in the history
* refactor: `create_synthesis_test_base()` から assert を分離

* refactor: `create_synthesis_test_base()` から apply upspeak を分離
  • Loading branch information
tarepan authored Jun 25, 2024
1 parent 5ee68be commit f2bba11
Showing 1 changed file with 86 additions and 69 deletions.
155 changes: 86 additions & 69 deletions test/unit/tts_pipeline/test_tts_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,16 +496,9 @@ def koreha_arimasuka_base_expected() -> list[AccentPhrase]:
]


def create_synthesis_test_base(
text: str, expected: list[AccentPhrase], enable_interrogative_upspeak: bool
) -> None:
"""音声合成時に疑問文モーラ処理を行っているかどうかを検証
(https://github.com/VOICEVOX/voicevox_engine/issues/272#issuecomment-1022610866)
"""
def create_synthesis_test_base(text: str) -> list[AccentPhrase]:
tts_engine = TTSEngine(core=MockCoreWrapper())
inputs = tts_engine.create_accent_phrases(text, StyleId(1))
outputs = apply_interrogative_upspeak(inputs, enable_interrogative_upspeak)
assert expected == outputs, f"case(text:{text})"
return tts_engine.create_accent_phrases(text, StyleId(1))


def test_create_accent_phrases() -> None:
Expand All @@ -522,6 +515,9 @@ def test_create_accent_phrases() -> None:

def test_upspeak_voiced_last_mora() -> None:
# voiced + "?" + flagON -> upspeak
# Inputs
inputs = create_synthesis_test_base(text="これはありますか?")
# Expects
expected = koreha_arimasuka_base_expected()
expected[-1].is_interrogative = True
expected[-1].moras += [
Expand All @@ -534,28 +530,31 @@ def test_upspeak_voiced_last_mora() -> None:
pitch=np.float32(expected[-1].moras[-1].pitch) + 0.3,
)
]
create_synthesis_test_base(
text="これはありますか?",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

# voiced + "?" + flagOFF -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="これはありますか?")
# Expects
expected = koreha_arimasuka_base_expected()
expected[-1].is_interrogative = True
create_synthesis_test_base(
text="これはありますか?",
expected=expected,
enable_interrogative_upspeak=False,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs

# voiced + "" + flagON -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="これはありますか")
# Expects
expected = koreha_arimasuka_base_expected()
create_synthesis_test_base(
text="これはありますか",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs


def test_upspeak_voiced_N_last_mora() -> None:
Expand All @@ -579,14 +578,19 @@ def nn_base_expected() -> list[AccentPhrase]:
]

# voiced + "" + flagON -> upspeak
# Inputs
inputs = create_synthesis_test_base(text="ん")
# Expects
expected = nn_base_expected()
create_synthesis_test_base(
text="ん",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

# voiced + "?" + flagON -> upspeak
# Inputs
inputs = create_synthesis_test_base(text="ん?")
# Expects
expected = nn_base_expected()
expected[-1].is_interrogative = True
expected[-1].moras += [
Expand All @@ -599,20 +603,21 @@ def nn_base_expected() -> list[AccentPhrase]:
pitch=np.float32(expected[-1].moras[-1].pitch) + 0.3,
)
]
create_synthesis_test_base(
text="ん?",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

# voiced + "?" + flagOFF -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="ん?")
# Expects
expected = nn_base_expected()
expected[-1].is_interrogative = True
create_synthesis_test_base(
text="ん?",
expected=expected,
enable_interrogative_upspeak=False,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs


def test_upspeak_unvoiced_last_mora() -> None:
Expand All @@ -636,30 +641,36 @@ def ltu_base_expected() -> list[AccentPhrase]:
]

# unvoiced + "" + flagON -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="っ")
# Expects
expected = ltu_base_expected()
create_synthesis_test_base(
text="っ",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

# unvoiced + "?" + flagON -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="っ?")
# Expects
expected = ltu_base_expected()
expected[-1].is_interrogative = True
create_synthesis_test_base(
text="っ?",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

# unvoiced + "?" + flagOFF -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="っ?")
# Expects
expected = ltu_base_expected()
expected[-1].is_interrogative = True
create_synthesis_test_base(
text="っ?",
expected=expected,
enable_interrogative_upspeak=False,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs


def test_upspeak_voiced_u_last_mora() -> None:
Expand All @@ -683,14 +694,19 @@ def su_base_expected() -> list[AccentPhrase]:
]

# voiced + "" + flagON -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="す")
# Expects
expected = su_base_expected()
create_synthesis_test_base(
text="す",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

# voiced + "?" + flagON -> upspeak
# Inputs
inputs = create_synthesis_test_base(text="す?")
# Expects
expected = su_base_expected()
expected[-1].is_interrogative = True
expected[-1].moras += [
Expand All @@ -703,17 +719,18 @@ def su_base_expected() -> list[AccentPhrase]:
pitch=expected[-1].moras[-1].pitch + 0.3,
)
]
create_synthesis_test_base(
text="す?",
expected=expected,
enable_interrogative_upspeak=True,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, True)
# Test
assert expected == outputs

# voiced + "?" + flagOFF -> non-upspeak
# Inputs
inputs = create_synthesis_test_base(text="す?")
# Expects
expected = su_base_expected()
expected[-1].is_interrogative = True
create_synthesis_test_base(
text="す?",
expected=expected,
enable_interrogative_upspeak=False,
)
# Outputs
outputs = apply_interrogative_upspeak(inputs, False)
# Test
assert expected == outputs

0 comments on commit f2bba11

Please sign in to comment.