Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

リファクタリング: SynthesisEngine内の関数のテストをファイル単位に切り出し #216

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions test/data_hello_hiho.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from voicevox_engine.acoustic_feature_extractor import OjtPhoneme
from voicevox_engine.model import AccentPhrase, Mora

str_list = "sil k o N n i ch i w a pau h i h o d e s U sil".split()

phoneme_data_list = [
OjtPhoneme(phoneme=p, start=i, end=i + 1)
for i, p in enumerate("pau k o N n i ch i w a pau h i h o d e s U pau".split())
]

accent_phrases = [
AccentPhrase(
moras=[
Mora(
text="コ",
consonant="k",
consonant_length=0.0,
vowel="o",
vowel_length=0.0,
pitch=0.0,
),
Mora(
text="ン",
consonant=None,
consonant_length=None,
vowel="N",
vowel_length=0.0,
pitch=0.0,
),
Mora(
text="ニ",
consonant="n",
consonant_length=0.0,
vowel="i",
vowel_length=0.0,
pitch=0.0,
),
Mora(
text="チ",
consonant="ch",
consonant_length=0.0,
vowel="i",
vowel_length=0.0,
pitch=0.0,
),
Mora(
text="ワ",
consonant="w",
consonant_length=0.0,
vowel="a",
vowel_length=0.0,
pitch=0.0,
),
],
accent=5,
pause_mora=Mora(
text="、",
consonant=None,
consonant_length=None,
vowel="pau",
vowel_length=0.0,
pitch=0.0,
),
),
AccentPhrase(
moras=[
Mora(
text="ヒ",
consonant="h",
consonant_length=0.0,
vowel="i",
vowel_length=0.0,
pitch=0.0,
),
Mora(
text="ホ",
consonant="h",
consonant_length=0.0,
vowel="o",
vowel_length=0.0,
pitch=0.0,
),
Mora(
text="デ",
consonant="d",
consonant_length=0.0,
vowel="e",
vowel_length=0.0,
pitch=0.0,
),
Mora(
text="ス",
consonant="s",
consonant_length=0.0,
vowel="U",
vowel_length=0.0,
pitch=0.0,
),
],
accent=1,
pause_mora=None,
),
]
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import TestCase

# TODO: import from voicevox_engine.synthesis_engine.mora
from voicevox_engine.synthesis_engine.synthesis_engine import mora_to_text
from voicevox_engine.synthesis_engine.mora import mora_to_text


class TestMoraToText(TestCase):
Expand Down
47 changes: 47 additions & 0 deletions test/synthesis_engine/mora/test_pre_process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from copy import deepcopy
from unittest import TestCase

from voicevox_engine.acoustic_feature_extractor import OjtPhoneme
from voicevox_engine.synthesis_engine.mora import pre_process

from ... import data_hello_hiho


class TestPreProcess(TestCase):
def test_pre_process(self):
flatten_moras, phoneme_data_list = pre_process(
deepcopy(data_hello_hiho.accent_phrases)
)

mora_index = 0
phoneme_index = 1

self.assertEqual(phoneme_data_list[0], OjtPhoneme("pau", 0, 1))
for accent_phrase in data_hello_hiho.accent_phrases:
moras = accent_phrase.moras
for mora in moras:
self.assertEqual(flatten_moras[mora_index], mora)
mora_index += 1
if mora.consonant is not None:
self.assertEqual(
phoneme_data_list[phoneme_index],
OjtPhoneme(mora.consonant, phoneme_index, phoneme_index + 1),
)
phoneme_index += 1
self.assertEqual(
phoneme_data_list[phoneme_index],
OjtPhoneme(mora.vowel, phoneme_index, phoneme_index + 1),
)
phoneme_index += 1
if accent_phrase.pause_mora:
self.assertEqual(flatten_moras[mora_index], accent_phrase.pause_mora)
mora_index += 1
self.assertEqual(
phoneme_data_list[phoneme_index],
OjtPhoneme("pau", phoneme_index, phoneme_index + 1),
)
phoneme_index += 1
self.assertEqual(
phoneme_data_list[phoneme_index],
OjtPhoneme("pau", phoneme_index, phoneme_index + 1),
)
49 changes: 49 additions & 0 deletions test/synthesis_engine/mora/test_split_mora.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from unittest import TestCase

from voicevox_engine.acoustic_feature_extractor import OjtPhoneme
from voicevox_engine.synthesis_engine.mora import split_mora

from ... import data_hello_hiho


class TestSplitMora(TestCase):
def test_split_mora(self):
consonant_phoneme_list, vowel_phoneme_list, vowel_indexes = split_mora(
data_hello_hiho.phoneme_data_list
)

self.assertEqual(vowel_indexes, [0, 2, 3, 5, 7, 9, 10, 12, 14, 16, 18, 19])
self.assertEqual(
vowel_phoneme_list,
[
OjtPhoneme(phoneme="pau", start=0, end=1),
OjtPhoneme(phoneme="o", start=2, end=3),
OjtPhoneme(phoneme="N", start=3, end=4),
OjtPhoneme(phoneme="i", start=5, end=6),
OjtPhoneme(phoneme="i", start=7, end=8),
OjtPhoneme(phoneme="a", start=9, end=10),
OjtPhoneme(phoneme="pau", start=10, end=11),
OjtPhoneme(phoneme="i", start=12, end=13),
OjtPhoneme(phoneme="o", start=14, end=15),
OjtPhoneme(phoneme="e", start=16, end=17),
OjtPhoneme(phoneme="U", start=18, end=19),
OjtPhoneme(phoneme="pau", start=19, end=20),
],
)
self.assertEqual(
consonant_phoneme_list,
[
None,
OjtPhoneme(phoneme="k", start=1, end=2),
None,
OjtPhoneme(phoneme="n", start=4, end=5),
OjtPhoneme(phoneme="ch", start=6, end=7),
OjtPhoneme(phoneme="w", start=8, end=9),
None,
OjtPhoneme(phoneme="h", start=11, end=12),
OjtPhoneme(phoneme="h", start=13, end=14),
OjtPhoneme(phoneme="d", start=15, end=16),
OjtPhoneme(phoneme="s", start=17, end=18),
None,
],
)
16 changes: 16 additions & 0 deletions test/synthesis_engine/mora/test_to_flatten_moras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest import TestCase

from voicevox_engine.synthesis_engine.mora import to_flatten_moras

from ... import data_hello_hiho


class TestToFlattenMoras(TestCase):
def test_to_flatten_moras(self):
flatten_moras = to_flatten_moras(data_hello_hiho.accent_phrases)
self.assertEqual(
flatten_moras,
data_hello_hiho.accent_phrases[0].moras
+ [data_hello_hiho.accent_phrases[0].pause_mora]
+ data_hello_hiho.accent_phrases[1].moras,
)
11 changes: 11 additions & 0 deletions test/synthesis_engine/mora/test_to_phoneme_data_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from unittest import TestCase

from voicevox_engine.synthesis_engine.mora import to_phoneme_data_list

from ... import data_hello_hiho


class TestToPhonemeDataList(TestCase):
def test_to_phoneme_data_list(self):
phoneme_data_list = to_phoneme_data_list(data_hello_hiho.str_list)
self.assertEqual(phoneme_data_list, data_hello_hiho.phoneme_data_list)
Loading