forked from monuminu/voicebot-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebapp.py
More file actions
54 lines (42 loc) · 1.75 KB
/
webapp.py
File metadata and controls
54 lines (42 loc) · 1.75 KB
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
44
45
46
47
48
49
50
51
52
53
54
import os
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import logging
import csv
logging.basicConfig(level=logging.INFO)
WEBSOCKET_URL = "ws://localhost:5000"#os.environ.get("WEBSOCKET_URL")
if not WEBSOCKET_URL:
raise ValueError("WEBSOCKET_URL must be set")
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
app.mount("/scripts", StaticFiles(directory="scripts"), name="scripts")
app.mount("/styles", StaticFiles(directory="styles"), name="styles")
templates = Jinja2Templates(directory="templates")
# read csv
region = os.getenv("SPEECH_REGION", "").lower()
preview_regions = ["eastus", "southeastasia", "westeurope", "westus2"]
with open('voices.csv', 'r') as f:
f.readline()
reader = csv.reader(f)
voice_list ={
"voices": {
k: v.strip() for k, v, p in reader if not p or region in preview_regions
}
}
print(voice_list)
@app.get("/", response_class=HTMLResponse)
async def read_item(request: Request):
logging.info(request.headers)
logging.info(request.url)
return templates.TemplateResponse(
name="index.html", context={"ws_url": WEBSOCKET_URL, "request": request}
)
voice_list = {'voices': {'en-IN-AartiNeural': 'AartiNeural English',
'hi-IN-AartiNeural': 'AartiNeural Hindi',
'en-IN-AnanyaNeural': 'AnanyaNeural English',
'hi-IN-AnanyaNeural': 'AnanyaNeural Hindi'}}
@app.get("/voices", response_class=JSONResponse)
async def voices(request: Request):
return JSONResponse(content=voice_list)