|
|
from fastapi import FastAPI |
|
|
import edge_tts |
|
|
import asyncio |
|
|
from fastapi.responses import FileResponse |
|
|
import uvicorn |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
@app.get("/") |
|
|
def home(): |
|
|
return {"message": "EdgeTTS FastAPI is running!"} |
|
|
|
|
|
@app.get("/tts") |
|
|
async def tts(text: str, voice: str = "en-US-AriaNeural"): |
|
|
output_file = "output.mp3" |
|
|
|
|
|
|
|
|
communicate = edge_tts.Communicate(text, voice) |
|
|
await communicate.save(output_file) |
|
|
|
|
|
return FileResponse(output_file, media_type="audio/mpeg", filename="speech.mp3") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
uvicorn.run(app, host="0.0.0.0", port=7860) |
|
|
|