-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* `blocking.{OpenJtalk,UserDict}` * `voicevox_core.asyncio` * Blackとisortに`--diff`を付ける * isort * `blocking.{Synthesizer,VoiceModel}` * `add_class` * example/python/run.pyをブロッキング版に * テストをコピペで実装 * #701 の動作チェックにrun-asyncio.pyを追加 * `shell: bash` * #699 のusage.mdを更新 * スタイルの統一 * run-asyncio.pyのコメント変更
- Loading branch information
Showing
22 changed files
with
1,341 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
crates/voicevox_core_python_api/python/test/test_blocking_user_dict_load.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
ユーザー辞書の単語が反映されるかをテストする。 | ||
``test_pseudo_raii_for_asyncio_synthesizer`` と対になる。 | ||
""" | ||
|
||
# AudioQueryのkanaを比較して変化するかどうかで判断する。 | ||
|
||
from uuid import UUID | ||
|
||
import conftest | ||
import voicevox_core | ||
|
||
|
||
def test_user_dict_load() -> None: | ||
open_jtalk = voicevox_core.blocking.OpenJtalk(conftest.open_jtalk_dic_dir) | ||
model = voicevox_core.blocking.VoiceModel.from_path(conftest.model_dir) | ||
synthesizer = voicevox_core.blocking.Synthesizer(open_jtalk) | ||
|
||
synthesizer.load_voice_model(model) | ||
|
||
audio_query_without_dict = synthesizer.audio_query( | ||
"this_word_should_not_exist_in_default_dictionary", style_id=0 | ||
) | ||
|
||
temp_dict = voicevox_core.blocking.UserDict() | ||
uuid = temp_dict.add_word( | ||
voicevox_core.UserDictWord( | ||
surface="this_word_should_not_exist_in_default_dictionary", | ||
pronunciation="アイウエオ", | ||
) | ||
) | ||
assert isinstance(uuid, UUID) | ||
|
||
open_jtalk.use_user_dict(temp_dict) | ||
|
||
audio_query_with_dict = synthesizer.audio_query( | ||
"this_word_should_not_exist_in_default_dictionary", style_id=0 | ||
) | ||
assert audio_query_without_dict != audio_query_with_dict |
83 changes: 83 additions & 0 deletions
83
crates/voicevox_core_python_api/python/test/test_blocking_user_dict_manipulate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
ユーザー辞書の操作をテストする。 | ||
``test_asyncio_user_dict_manipulate`` と対になる。 | ||
""" | ||
|
||
# どのコードがどの操作を行っているかはコメントを参照。 | ||
|
||
import os | ||
import tempfile | ||
from uuid import UUID | ||
|
||
import pydantic | ||
import pytest | ||
import voicevox_core | ||
|
||
|
||
def test_user_dict_load() -> None: | ||
dict_a = voicevox_core.blocking.UserDict() | ||
|
||
# 単語の追加 | ||
uuid_a = dict_a.add_word( | ||
voicevox_core.UserDictWord( | ||
surface="hoge", | ||
pronunciation="ホゲ", | ||
) | ||
) | ||
assert isinstance(uuid_a, UUID) | ||
assert dict_a.words[uuid_a].surface == "hoge" | ||
assert dict_a.words[uuid_a].pronunciation == "ホゲ" | ||
|
||
# 単語の更新 | ||
dict_a.update_word( | ||
uuid_a, | ||
voicevox_core.UserDictWord( | ||
surface="fuga", | ||
pronunciation="フガ", | ||
), | ||
) | ||
|
||
assert dict_a.words[uuid_a].surface == "fuga" | ||
assert dict_a.words[uuid_a].pronunciation == "フガ" | ||
|
||
# ユーザー辞書のインポート | ||
dict_b = voicevox_core.blocking.UserDict() | ||
uuid_b = dict_b.add_word( | ||
voicevox_core.UserDictWord( | ||
surface="foo", | ||
pronunciation="フー", | ||
) | ||
) | ||
|
||
dict_a.import_dict(dict_b) | ||
assert uuid_b in dict_a.words | ||
|
||
# ユーザー辞書のエクスポート | ||
dict_c = voicevox_core.blocking.UserDict() | ||
uuid_c = dict_c.add_word( | ||
voicevox_core.UserDictWord( | ||
surface="bar", | ||
pronunciation="バー", | ||
) | ||
) | ||
temp_path_fd, temp_path = tempfile.mkstemp() | ||
os.close(temp_path_fd) | ||
dict_c.save(temp_path) | ||
dict_a.load(temp_path) | ||
assert uuid_a in dict_a.words | ||
assert uuid_c in dict_a.words | ||
|
||
# 単語の削除 | ||
dict_a.remove_word(uuid_a) | ||
assert uuid_a not in dict_a.words | ||
assert uuid_c in dict_a.words | ||
|
||
# 単語のバリデーション | ||
with pytest.raises(pydantic.ValidationError): | ||
dict_a.add_word( | ||
voicevox_core.UserDictWord( | ||
surface="", | ||
pronunciation="カタカナ以外の文字", | ||
) | ||
) |
4 changes: 3 additions & 1 deletion
4
.../test/test_pseudo_raii_for_synthesizer.py → ...st_pseudo_raii_for_asyncio_synthesizer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
crates/voicevox_core_python_api/python/test/test_pseudo_raii_for_blocking_synthesizer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
``Synthesizer`` について、(広義の)RAIIができることをテストする。 | ||
``test_pseudo_raii_for_asyncio_synthesizer`` と対になる。 | ||
""" | ||
|
||
import conftest | ||
import pytest | ||
from voicevox_core.blocking import OpenJtalk, Synthesizer | ||
|
||
|
||
def test_enter_returns_workable_self(synthesizer: Synthesizer) -> None: | ||
with synthesizer as ctx: | ||
assert ctx is synthesizer | ||
_ = synthesizer.metas | ||
|
||
|
||
def test_closing_multiple_times_is_allowed(synthesizer: Synthesizer) -> None: | ||
with synthesizer: | ||
with synthesizer: | ||
pass | ||
synthesizer.close() | ||
synthesizer.close() | ||
|
||
|
||
def test_access_after_close_denied(synthesizer: Synthesizer) -> None: | ||
synthesizer.close() | ||
with pytest.raises(ValueError, match="^The `Synthesizer` is closed$"): | ||
_ = synthesizer.metas | ||
|
||
|
||
def test_access_after_exit_denied(synthesizer: Synthesizer) -> None: | ||
with synthesizer: | ||
pass | ||
with pytest.raises(ValueError, match="^The `Synthesizer` is closed$"): | ||
_ = synthesizer.metas | ||
|
||
|
||
@pytest.fixture | ||
def synthesizer(open_jtalk: OpenJtalk) -> Synthesizer: | ||
return Synthesizer(open_jtalk) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def open_jtalk() -> OpenJtalk: | ||
return OpenJtalk(conftest.open_jtalk_dic_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.