From 11d1e847ad17932a2ad5195735e0810667563573 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sat, 1 Jun 2024 05:35:24 +0000 Subject: [PATCH 1/4] =?UTF-8?q?add:=20=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E5=86=85=20`run.py`=20=E3=81=A8=E3=81=9D=E3=81=AE?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-engine-package.yml | 2 +- CONTRIBUTING.md | 16 +++++----- Dockerfile | 6 ++-- README.md | 36 +++++++++++----------- test/benchmark/speed/request.py | 2 +- test/benchmark/speed/speaker.py | 2 +- voicevox_engine/__main__.py | 3 ++ run.py => voicevox_engine/run.py | 0 run.spec => voicevox_engine/run.spec | 10 +++--- 9 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 voicevox_engine/__main__.py rename run.py => voicevox_engine/run.py (100%) rename run.spec => voicevox_engine/run.spec (92%) diff --git a/.github/workflows/build-engine-package.yml b/.github/workflows/build-engine-package.yml index b4a49f305..cae824a41 100644 --- a/.github/workflows/build-engine-package.yml +++ b/.github/workflows/build-engine-package.yml @@ -470,7 +470,7 @@ jobs: CORE_MODEL_DIR_PATH="download/core/model" \ LIBCORE_PATH="$LIBCORE_PATH" \ LIBONNXRUNTIME_PATH="$LIBONNXRUNTIME_PATH" \ - pyinstaller --noconfirm run.spec + pyinstaller --noconfirm voicevox_engine/run.spec # Because PyInstaller does not copy dynamic loaded libraries, # manually move DLL dependencies into `dist/run/` (cache already saved) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 855354b11..5d6ff88ee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -94,35 +94,35 @@ VOICEVOX ENGINE を実行することで HTTP サーバーが立ち上がりま コマンドライン引数の詳細は以下のコマンドで確認してください。 ```bash -python run.py --help +python -m voicevox_engine --help ``` #### 音声ライブラリに製品版 VOICEVOX を利用して実行 ```bash VOICEVOX_DIR="C:/path/to/voicevox" # 製品版 VOICEVOX ディレクトリのパス -python run.py --voicevox_dir=$VOICEVOX_DIR +python -m voicevox_engine --voicevox_dir=$VOICEVOX_DIR ``` #### 音声ライブラリに製品版 VOICEVOX CORE を利用して実行 ```bash VOICELIB_DIR_1="C:/path/to/core_1"; VOICELIB_DIR_2="C:/path/to/core_2"; # 製品版 VOICEVOX CORE ディレクトリのパス -python run.py --voicelib_dir=$VOICELIB_DIR_1 --voicelib_dir=$VOICELIB_DIR_2 +python -m voicevox_engine --voicelib_dir=$VOICELIB_DIR_1 --voicelib_dir=$VOICELIB_DIR_2 ``` #### 音声ライブラリ無しで実行 ```bash -python run.py --enable_mock +python -m voicevox_engine --enable_mock ``` #### ログを UTF8 に変更 ```bash -python run.py --output_log_utf8 +python -m voicevox_engine --output_log_utf8 # もしくは -VV_OUTPUT_LOG_UTF8=1 python run.py +VV_OUTPUT_LOG_UTF8=1 python -m voicevox_engine ``` ### テスト @@ -146,13 +146,13 @@ OUTPUT_LICENSE_JSON_PATH=licenses.json \ bash build_util/create_venv_and_generate_licenses.bash # モックでビルドする場合 -pyinstaller --noconfirm run.spec +pyinstaller --noconfirm voicevox_engine/run.spec # 製品版でビルドする場合 CORE_MODEL_DIR_PATH="/path/to/core_model" \ LIBCORE_PATH="/path/to/libcore" \ LIBONNXRUNTIME_PATH="/path/to/libonnxruntime" \ -pyinstaller --noconfirm run.spec +pyinstaller --noconfirm voicevox_engine/run.spec ``` #### Github Actions でビルド diff --git a/Dockerfile b/Dockerfile index c4049be8a..66fe7d5c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -227,7 +227,7 @@ COPY --from=download-onnxruntime-env /opt/onnxruntime /opt/onnxruntime # Add local files ADD ./voicevox_engine /opt/voicevox_engine/voicevox_engine ADD ./docs /opt/voicevox_engine/docs -ADD ./run.py ./presets.yaml ./engine_manifest.json /opt/voicevox_engine/ +ADD ./presets.yaml ./engine_manifest.json /opt/voicevox_engine/ ADD ./resources /opt/voicevox_engine/resources ADD ./build_util/generate_licenses.py /opt/voicevox_engine/build_util/ ADD ./build_util/licenses /opt/voicevox_engine/build_util/licenses @@ -295,8 +295,8 @@ exec "\$@" EOF ENTRYPOINT [ "/entrypoint.sh" ] -CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--voicelib_dir", "/opt/voicevox_core/", "--runtime_dir", "/opt/onnxruntime/lib", "--host", "0.0.0.0" ] +CMD [ "gosu", "user", "/opt/python/bin/python3", "-m", "voicevox_engine", "--voicelib_dir", "/opt/voicevox_core/", "--runtime_dir", "/opt/onnxruntime/lib", "--host", "0.0.0.0" ] # Enable use_gpu FROM runtime-env AS runtime-nvidia-env -CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--use_gpu", "--voicelib_dir", "/opt/voicevox_core/", "--runtime_dir", "/opt/onnxruntime/lib", "--host", "0.0.0.0" ] +CMD [ "gosu", "user", "/opt/python/bin/python3", "-m", "voicevox_engine", "--use_gpu", "--voicelib_dir", "/opt/voicevox_core/", "--runtime_dir", "/opt/onnxruntime/lib", "--host", "0.0.0.0" ] diff --git a/README.md b/README.md index 245e8d5ed..9199f5e18 100644 --- a/README.md +++ b/README.md @@ -398,11 +398,11 @@ VOICEVOX ではセキュリティ保護のため`localhost`・`127.0.0.1`・`app エンジン起動時に引数を指定できます。詳しいことは`-h`引数でヘルプを確認してください。 ```bash -$ python run.py -h +$ python -m voicevox_engine -h -usage: run.py [-h] [--host HOST] [--port PORT] [--use_gpu] [--voicevox_dir VOICEVOX_DIR] [--voicelib_dir VOICELIB_DIR] [--runtime_dir RUNTIME_DIR] [--enable_mock] [--enable_cancellable_synthesis] - [--init_processes INIT_PROCESSES] [--load_all_models] [--cpu_num_threads CPU_NUM_THREADS] [--output_log_utf8] [--cors_policy_mode {CorsPolicyMode.all,CorsPolicyMode.localapps}] - [--allow_origin [ALLOW_ORIGIN ...]] [--setting_file SETTING_FILE] [--preset_file PRESET_FILE] +usage: __main__.py [-h] [--host HOST] [--port PORT] [--use_gpu] [--voicevox_dir VOICEVOX_DIR] [--voicelib_dir VOICELIB_DIR] [--runtime_dir RUNTIME_DIR] [--enable_mock] [--enable_cancellable_synthesis] + [--init_processes INIT_PROCESSES] [--load_all_models] [--cpu_num_threads CPU_NUM_THREADS] [--output_log_utf8] [--cors_policy_mode {CorsPolicyMode.all,CorsPolicyMode.localapps}] + [--allow_origin [ALLOW_ORIGIN ...]] [--setting_file SETTING_FILE] [--preset_file PRESET_FILE] VOICEVOX のエンジンです。 @@ -469,32 +469,32 @@ python -m pip install -r requirements-test.txt -r requirements-build.txt コマンドライン引数の詳細は以下のコマンドで確認してください。 ```bash -python run.py --help +python -m voicevox_engine --help ``` ```bash # 製品版 VOICEVOX でサーバーを起動 VOICEVOX_DIR="C:/path/to/voicevox" # 製品版 VOICEVOX ディレクトリのパス -python run.py --voicevox_dir=$VOICEVOX_DIR +python -m voicevox_engine --voicevox_dir=$VOICEVOX_DIR ``` ```bash # モックでサーバー起動 -python run.py --enable_mock +python -m voicevox_engine --enable_mock ``` ```bash # ログをUTF8に変更 -python run.py --output_log_utf8 -# もしくは VV_OUTPUT_LOG_UTF8=1 python run.py +python -m voicevox_engine --output_log_utf8 +# もしくは VV_OUTPUT_LOG_UTF8=1 python -m voicevox_engine ``` #### CPU スレッド数を指定する @@ -505,12 +505,12 @@ CPU スレッド数が未指定の場合は、論理コア数の半分が使わ - 実行時引数で指定する ```bash - python run.py --voicevox_dir=$VOICEVOX_DIR --cpu_num_threads=4 + python -m voicevox_engine --voicevox_dir=$VOICEVOX_DIR --cpu_num_threads=4 ``` - 環境変数で指定する ```bash export VV_CPU_NUM_THREADS=4 - python run.py --voicevox_dir=$VOICEVOX_DIR + python -m voicevox_engine --voicevox_dir=$VOICEVOX_DIR ``` #### 過去のバージョンのコアを使う @@ -523,13 +523,13 @@ Mac での libtorch 版コアのサポートはしていません。 製品版 VOICEVOX もしくはコンパイル済みエンジンのディレクトリを`--voicevox_dir`引数で指定すると、そのバージョンのコアが使用されます。 ```bash -python run.py --voicevox_dir="/path/to/voicevox" +python -m voicevox_engine --voicevox_dir="/path/to/voicevox" ``` Mac では、`DYLD_LIBRARY_PATH`の指定が必要です。 ```bash -DYLD_LIBRARY_PATH="/path/to/voicevox" python run.py --voicevox_dir="/path/to/voicevox" +DYLD_LIBRARY_PATH="/path/to/voicevox" python -m voicevox_engine --voicevox_dir="/path/to/voicevox" ``` ##### 音声ライブラリを直接指定する @@ -541,13 +541,13 @@ DYLD_LIBRARY_PATH="/path/to/voicevox" python run.py --voicevox_dir="/path/to/voi API エンドポイントでコアのバージョンを指定する場合は`core_version`引数を指定してください。(未指定の場合は最新のコアが使用されます) ```bash -python run.py --voicelib_dir="/path/to/voicevox_core" --runtime_dir="/path/to/libtorch_or_onnx" +python -m voicevox_engine --voicelib_dir="/path/to/voicevox_core" --runtime_dir="/path/to/libtorch_or_onnx" ``` Mac では、`--runtime_dir`引数の代わりに`DYLD_LIBRARY_PATH`の指定が必要です。 ```bash -DYLD_LIBRARY_PATH="/path/to/onnx" python run.py --voicelib_dir="/path/to/voicevox_core" +DYLD_LIBRARY_PATH="/path/to/onnx" python -m voicevox_engine --voicelib_dir="/path/to/voicevox_core" ``` ##### ユーザーディレクトリに配置する @@ -575,13 +575,13 @@ OUTPUT_LICENSE_JSON_PATH=licenses.json \ bash build_util/create_venv_and_generate_licenses.bash # モックでビルドする場合 -pyinstaller --noconfirm run.spec +pyinstaller --noconfirm voicevox_engine/run.spec # 製品版でビルドする場合 CORE_MODEL_DIR_PATH="/path/to/core_model" \ LIBCORE_PATH="/path/to/libcore" \ LIBONNXRUNTIME_PATH="/path/to/libonnxruntime" \ -pyinstaller --noconfirm run.spec +pyinstaller --noconfirm voicevox_engine/run.spec ``` #### Github Actions でビルド diff --git a/test/benchmark/speed/request.py b/test/benchmark/speed/request.py index 63b0ec8ec..313b990b5 100644 --- a/test/benchmark/speed/request.py +++ b/test/benchmark/speed/request.py @@ -26,7 +26,7 @@ def execute() -> None: # 実行コマンドは `python -m test.benchmark.speed.request` である。 # `server="localhost"` の場合、本ベンチマーク実行に先立ってエンジン起動が必要である。 # エンジン起動コマンドの一例として以下を示す。 - # (別プロセスで)`python run.py --voicevox_dir=VOICEVOX/vv-engine` + # (別プロセスで)`python -m voicevox_engine --voicevox_dir=VOICEVOX/vv-engine` parser = argparse.ArgumentParser() parser.add_argument("--voicevox_dir", type=Path) diff --git a/test/benchmark/speed/speaker.py b/test/benchmark/speed/speaker.py index 7b8c39ecc..f6052d30f 100644 --- a/test/benchmark/speed/speaker.py +++ b/test/benchmark/speed/speaker.py @@ -70,7 +70,7 @@ def execute() -> None: # 実行コマンドは `python -m test.benchmark.speed.speaker` である。 # `server="localhost"` の場合、本ベンチマーク実行に先立ってエンジン起動が必要である。 # エンジン起動コマンドの一例として以下を示す。 - # (別プロセスで)`python run.py --voicevox_dir=VOICEVOX/vv-engine` + # (別プロセスで)`python -m voicevox_engine --voicevox_dir=VOICEVOX/vv-engine` parser = argparse.ArgumentParser() parser.add_argument("--voicevox_dir", type=Path) diff --git a/voicevox_engine/__main__.py b/voicevox_engine/__main__.py new file mode 100644 index 000000000..25aa588c1 --- /dev/null +++ b/voicevox_engine/__main__.py @@ -0,0 +1,3 @@ +from .run import main + +main() diff --git a/run.py b/voicevox_engine/run.py similarity index 100% rename from run.py rename to voicevox_engine/run.py diff --git a/run.spec b/voicevox_engine/run.spec similarity index 92% rename from run.spec rename to voicevox_engine/run.spec index d873ff32e..8502cdc55 100644 --- a/run.spec +++ b/voicevox_engine/run.spec @@ -4,11 +4,11 @@ from PyInstaller.utils.hooks import collect_data_files import os datas = [ - ('resources', 'resources'), - ('speaker_info', 'speaker_info'), - ('engine_manifest.json', '.'), - ('licenses.json', '.'), - ('presets.yaml', '.'), + ('../resources', 'resources'), + ('../speaker_info', 'speaker_info'), + ('../engine_manifest.json', '.'), + ('../licenses.json', '.'), + ('../presets.yaml', '.'), ] datas += collect_data_files('pyopenjtalk') From 4441932ed68cfc55379f167d3905407787d81030 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sat, 1 Jun 2024 05:55:08 +0000 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20`run.py`=20=E3=81=AE=E7=89=B9?= =?UTF-8?q?=E5=88=A5=E6=89=B1=E3=81=84=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-engine-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-engine-package.yml b/.github/workflows/build-engine-package.yml index cae824a41..b5de492b5 100644 --- a/.github/workflows/build-engine-package.yml +++ b/.github/workflows/build-engine-package.yml @@ -445,7 +445,7 @@ jobs: # FIXME: VOICEVOX (editor) cannot build without licenses.json cp resources/engine_manifest_assets/dependency_licenses.json licenses.json - - name: Build VOICEVOX ENGINE run.py + - name: Build VOICEVOX ENGINE run: | set -eux From e604d2bea4f9e57a0f5c0d789e6b8e070ef048cb Mon Sep 17 00:00:00 2001 From: tarepan Date: Mon, 3 Jun 2024 13:31:30 +0000 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20`run.spec`=20=E3=82=92=20`build=5Fut?= =?UTF-8?q?il/`=20=E3=81=B8=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-engine-package.yml | 2 +- CONTRIBUTING.md | 4 ++-- README.md | 4 ++-- {voicevox_engine => build_util}/run.spec | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename {voicevox_engine => build_util}/run.spec (98%) diff --git a/.github/workflows/build-engine-package.yml b/.github/workflows/build-engine-package.yml index b7ce8c88b..053736fcd 100644 --- a/.github/workflows/build-engine-package.yml +++ b/.github/workflows/build-engine-package.yml @@ -470,7 +470,7 @@ jobs: CORE_MODEL_DIR_PATH="download/core/model" \ LIBCORE_PATH="$LIBCORE_PATH" \ LIBONNXRUNTIME_PATH="$LIBONNXRUNTIME_PATH" \ - pyinstaller --noconfirm voicevox_engine/run.spec + pyinstaller --noconfirm build_util/run.spec # Because PyInstaller does not copy dynamic loaded libraries, # manually move DLL dependencies into `dist/run/` (cache already saved) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 172541d8c..3c6f06487 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -309,13 +309,13 @@ OUTPUT_LICENSE_JSON_PATH=licenses.json \ bash build_util/create_venv_and_generate_licenses.bash # モックでビルドする場合 -pyinstaller --noconfirm voicevox_engine/run.spec +pyinstaller --noconfirm build_util/run.spec # 製品版でビルドする場合 CORE_MODEL_DIR_PATH="/path/to/core_model" \ LIBCORE_PATH="/path/to/libcore" \ LIBONNXRUNTIME_PATH="/path/to/libonnxruntime" \ -pyinstaller --noconfirm voicevox_engine/run.spec +pyinstaller --noconfirm build_util/run.spec ``` ### Github Actions でビルド diff --git a/README.md b/README.md index 2c596956b..b440cb91d 100644 --- a/README.md +++ b/README.md @@ -575,13 +575,13 @@ OUTPUT_LICENSE_JSON_PATH=licenses.json \ bash build_util/create_venv_and_generate_licenses.bash # モックでビルドする場合 -pyinstaller --noconfirm voicevox_engine/run.spec +pyinstaller --noconfirm build_util/run.spec # 製品版でビルドする場合 CORE_MODEL_DIR_PATH="/path/to/core_model" \ LIBCORE_PATH="/path/to/libcore" \ LIBONNXRUNTIME_PATH="/path/to/libonnxruntime" \ -pyinstaller --noconfirm voicevox_engine/run.spec +pyinstaller --noconfirm build_util/run.spec ``` TODO: Docker 版のビルド手順を GitHub Actions をベースに記述する diff --git a/voicevox_engine/run.spec b/build_util/run.spec similarity index 98% rename from voicevox_engine/run.spec rename to build_util/run.spec index a8b6f5d5e..44d42fffb 100644 --- a/voicevox_engine/run.spec +++ b/build_util/run.spec @@ -40,7 +40,7 @@ block_cipher = None a = Analysis( - ['run.py'], + ['../voicevox_engine/run.py'], pathex=[], binaries=[], datas=datas, From 46a55d017543b6dcacacd7fb5c48c772d91f7675 Mon Sep 17 00:00:00 2001 From: tarepan Date: Wed, 19 Jun 2024 16:15:04 +0000 Subject: [PATCH 4/4] =?UTF-8?q?revert:=20`run.spec`=20=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=82=92=E5=85=A8=E9=9D=A2=E3=83=AA=E3=83=90=E3=83=BC=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-engine-package.yml | 4 ++-- CONTRIBUTING.md | 4 ++-- README.md | 4 ++-- build_util/run.spec => run.spec | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) rename build_util/run.spec => run.spec (93%) diff --git a/.github/workflows/build-engine-package.yml b/.github/workflows/build-engine-package.yml index 053736fcd..f979c3af6 100644 --- a/.github/workflows/build-engine-package.yml +++ b/.github/workflows/build-engine-package.yml @@ -445,7 +445,7 @@ jobs: # FIXME: VOICEVOX (editor) cannot build without licenses.json cp resources/engine_manifest_assets/dependency_licenses.json licenses.json - - name: Build VOICEVOX ENGINE + - name: Build VOICEVOX ENGINE run.py run: | set -eux @@ -470,7 +470,7 @@ jobs: CORE_MODEL_DIR_PATH="download/core/model" \ LIBCORE_PATH="$LIBCORE_PATH" \ LIBONNXRUNTIME_PATH="$LIBONNXRUNTIME_PATH" \ - pyinstaller --noconfirm build_util/run.spec + pyinstaller --noconfirm run.spec # Because PyInstaller does not copy dynamic loaded libraries, # manually move DLL dependencies into `dist/run/` (cache already saved) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index efae8ec07..40d065d07 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -308,13 +308,13 @@ OUTPUT_LICENSE_JSON_PATH=licenses.json \ bash build_util/create_venv_and_generate_licenses.bash # モックでビルドする場合 -pyinstaller --noconfirm build_util/run.spec +pyinstaller --noconfirm run.spec # 製品版でビルドする場合 CORE_MODEL_DIR_PATH="/path/to/core_model" \ LIBCORE_PATH="/path/to/libcore" \ LIBONNXRUNTIME_PATH="/path/to/libonnxruntime" \ -pyinstaller --noconfirm build_util/run.spec +pyinstaller --noconfirm run.spec ``` ### Github Actions でビルド diff --git a/README.md b/README.md index fc1f05d13..30799738e 100644 --- a/README.md +++ b/README.md @@ -576,13 +576,13 @@ OUTPUT_LICENSE_JSON_PATH=licenses.json \ bash build_util/create_venv_and_generate_licenses.bash # モックでビルドする場合 -pyinstaller --noconfirm build_util/run.spec +pyinstaller --noconfirm run.spec # 製品版でビルドする場合 CORE_MODEL_DIR_PATH="/path/to/core_model" \ LIBCORE_PATH="/path/to/libcore" \ LIBONNXRUNTIME_PATH="/path/to/libonnxruntime" \ -pyinstaller --noconfirm build_util/run.spec +pyinstaller --noconfirm run.spec ``` TODO: Docker 版のビルド手順を GitHub Actions をベースに記述する diff --git a/build_util/run.spec b/run.spec similarity index 93% rename from build_util/run.spec rename to run.spec index 44d42fffb..e295a5a06 100644 --- a/build_util/run.spec +++ b/run.spec @@ -4,10 +4,10 @@ from PyInstaller.utils.hooks import collect_data_files import os datas = [ - ('../resources', 'resources'), - ('../engine_manifest.json', '.'), - ('../licenses.json', '.'), - ('../presets.yaml', '.'), + ('resources', 'resources'), + ('engine_manifest.json', '.'), + ('licenses.json', '.'), + ('presets.yaml', '.'), ] datas += collect_data_files('pyopenjtalk') @@ -40,7 +40,7 @@ block_cipher = None a = Analysis( - ['../voicevox_engine/run.py'], + ['voicevox_engine/run.py'], pathex=[], binaries=[], datas=datas,