diff --git a/run.py b/run.py index ccc6119c7..eea5fad11 100644 --- a/run.py +++ b/run.py @@ -117,6 +117,7 @@ def generate_app( latest_core_version: str, setting_loader: SettingLoader, preset_manager: PresetManager, + cancellable_engine: CancellableEngine | None = None, root_dir: Optional[Path] = None, cors_policy_mode: CorsPolicyMode = CorsPolicyMode.localapps, allow_origin: Optional[List[str]] = None, @@ -200,7 +201,7 @@ async def block_origin_middleware(request: Request, call_next): # @app.on_event("startup") # async def start_catch_disconnection(): - # if args.enable_cancellable_synthesis: + # if cancellable_engine is not None: # loop = asyncio.get_event_loop() # _ = loop.create_task(cancellable_engine.catch_disconnection()) @@ -429,7 +430,7 @@ def cancellable_synthesis( request: Request, core_version: Optional[str] = None, ): - if not args.enable_cancellable_synthesis: + if cancellable_engine is None: raise HTTPException( status_code=404, detail="実験的機能はデフォルトで無効になっています。使用するには引数を指定してください。", @@ -1170,7 +1171,7 @@ def custom_openapi(): return app -if __name__ == "__main__": +def main() -> None: multiprocessing.freeze_support() output_log_utf8 = os.getenv("VV_OUTPUT_LOG_UTF8", default="") @@ -1182,8 +1183,6 @@ def custom_openapi(): file=sys.stderr, ) - default_cors_policy_mode = CorsPolicyMode.localapps - parser = argparse.ArgumentParser(description="VOICEVOX のエンジンです。") parser.add_argument( "--host", type=str, default="127.0.0.1", help="接続を受け付けるホストアドレスです。" @@ -1301,8 +1300,9 @@ def custom_openapi(): assert len(synthesis_engines) != 0, "音声合成エンジンがありません。" latest_core_version = get_latest_core_version(versions=synthesis_engines.keys()) - cancellable_engine = None - if args.enable_cancellable_synthesis: + enable_cancellable_synthesis: bool = args.enable_cancellable_synthesis + cancellable_engine: CancellableEngine | None = None + if enable_cancellable_synthesis: cancellable_engine = CancellableEngine(args) root_dir: Path | None = args.voicevox_dir @@ -1347,6 +1347,7 @@ def custom_openapi(): latest_core_version, setting_loader, preset_manager=preset_manager, + cancellable_engine=cancellable_engine, root_dir=root_dir, cors_policy_mode=cors_policy_mode, allow_origin=allow_origin, @@ -1354,3 +1355,7 @@ def custom_openapi(): host=args.host, port=args.port, ) + + +if __name__ == "__main__": + main()