-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
43 lines (30 loc) · 888 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from fastapi import FastAPI, WebSocket
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
from utils import ClientConnection, init
@asynccontextmanager
async def lifespan(app: FastAPI):
init()
yield
app = FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def root():
return {"message": "Welcome to the STT service"}
@app.websocket("/stt")
async def websocket_endpoint(websocket: WebSocket):
"""Handle WebSocket connections."""
client = ClientConnection(websocket)
await client.handle()
if __name__ == "__main__":
import uvicorn
import os
HOST = os.getenv("HOST", "localhost")
PORT = os.getenv("PORT", 8000)
uvicorn.run(app, host=HOST, port=PORT)