Skip to content
Open
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
13 changes: 8 additions & 5 deletions demo/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand Down