diff --git a/demo/web/app.py b/demo/web/app.py index 1b45117e..f29241c2 100644 --- a/demo/web/app.py +++ b/demo/web/app.py @@ -332,17 +332,16 @@ def chunk_to_pcm16(self, chunk: np.ndarray) -> bytes: return pcm.tobytes() -app = FastAPI() +from contextlib import asynccontextmanager - -@app.on_event("startup") -async def _startup() -> None: +@asynccontextmanager +async def lifespan(app: FastAPI): model_path = os.environ.get("MODEL_PATH") if not model_path: raise RuntimeError("MODEL_PATH not set in environment") device = os.environ.get("MODEL_DEVICE", "cuda") - + service = StreamingTTSService( model_path=model_path, device=device @@ -354,6 +353,10 @@ async def _startup() -> None: app.state.device = device app.state.websocket_lock = asyncio.Lock() print("[startup] Model ready.") + yield + + +app = FastAPI(lifespan=lifespan) def streaming_tts(text: str, **kwargs) -> Iterator[np.ndarray]: