Skip to content

Commit

Permalink
run.py: __main__実装をmain関数スコープに移動させる (VOICEVOX#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoirint authored Oct 9, 2023
1 parent a398d3b commit 5ca4c30
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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="実験的機能はデフォルトで無効になっています。使用するには引数を指定してください。",
Expand Down Expand Up @@ -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="")
Expand All @@ -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="接続を受け付けるホストアドレスです。"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1347,10 +1347,15 @@ 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,
),
host=args.host,
port=args.port,
)


if __name__ == "__main__":
main()

0 comments on commit 5ca4c30

Please sign in to comment.