Files

58 lines
2.2 KiB
Python

from .supavoice_transcriber import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
from .supavoice_denoiser import (
NODE_CLASS_MAPPINGS as _DENOISER_CLASSES,
NODE_DISPLAY_NAME_MAPPINGS as _DENOISER_NAMES,
)
NODE_CLASS_MAPPINGS = {**NODE_CLASS_MAPPINGS, **_DENOISER_CLASSES}
NODE_DISPLAY_NAME_MAPPINGS = {**NODE_DISPLAY_NAME_MAPPINGS, **_DENOISER_NAMES}
WEB_DIRECTORY = "web"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
# ── Server routes ─────────────────────────────────────────────────────────────
try:
import json
import subprocess
from pathlib import Path
import folder_paths
from aiohttp import web
from server import PromptServer
_UPLOAD_DIR = Path(folder_paths.get_input_directory()) / "supavoice"
_UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
@PromptServer.instance.routes.post("/supavoice/upload_audio")
async def _sv_upload(request):
reader = await request.multipart()
field = await reader.next()
if field is None:
return web.json_response({"error": "no file"}, status=400)
filename = Path(field.filename).name
out_path = _UPLOAD_DIR / filename
with open(out_path, "wb") as f:
while chunk := await field.read_chunk(65536):
f.write(chunk)
return web.json_response({"path": str(out_path)})
@PromptServer.instance.routes.get("/supavoice/probe_duration")
async def _sv_probe(request):
path = request.query.get("path", "")
if not path or not Path(path).exists():
return web.json_response({"duration": 0})
try:
result = subprocess.run(
["ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", path],
capture_output=True, text=True, timeout=10,
)
data = json.loads(result.stdout)
duration = float(data.get("format", {}).get("duration", 0))
except Exception:
duration = 0
return web.json_response({"duration": duration})
except Exception as _e:
print(f"[SupaVoice] Server routes failed to register: {_e}")