Spaces:
Running
Running
serve engine.js same-origin for the Web Worker
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ import numpy as np
|
|
| 29 |
import onnxruntime as ort
|
| 30 |
import soundfile as sf
|
| 31 |
import uvicorn
|
| 32 |
-
from fastapi.responses import HTMLResponse
|
| 33 |
from gradio.utils import get_upload_folder
|
| 34 |
from gradio_client import utils as client_utils
|
| 35 |
|
|
@@ -244,6 +244,14 @@ def _studio_page():
|
|
| 244 |
return f.read()
|
| 245 |
|
| 246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
@server.api(name="speak", concurrency_limit=2)
|
| 248 |
def api_speak(text: str, voice: str = "F2", speed: float = 1.0,
|
| 249 |
pitch_shift: float = 0.0, pitch_range: float = 1.0) -> dict:
|
|
|
|
| 29 |
import onnxruntime as ort
|
| 30 |
import soundfile as sf
|
| 31 |
import uvicorn
|
| 32 |
+
from fastapi.responses import FileResponse, HTMLResponse
|
| 33 |
from gradio.utils import get_upload_folder
|
| 34 |
from gradio_client import utils as client_utils
|
| 35 |
|
|
|
|
| 244 |
return f.read()
|
| 245 |
|
| 246 |
|
| 247 |
+
@server.get("/engine.js")
|
| 248 |
+
def _engine_js():
|
| 249 |
+
"""The in-browser engine (Web Worker): Pyodide phonemizer + onnxruntime-web
|
| 250 |
+
WebGPU/WASM session, so the studio can synthesize entirely on the visitor's
|
| 251 |
+
device. Served same-origin so the Worker constructor accepts it."""
|
| 252 |
+
return FileResponse(os.path.join(APP_DIR, "engine.js"), media_type="text/javascript")
|
| 253 |
+
|
| 254 |
+
|
| 255 |
@server.api(name="speak", concurrency_limit=2)
|
| 256 |
def api_speak(text: str, voice: str = "F2", speed: float = 1.0,
|
| 257 |
pitch_shift: float = 0.0, pitch_range: float = 1.0) -> dict:
|