Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
+
from fastapi.responses import FileResponse
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
@app.get("/")
|
9 |
+
def home():
|
10 |
+
return {"message": "EdgeTTS FastAPI is running!"}
|
11 |
+
|
12 |
+
@app.get("/tts")
|
13 |
+
async def tts(text: str, voice: str = "en-US-AriaNeural"):
|
14 |
+
output_file = "output.mp3"
|
15 |
+
|
16 |
+
# Generate speech
|
17 |
+
communicate = edge_tts.Communicate(text, voice)
|
18 |
+
await communicate.save(output_file)
|
19 |
+
|
20 |
+
return FileResponse(output_file, media_type="audio/mpeg", filename="speech.mp3")
|
21 |
+
|