diff --git a/README.md b/README.md index 0ab02908c..b46fc4a9c 100644 --- a/README.md +++ b/README.md @@ -288,8 +288,9 @@ VOICEVOXではセキュリティ保護のため`localhost`・`127.0.0.1`・`app: ```bash $ python run.py -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] +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] VOICEVOX のエンジンです。 @@ -319,6 +320,8 @@ options: 許可するオリジンを指定します。スペースで区切ることで複数指定できます。 --setting_file SETTING_FILE 設定ファイルを指定できます。 + --preset_file PRESET_FILE + プリセットファイルを指定できます。指定がない場合、環境変数 VV_PRESET_FILE、--voicevox_dirのpresets.yaml、実行ファイルのディレクトリのpresets.yamlを順に探します。 ``` ## アップデート diff --git a/make_docs.py b/make_docs.py index d10bd1aa4..d21ba85b9 100644 --- a/make_docs.py +++ b/make_docs.py @@ -2,7 +2,9 @@ from voicevox_engine.dev.core import mock as core from voicevox_engine.dev.synthesis_engine.mock import MockSynthesisEngine +from voicevox_engine.preset import PresetManager from voicevox_engine.setting import USER_SETTING_PATH, SettingLoader +from voicevox_engine.utility import engine_root if __name__ == "__main__": import run @@ -11,6 +13,9 @@ synthesis_engines={"mock": MockSynthesisEngine(speakers=core.metas())}, latest_core_version="mock", setting_loader=SettingLoader(USER_SETTING_PATH), + preset_manager=PresetManager( # FIXME: impl MockPresetManager + preset_path=engine_root() / "presets.yaml", + ), ) with open("docs/api/index.html", "w") as f: f.write( diff --git a/run.py b/run.py index 8fc2cddea..ccc6119c7 100644 --- a/run.py +++ b/run.py @@ -116,6 +116,7 @@ def generate_app( synthesis_engines: Dict[str, SynthesisEngineBase], latest_core_version: str, setting_loader: SettingLoader, + preset_manager: PresetManager, root_dir: Optional[Path] = None, cors_policy_mode: CorsPolicyMode = CorsPolicyMode.localapps, allow_origin: Optional[List[str]] = None, @@ -177,9 +178,6 @@ async def block_origin_middleware(request: Request, call_next): status_code=403, content={"detail": "Origin not allowed"} ) - preset_manager = PresetManager( - preset_path=root_dir / "presets.yaml", - ) engine_manifest_data = EngineManifestLoader( engine_root() / "engine_manifest.json", engine_root() ).load_manifest() @@ -1273,6 +1271,17 @@ def custom_openapi(): "--setting_file", type=Path, default=USER_SETTING_PATH, help="設定ファイルを指定できます。" ) + parser.add_argument( + "--preset_file", + type=Path, + default=None, + help=( + "プリセットファイルを指定できます。" + "指定がない場合、環境変数 VV_PRESET_FILE、--voicevox_dirのpresets.yaml、" + "実行ファイルのディレクトリのpresets.yamlを順に探します。" + ), + ) + args = parser.parse_args() if args.output_log_utf8: @@ -1296,17 +1305,17 @@ def custom_openapi(): if args.enable_cancellable_synthesis: cancellable_engine = CancellableEngine(args) - root_dir = args.voicevox_dir if args.voicevox_dir is not None else engine_root() + root_dir: Path | None = args.voicevox_dir + if root_dir is None: + root_dir = engine_root() setting_loader = SettingLoader(args.setting_file) settings = setting_loader.load_setting_file() - cors_policy_mode = ( - args.cors_policy_mode - if args.cors_policy_mode is not None - else settings.cors_policy_mode - ) + cors_policy_mode: CorsPolicyMode | None = args.cors_policy_mode + if cors_policy_mode is None: + cors_policy_mode = settings.cors_policy_mode allow_origin = None if args.allow_origin is not None: @@ -1314,11 +1323,30 @@ def custom_openapi(): elif settings.allow_origin is not None: allow_origin = settings.allow_origin.split(" ") + # Preset Manager + # preset_pathの優先順: 引数、環境変数、voicevox_dir、実行ファイルのディレクトリ + # ファイルの存在に関わらず、優先順で最初に指定されたパスをプリセットファイルとして使用する + preset_path: Path | None = args.preset_file + if preset_path is None: + # 引数 --preset_file の指定がない場合 + env_preset_path = os.getenv("VV_PRESET_FILE") + if env_preset_path is not None and len(env_preset_path) != 0: + # 環境変数 VV_PRESET_FILE の指定がある場合 + preset_path = Path(env_preset_path) + else: + # 環境変数 VV_PRESET_FILE の指定がない場合 + preset_path = root_dir / "presets.yaml" + + preset_manager = PresetManager( + preset_path=preset_path, + ) + uvicorn.run( generate_app( synthesis_engines, latest_core_version, setting_loader, + preset_manager=preset_manager, root_dir=root_dir, cors_policy_mode=cors_policy_mode, allow_origin=allow_origin, diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index 23fd4f042..af21590c1 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -4,6 +4,7 @@ from fastapi.testclient import TestClient from run import generate_app +from voicevox_engine.preset import PresetManager from voicevox_engine.setting import SettingLoader from voicevox_engine.synthesis_engine import make_synthesis_engines from voicevox_engine.utility.core_version_utility import get_latest_core_version @@ -14,11 +15,15 @@ def client(): synthesis_engines = make_synthesis_engines(use_gpu=False) latest_core_version = get_latest_core_version(versions=synthesis_engines.keys()) setting_loader = SettingLoader(Path("./default_setting.yml")) + preset_manager = PresetManager( # FIXME: impl MockPresetManager + preset_path=Path("./presets.yaml"), + ) return TestClient( generate_app( synthesis_engines=synthesis_engines, latest_core_version=latest_core_version, setting_loader=setting_loader, + preset_manager=preset_manager, ) )