Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.responses import StreamingResponse
|
| 4 |
+
from chatterbox import ChatterboxMultilingualTTS # حسب التسمية في الريبو
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
model = ChatterboxMultilingualTTS.from_pretrained("ResembleAI/chatterbox")
|
| 9 |
+
|
| 10 |
+
@app.post("/tts")
|
| 11 |
+
async def tts_endpoint(text: str, language: str = "ar"):
|
| 12 |
+
# يمكنك ضبط باراميترات اللغة/الصوت حسب الدوكمنتشِن
|
| 13 |
+
audio = model.tts(text, language=language)
|
| 14 |
+
# audio: numpy array or torch tensor
|
| 15 |
+
# حوّله إلى wav/ogg stream
|
| 16 |
+
def iterfile():
|
| 17 |
+
yield audio.tobytes()
|
| 18 |
+
return StreamingResponse(iterfile(), media_type="audio/wav")
|