22 lines
519 B
Python
22 lines
519 B
Python
from fastapi import APIRouter
|
|
import json
|
|
from pathlib import Path
|
|
|
|
router = APIRouter()
|
|
REG = Path("voices/registry.json")
|
|
|
|
@router.post("/register")
|
|
async def register(data: dict):
|
|
reg = {}
|
|
if REG.exists():
|
|
reg = json.loads(REG.read_text())
|
|
reg[data["name"]] = data
|
|
REG.write_text(json.dumps(reg, indent=2))
|
|
return {"status": "ok", "voices": list(reg.keys())}
|
|
|
|
@router.get("/list")
|
|
async def list_voices():
|
|
if not REG.exists():
|
|
return []
|
|
return json.loads(REG.read_text())
|