#!/usr/bin/env python3 """FastAPI WebSocket endpoint for live audio streaming.""" from __future__ import annotations from fastapi import FastAPI, WebSocket, WebSocketDisconnect from ws_manager import ConnectionManager app = FastAPI(title="Audio Analyzer WebSocket") manager = ConnectionManager() @app.get("/health") async def health() -> dict[str, str]: """Health check endpoint.""" return {"status": "ok"} @app.websocket("/ws/live") async def ws_live(websocket: WebSocket) -> None: """WebSocket endpoint for real-time audio data streaming.""" await manager.connect(websocket) try: while True: # Keep connection alive await websocket.receive_text() except WebSocketDisconnect: pass except Exception: pass finally: await manager.disconnect(websocket)