Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -94,14 +94,18 @@ async def search(request: dict):
|
|
| 94 |
@app.post("/api/tts")
|
| 95 |
async def tts(request: dict):
|
| 96 |
try:
|
| 97 |
-
from
|
| 98 |
-
import
|
|
|
|
|
|
|
| 99 |
text = request.get("text", "")
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
buf = io.BytesIO()
|
| 102 |
-
|
| 103 |
audio_b64 = base64.b64encode(buf.getvalue()).decode()
|
| 104 |
-
return {"audio": audio_b64, "format": "
|
| 105 |
except Exception as e:
|
| 106 |
raise HTTPException(status_code=500, detail=str(e))
|
| 107 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 94 |
@app.post("/api/tts")
|
| 95 |
async def tts(request: dict):
|
| 96 |
try:
|
| 97 |
+
from kokoro import KPipeline
|
| 98 |
+
import soundfile as sf
|
| 99 |
+
import io, base64, numpy as np
|
| 100 |
+
|
| 101 |
text = request.get("text", "")
|
| 102 |
+
pipeline = KPipeline(lang_code='ar')
|
| 103 |
+
samples, sample_rate = pipeline(text)
|
| 104 |
+
|
| 105 |
buf = io.BytesIO()
|
| 106 |
+
sf.write(buf, samples, sample_rate, format='WAV')
|
| 107 |
audio_b64 = base64.b64encode(buf.getvalue()).decode()
|
| 108 |
+
return {"audio": audio_b64, "format": "wav"}
|
| 109 |
except Exception as e:
|
| 110 |
raise HTTPException(status_code=500, detail=str(e))
|
| 111 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|