Spaces:
Sleeping
Sleeping
File size: 1,909 Bytes
2e818da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import os
from fastapi import APIRouter, HTTPException
from app.services.tts_service import build_default_registry
from app.services.voice_selection import VoiceSelectionError, get_voice_selection_store
from app.services.voice_transcription_service import VoiceTranscriptionService
router = APIRouter(prefix="/api/voice", tags=["voice"])
def _is_demo_mode() -> bool:
return os.getenv("DEPLOYMENT_ENV", "desktop") == "demo"
@router.get("/catalog")
def voice_catalog():
registry = build_default_registry()
return {
"default_selection": get_voice_selection_store().get(registry),
"models": registry.catalog(),
}
@router.get("/default-selection")
def get_default_voice_selection():
registry = build_default_registry()
return {"selection": get_voice_selection_store().get(registry)}
@router.put("/default-selection")
def set_default_voice_selection(payload: dict):
registry = build_default_registry()
try:
selection = get_voice_selection_store().set(payload, registry)
except VoiceSelectionError as exc:
raise HTTPException(status_code=422, detail=str(exc)) from exc
return {"selection": selection}
@router.get("/status")
def voice_status():
if _is_demo_mode():
return {
"available": False,
"is_loading": False,
"backend": "disabled",
"model": "disabled",
"compute_type": "disabled",
"tts_backend": "disabled",
"tts_voice": "disabled",
}
service = VoiceTranscriptionService.get()
config = service.model_config
return {
"available": service.is_available,
"is_loading": service.is_model_loading(),
"backend": config.backend,
"model": config.model,
"compute_type": config.compute_type,
"tts_backend": "pocket-tts",
"tts_voice": "anshuman-normal-custom",
}
|