Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from fastapi import FastAPI, Request, HTTPException
|
| 4 |
from tts_arabic import tts as arabic_tts
|
| 5 |
|
|
@@ -165,6 +169,13 @@ async def tts_api(request: Request):
|
|
| 165 |
"model_id": "fastpitch",
|
| 166 |
"vocoder_id": "hifigan"
|
| 167 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
"""
|
| 169 |
key = request.headers.get("x-api-key")
|
| 170 |
if key != API_KEY:
|
|
@@ -188,9 +199,16 @@ async def tts_api(request: Request):
|
|
| 188 |
raise HTTPException(status_code=400, detail=status)
|
| 189 |
|
| 190 |
sr, data = audio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
return {
|
|
|
|
| 192 |
"sample_rate": sr,
|
| 193 |
-
"audio": data.tolist(), # قائمة أرقام float
|
| 194 |
"status": status,
|
| 195 |
}
|
| 196 |
|
|
|
|
| 1 |
+
import base64
|
| 2 |
+
from io import BytesIO
|
| 3 |
+
|
| 4 |
import numpy as np
|
| 5 |
import gradio as gr
|
| 6 |
+
import soundfile as sf
|
| 7 |
from fastapi import FastAPI, Request, HTTPException
|
| 8 |
from tts_arabic import tts as arabic_tts
|
| 9 |
|
|
|
|
| 169 |
"model_id": "fastpitch",
|
| 170 |
"vocoder_id": "hifigan"
|
| 171 |
}
|
| 172 |
+
|
| 173 |
+
Response:
|
| 174 |
+
{
|
| 175 |
+
"wav_base64": "...",
|
| 176 |
+
"sample_rate": 22050,
|
| 177 |
+
"status": "..."
|
| 178 |
+
}
|
| 179 |
"""
|
| 180 |
key = request.headers.get("x-api-key")
|
| 181 |
if key != API_KEY:
|
|
|
|
| 199 |
raise HTTPException(status_code=400, detail=status)
|
| 200 |
|
| 201 |
sr, data = audio
|
| 202 |
+
|
| 203 |
+
# -------- تحويل الـnumpy إلى WAV Base64 --------
|
| 204 |
+
buffer = BytesIO()
|
| 205 |
+
sf.write(buffer, data, sr, format="WAV")
|
| 206 |
+
wav_bytes = buffer.getvalue()
|
| 207 |
+
wav_base64 = base64.b64encode(wav_bytes).decode("utf-8")
|
| 208 |
+
|
| 209 |
return {
|
| 210 |
+
"wav_base64": wav_base64,
|
| 211 |
"sample_rate": sr,
|
|
|
|
| 212 |
"status": status,
|
| 213 |
}
|
| 214 |
|