-
Notifications
You must be signed in to change notification settings - Fork 22
/
app.py
47 lines (32 loc) · 1.04 KB
/
app.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
44
45
46
47
import os
import uvicorn
from fastapi import FastAPI
from fastapi.responses import FileResponse, Response
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from utils.app_utils import TTSManager
app = FastAPI()
use_cuda_if_available = True
tts_manager = TTSManager('app/static', use_cuda_if_available=use_cuda_if_available)
class TTSRequest(BaseModel):
buckw: str
rate: float
denoise: float
app.mount('/static', StaticFiles(directory='./app/static'), 'static')
@app.get('/')
async def main():
return FileResponse('./app/index.html')
@app.get('/{filename}')
async def get_file(filename: str):
filepath = f'./app/{filename}'
if os.path.exists(filepath):
return FileResponse(filepath)
return Response(status_code=404)
@app.post('/api/tts')
async def tts(req: TTSRequest):
print(req)
response_data = tts_manager.tts(req.buckw, req.rate,
req.denoise)
return response_data
if __name__ == '__main__':
uvicorn.run(app, host="127.0.0.1", port=8000)