Skip to content

Commit

Permalink
疑問文の仕様変更反映 #272
Browse files Browse the repository at this point in the history
- AccentPhraseにis_interrogativeをもたせる
- 疑問符Mora追加を調整前ではなく調整後に行うようにした #272 (comment)

refs #272
  • Loading branch information
qwerty2501 committed Jan 6, 2022
1 parent 16b1d5a commit 7d4eb98
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 99 deletions.
167 changes: 119 additions & 48 deletions test/test_synthesis_engine_base.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,93 @@
from typing import List
from typing import List, Union
from unittest import TestCase
from unittest.mock import Mock

import numpy

from voicevox_engine.dev.synthesis_engine.mock import MockSynthesisEngine
from voicevox_engine.model import AccentPhrase, Mora
from voicevox_engine.synthesis_engine import SynthesisEngine


def yukarin_s_mock(length: int, phoneme_list: numpy.ndarray, speaker_id: numpy.ndarray):
result = []
# mockとしての適当な処理、特に意味はない
for i in range(length):
result.append(round(float(phoneme_list[i] * 0.0625 + speaker_id), 2))
return numpy.array(result)


def yukarin_sa_mock(
length: int,
vowel_phoneme_list: numpy.ndarray,
consonant_phoneme_list: numpy.ndarray,
start_accent_list: numpy.ndarray,
end_accent_list: numpy.ndarray,
start_accent_phrase_list: numpy.ndarray,
end_accent_phrase_list: numpy.ndarray,
speaker_id: numpy.ndarray,
):
result = []
# mockとしての適当な処理、特に意味はない
for i in range(length):
result.append(
round(
float(
(
vowel_phoneme_list[0][i]
+ consonant_phoneme_list[0][i]
+ start_accent_list[0][i]
+ end_accent_list[0][i]
+ start_accent_phrase_list[0][i]
+ end_accent_phrase_list[0][i]
)
* 0.0625
+ speaker_id
),
2,
)
)
return numpy.array(result)[numpy.newaxis]


def decode_mock(
length: int,
phoneme_size: int,
f0: numpy.ndarray,
phoneme: numpy.ndarray,
speaker_id: Union[numpy.ndarray, int],
):
result = []
# mockとしての適当な処理、特に意味はない
for i in range(length):
# decode forwardはデータサイズがlengthの256倍になるのでとりあえず256回データをresultに入れる
for _ in range(256):
result.append(
float(
f0[i][0] * (numpy.where(phoneme[i] == 1)[0] / phoneme_size)
+ speaker_id
)
)
return numpy.array(result)


class TestSynthesisEngineBase(TestCase):
def setUp(self):
super().setUp()
self.synthesis_engine = MockSynthesisEngine(speakers="")
self.synthesis_engine = SynthesisEngine(
yukarin_s_forwarder=Mock(side_effect=yukarin_s_mock),
yukarin_sa_forwarder=Mock(side_effect=yukarin_sa_mock),
decode_forwarder=Mock(side_effect=decode_mock),
speakers="",
)

def create_accent_phrases_test_base(
self, text: str, expected: List[AccentPhrase], enable_interrogative: bool
):
actual = self.synthesis_engine.create_accent_phrases(
text, 1, enable_interrogative
)
print(expected)
print(actual)
self.assertEqual(
expected,
actual,
Expand All @@ -34,30 +106,31 @@ def koreha_arimasuka_base_expected():
Mora(
text="コ",
consonant="k",
consonant_length=0,
consonant_length=2.44,
vowel="o",
vowel_length=0,
pitch=0,
vowel_length=2.88,
pitch=4.38,
),
Mora(
text="レ",
consonant="r",
consonant_length=0,
consonant_length=3.06,
vowel="e",
vowel_length=0,
pitch=0,
vowel_length=1.88,
pitch=4.0,
),
Mora(
text="ワ",
consonant="w",
consonant_length=0,
consonant_length=3.62,
vowel="a",
vowel_length=0,
pitch=0,
vowel_length=1.44,
pitch=4.19,
),
],
accent=3,
pause_mora=None,
is_interrogative=False,
),
AccentPhrase(
moras=[
Expand All @@ -66,56 +139,58 @@ def koreha_arimasuka_base_expected():
consonant=None,
consonant_length=None,
vowel="a",
vowel_length=0,
pitch=0,
vowel_length=1.44,
pitch=1.44,
),
Mora(
text="リ",
consonant="r",
consonant_length=0,
consonant_length=3.06,
vowel="i",
vowel_length=0,
pitch=0,
vowel_length=2.31,
pitch=4.44,
),
Mora(
text="マ",
consonant="m",
consonant_length=0,
consonant_length=2.62,
vowel="a",
vowel_length=0,
pitch=0,
vowel_length=1.44,
pitch=3.12,
),
Mora(
text="ス",
consonant="s",
consonant_length=0,
consonant_length=3.19,
vowel="U",
vowel_length=0,
pitch=0,
vowel_length=1.38,
pitch=0.0,
),
Mora(
text="カ",
consonant="k",
consonant_length=0,
consonant_length=2.44,
vowel="a",
vowel_length=0,
pitch=0,
vowel_length=1.44,
pitch=2.94,
),
],
accent=3,
pause_mora=None,
is_interrogative=False,
),
]

expected = koreha_arimasuka_base_expected()
expected[-1].is_interrogative = True
expected[-1].moras += [
Mora(
text="ア",
consonant=None,
consonant_length=None,
vowel="a",
vowel_length=0.15,
pitch=0.3,
pitch=round(expected[-1].moras[-1].pitch + 0.3, 2),
)
]
self.create_accent_phrases_test_base(
Expand Down Expand Up @@ -147,12 +222,13 @@ def nn_base_expected():
consonant=None,
consonant_length=None,
vowel="N",
vowel_length=0,
pitch=0,
),
vowel_length=1.25,
pitch=1.44,
)
],
accent=1,
pause_mora=None,
is_interrogative=False,
)
]

Expand All @@ -164,14 +240,15 @@ def nn_base_expected():
)

expected = nn_base_expected()
expected[-1].is_interrogative = True
expected[-1].moras += [
Mora(
text="ン",
consonant=None,
consonant_length=None,
vowel="N",
vowel_length=0.15,
pitch=0.3,
pitch=round(expected[-1].moras[-1].pitch + 0.3, 2),
)
]
self.create_accent_phrases_test_base(
Expand All @@ -196,12 +273,13 @@ def ltu_base_expected():
consonant=None,
consonant_length=None,
vowel="cl",
vowel_length=0,
vowel_length=1.69,
pitch=0.0,
),
)
],
accent=1,
pause_mora=None,
is_interrogative=False,
)
]

Expand All @@ -213,16 +291,7 @@ def ltu_base_expected():
)

expected = ltu_base_expected()
expected[-1].moras += [
Mora(
text="ッ",
consonant=None,
consonant_length=None,
vowel="cl",
vowel_length=0.15,
pitch=0.3,
)
]
expected[-1].is_interrogative = True
self.create_accent_phrases_test_base(
text="っ?",
expected=expected,
Expand All @@ -243,14 +312,15 @@ def su_base_expected():
Mora(
text="ス",
consonant="s",
consonant_length=0,
consonant_length=3.19,
vowel="u",
vowel_length=0,
pitch=0,
),
vowel_length=3.5,
pitch=5.94,
)
],
accent=1,
pause_mora=None,
is_interrogative=False,
)
]

Expand All @@ -262,14 +332,15 @@ def su_base_expected():
)

expected = su_base_expected()
expected[-1].is_interrogative = True
expected[-1].moras += [
Mora(
text="ウ",
consonant=None,
consonant_length=None,
vowel="u",
vowel_length=0.15,
pitch=0.3,
pitch=round(expected[-1].moras[-1].pitch + 0.3, 2),
)
]
self.create_accent_phrases_test_base(
Expand Down
1 change: 1 addition & 0 deletions voicevox_engine/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AccentPhrase(BaseModel):
moras: List[Mora] = Field(title="モーラのリスト")
accent: int = Field(title="アクセント箇所")
pause_mora: Optional[Mora] = Field(title="後ろに無音を付けるかどうか")
is_interrogative: bool = Field(default=False, title="疑問系かどうか")

def __hash__(self):
items = [
Expand Down
Loading

0 comments on commit 7d4eb98

Please sign in to comment.