Skip to content
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

run.py: __main__実装をmain関数スコープに移動させる #761

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()