muaadh019 commited on
Commit
6db99fc
·
verified ·
1 Parent(s): bf0686c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import FileResponse
3
+ from TTS.api import TTS
4
+ import uuid
5
+ import os
6
+
7
+ app = FastAPI()
8
+
9
+ # تحميل موديل XTTS
10
+ tts = TTS(
11
+ model_name="tts_models/multilingual/multi-dataset/xtts_v2",
12
+ progress_bar=False,
13
+ gpu=False
14
+ )
15
+
16
+ OUTPUT_DIR = "outputs"
17
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
18
+
19
+ @app.get("/")
20
+ def home():
21
+ return {
22
+ "message": "Saudi Arabic TTS is running 🎙️🇸🇦",
23
+ "usage": "/tts?text=هلا+والله"
24
+ }
25
+
26
+ @app.get("/tts")
27
+ def text_to_speech(text: str):
28
+ filename = f"{uuid.uuid4()}.wav"
29
+ filepath = os.path.join(OUTPUT_DIR, filename)
30
+
31
+ tts.tts_to_file(
32
+ text=text,
33
+ file_path=filepath,
34
+ language="ar"
35
+ )
36
+
37
+ return FileResponse(
38
+ filepath,
39
+ media_type="audio/wav",
40
+ filename="saudi_tts.wav"
41
+ )