File size: 849 Bytes
6db99fc | 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 | from fastapi import FastAPI
from fastapi.responses import FileResponse
from TTS.api import TTS
import uuid
import os
app = FastAPI()
# ุชุญู
ูู ู
ูุฏูู XTTS
tts = TTS(
model_name="tts_models/multilingual/multi-dataset/xtts_v2",
progress_bar=False,
gpu=False
)
OUTPUT_DIR = "outputs"
os.makedirs(OUTPUT_DIR, exist_ok=True)
@app.get("/")
def home():
return {
"message": "Saudi Arabic TTS is running ๐๏ธ๐ธ๐ฆ",
"usage": "/tts?text=ููุง+ูุงููู"
}
@app.get("/tts")
def text_to_speech(text: str):
filename = f"{uuid.uuid4()}.wav"
filepath = os.path.join(OUTPUT_DIR, filename)
tts.tts_to_file(
text=text,
file_path=filepath,
language="ar"
)
return FileResponse(
filepath,
media_type="audio/wav",
filename="saudi_tts.wav"
)
|