-
Notifications
You must be signed in to change notification settings - Fork 119
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
PythonのブロッキングAPIを実装 #706
Merged
Merged
PythonのブロッキングAPIを実装 #706
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b9edd5b
`blocking.{OpenJtalk,UserDict}`
qryxip 4b748f5
`voicevox_core.asyncio`
qryxip 8d0ead3
Blackとisortに`--diff`を付ける
qryxip a31760f
isort
qryxip d58ae78
`blocking.{Synthesizer,VoiceModel}`
qryxip 9da8b12
`add_class`
qryxip 16b8428
example/python/run.pyをブロッキング版に
qryxip 9c99edc
テストをコピペで実装
qryxip d7fed1f
#701 の動作チェックにrun-asyncio.pyを追加
qryxip a2a8143
`shell: bash`
qryxip 5000662
#699 のusage.mdを更新
qryxip d5083e5
スタイルの統一
qryxip 6b74f6c
run-asyncio.pyのコメント変更
qryxip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,7 @@ jobs: | |
runs-on: ${{ matrix.os }} | ||
defaults: | ||
run: | ||
shell: bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. どうやら今まで、このjob全体がPowerShellで実行されていた模様... |
||
working-directory: ./crates/voicevox_core_python_api | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
@@ -292,7 +293,10 @@ jobs: | |
|
||
poetry run pytest | ||
- name: Exampleを実行 | ||
run: poetry run python ../../example/python/run.py ../../model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11 | ||
run: | | ||
for file in ../../example/python/run{,-asyncio}.py; do | ||
poetry run python "$file" ../../model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11 | ||
done | ||
build-and-test-java-api: | ||
strategy: | ||
fail-fast: false | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRが出ているが、以下のコメントから約2ヶ月放置されている状態になっている。
readthedocs/sphinx-autoapi#406 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あと、このworkaroundを実行するとコードとしては壊れて実行できなくなる(_rust.abi3.*よりも_rust/__init__.pyの方が優先されるらしい)。
Sphinxを騙すためだけにGHA上で実行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
手元で生成するのに面倒が生じてきてるので、いっそのこと他言語ごと
❯ cargo xtask doc [--only rust c python ...] [--open]
みたいな感じで生成できるようにした方がよいかもしれない。