Create api.py
Browse files
api.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
import app # import the functions from app.py
|
4 |
+
|
5 |
+
app_api = FastAPI()
|
6 |
+
|
7 |
+
class TextRequest(BaseModel):
|
8 |
+
text: str
|
9 |
+
|
10 |
+
@app_api.post("/synthesize/")
|
11 |
+
async def synthesize(request: TextRequest):
|
12 |
+
processed_text = app.preprocess_text(request.text)
|
13 |
+
synthesized_audio = app.synthesize_speech(processed_text)
|
14 |
+
return {"processed_text": processed_text, "audio": synthesized_audio}
|
15 |
+
|
16 |
+
if __name__ == "__main__":
|
17 |
+
import uvicorn
|
18 |
+
uvicorn.run(app_api, host="0.0.0.0", port=8000)
|