-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
43 lines (30 loc) · 899 Bytes
/
server.py
File metadata and controls
43 lines (30 loc) · 899 Bytes
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, Request, Query
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
from utils import init, ClientConnection
@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 TTS Service"}
@app.get("/tts")
async def tts(request: Request, text: str = Query(...)):
"""Handle text-to-speech requests."""
client = ClientConnection()
return client.handle(request, text)
if __name__ == "__main__":
import uvicorn
import os
HOST = os.getenv("HOST", "localhost")
PORT = os.getenv("PORT", 8000)
uvicorn.run(app, host=HOST, port=PORT)