- app/engines: BaseEngine 인터페이스, MeloEngine(인프로세스), 레지스트리 - /api/engines 추가, /api/tts 에 engine 파라미터 - 프론트: 엔진 → 언어 → 목소리 선택, 라이선스/GPU/조절 지원 표기 - MeloTTS 동작 불변
74 lines
1.8 KiB
Python
74 lines
1.8 KiB
Python
"""엔진 레지스트리.
|
|
|
|
엔진을 lazy 하게 생성하고 id 로 조회한다. 사용 불가한 엔진(전용 venv/모델 미설치)은
|
|
자동으로 목록에서 제외한다.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import threading
|
|
|
|
from .base import BaseEngine
|
|
|
|
_ENGINES: dict[str, BaseEngine] = {}
|
|
_LOCK = threading.Lock()
|
|
_INITED = False
|
|
|
|
|
|
def _build() -> None:
|
|
global _INITED
|
|
if _INITED:
|
|
return
|
|
with _LOCK:
|
|
if _INITED:
|
|
return
|
|
|
|
# MeloTTS (항상 사용 가능)
|
|
try:
|
|
from .melo_engine import MeloEngine
|
|
|
|
e = MeloEngine()
|
|
_ENGINES[e.id] = e
|
|
except Exception as exc: # pragma: no cover
|
|
print(f"[registry] MeloTTS 로드 실패: {exc}")
|
|
|
|
# Coqui GlowTTS-KSS (전용 venv + 체크포인트가 있을 때만)
|
|
try:
|
|
from .coqui_engine import CoquiKssEngine
|
|
|
|
if CoquiKssEngine.available():
|
|
e = CoquiKssEngine()
|
|
_ENGINES[e.id] = e
|
|
except Exception as exc: # pragma: no cover
|
|
print(f"[registry] Coqui 엔진 스킵: {exc}")
|
|
|
|
_INITED = True
|
|
|
|
|
|
def get_engine(engine_id: str) -> BaseEngine:
|
|
_build()
|
|
if engine_id not in _ENGINES:
|
|
raise ValueError(f"알 수 없는 엔진입니다: {engine_id}")
|
|
return _ENGINES[engine_id]
|
|
|
|
|
|
def list_engines() -> list[BaseEngine]:
|
|
_build()
|
|
return list(_ENGINES.values())
|
|
|
|
|
|
def default_engine_id() -> str:
|
|
_build()
|
|
# MeloTTS 우선
|
|
if "melo" in _ENGINES:
|
|
return "melo"
|
|
return next(iter(_ENGINES)) if _ENGINES else ""
|
|
|
|
|
|
def warmup_all() -> None:
|
|
_build()
|
|
for e in _ENGINES.values():
|
|
try:
|
|
e.warmup()
|
|
except Exception as exc: # pragma: no cover
|
|
print(f"[registry] {e.id} warmup 실패: {exc}")
|