Spaces:
Sleeping
Sleeping
| 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" | |
| def voice_catalog(): | |
| registry = build_default_registry() | |
| return { | |
| "default_selection": get_voice_selection_store().get(registry), | |
| "models": registry.catalog(), | |
| } | |
| def get_default_voice_selection(): | |
| registry = build_default_registry() | |
| return {"selection": get_voice_selection_store().get(registry)} | |
| 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} | |
| 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", | |
| } | |