설치형 로컬 TTS를 MeloTTS 한국어(MIT)로 채택하고 엔드포인트로 연결
Higgs Audio v3 는 연구/비상업 라이선스라 config.py 가 environment != dev 에서 차단하고 있었다. 그 가드를 푸는 건 법적 판단이라 코드로 결정할 수 없어서, 상업 사용이 허용된 설치형을 다시 찾아 MeloTTS Korean 으로 바꿨다. 결과적으로 가드를 건드릴 필요 자체가 사라졌다 — Higgs 가드는 그대로 두고 provider 만 melotts 로 두면 운영에서도 동작한다. 검토 결과: - MeloTTS MIT 한국어 지원 -> 채택. CPU 실시간, 사전학습 다화자 - Kokoro-82M Apache2.0 한국어 없음 -> 탈락. 공식 VOICES.md 언어 목록에 부재 - Piper GPL -> 탈락 - XTTS-v2 / Fish Speech 비상업 -> 탈락. Higgs 와 같은 문제 사전학습 다화자 모델이라 실존 인물 reference 를 쓰지 않는다. Higgs 경로가 P1 프리셋 한정이던 이유가 없으므로 모든 페르소나 프리셋에 적용된다. 구현: - scripts/melotts-server.py loopback HTTP 사이드카(/health, POST /tts -> WAV) - voice_tts_provider=melotts 경로와 VIGNETTE_MELOTTS_TTS_* 설정 - scripts/start-melotts.ps1 런처(설치 순서 안내 포함) 실측: - CPU 정상 상태 RTF 0.27~0.28(실시간 3.6배). 첫 실행 13.25 는 모델 다운로드 - POST /tts 200, WAV 350,566 bytes, 3.61s, 헤더 provider/model/license - 빈 텍스트 422, 미지 경로 404 로 fail-closed - 왕복 검증: MeloTTS 합성음을 로컬 faster-whisper 가 완전 일치 전사 "그렇게 느끼셨군요. 조금 더 이야기해 주실 수 있을까요?" (word timestamp 8개) 설치 함정 3가지를 decisions/local-voice-stack.md 에 남겼다. librosa 0.9.1 의 pkg_resources(setuptools<81), MeloTTS 가 언어와 무관하게 임포트하는 일본어 unidic 사전, Windows 한국어 g2p 의 eunjeon. G7 게이트의 TTS 허용목록에 melotts 를 추가했다. 선언/실제 불일치 차단과 배치 STT 배제는 그대로다. 검증: API 914 passed, 사이드카 melotts 16/16 + whisper 37/37, SSOT FAIL 0, ruff clean.
This commit is contained in:
parent
05aa7b312e
commit
2624d49984
15 changed files with 749 additions and 33 deletions
|
|
@ -42,6 +42,8 @@ OPENAI_BASE_URL = "https://api.openai.com/v1"
|
|||
STT_ENDPOINT = "/audio/transcriptions"
|
||||
TTS_ENDPOINT = "/audio/speech"
|
||||
HIGGS_TTS_ENDPOINT = "/tts"
|
||||
MELOTTS_TTS_ENDPOINT = "/tts"
|
||||
MELOTTS_TTS_MODEL = "melotts-korean"
|
||||
DEEPGRAM_STT_URL = "wss://api.deepgram.com/v1/listen"
|
||||
DEEPGRAM_STT_MODEL = "nova-3"
|
||||
|
||||
|
|
@ -919,6 +921,8 @@ class VoiceService:
|
|||
local_whisper_utterance_end_ms: Optional[int] = None,
|
||||
local_whisper_finalize_timeout_seconds: Optional[float] = None,
|
||||
local_whisper_connect: Optional[Callable[..., Awaitable[Any]]] = None,
|
||||
melotts_base_url: Optional[str] = None,
|
||||
melotts_timeout_seconds: Optional[float] = None,
|
||||
) -> None:
|
||||
self._api_key = (api_key if api_key is not None else settings.openai_api_key) or ""
|
||||
self._base_url = (base_url or settings.openai_base_url or OPENAI_BASE_URL).rstrip("/")
|
||||
|
|
@ -1025,6 +1029,20 @@ class VoiceService:
|
|||
),
|
||||
)
|
||||
self._local_whisper_connect = local_whisper_connect or websocket_connect
|
||||
self._melotts_base_url = (
|
||||
melotts_base_url
|
||||
if melotts_base_url is not None
|
||||
else settings.melotts_tts_url
|
||||
).rstrip("/")
|
||||
self._melotts_timeout_seconds = max(
|
||||
1.0,
|
||||
float(
|
||||
melotts_timeout_seconds
|
||||
if melotts_timeout_seconds is not None
|
||||
else settings.melotts_tts_timeout_seconds
|
||||
),
|
||||
)
|
||||
self._melotts_client: httpx.AsyncClient | None = None
|
||||
self._tts_provider = (
|
||||
tts_provider if tts_provider is not None else settings.voice_tts_provider
|
||||
).strip().lower()
|
||||
|
|
@ -1069,6 +1087,11 @@ class VoiceService:
|
|||
base_url=self._higgs_base_url,
|
||||
timeout=httpx.Timeout(self._higgs_timeout_seconds, connect=3.0),
|
||||
)
|
||||
if self._melotts_enabled():
|
||||
self._melotts_client = httpx.AsyncClient(
|
||||
base_url=self._melotts_base_url,
|
||||
timeout=httpx.Timeout(self._melotts_timeout_seconds, connect=3.0),
|
||||
)
|
||||
|
||||
async def shutdown(self) -> None:
|
||||
if self._client is not None:
|
||||
|
|
@ -1077,6 +1100,9 @@ class VoiceService:
|
|||
if self._higgs_client is not None:
|
||||
await self._higgs_client.aclose()
|
||||
self._higgs_client = None
|
||||
if self._melotts_client is not None:
|
||||
await self._melotts_client.aclose()
|
||||
self._melotts_client = None
|
||||
|
||||
def is_available(self) -> bool:
|
||||
"""마이크 캐스케이드(STT+TTS) 전체 가용 여부."""
|
||||
|
|
@ -1240,6 +1266,8 @@ class VoiceService:
|
|||
)
|
||||
|
||||
def tts_available(self, voice: VoicePreset | None = None) -> bool:
|
||||
if self._melotts_enabled():
|
||||
return True
|
||||
if self._higgs_enabled() and (voice is None or self._should_use_higgs_tts(voice)):
|
||||
return True
|
||||
if self._poc_sample_tts_available():
|
||||
|
|
@ -1247,6 +1275,8 @@ class VoiceService:
|
|||
return bool(self._api_key)
|
||||
|
||||
def tts_provider(self) -> str:
|
||||
if self._melotts_enabled():
|
||||
return "melotts"
|
||||
if self._higgs_enabled():
|
||||
return "higgs"
|
||||
if self._poc_sample_tts_available():
|
||||
|
|
@ -1260,6 +1290,8 @@ class VoiceService:
|
|||
return "unavailable"
|
||||
|
||||
def tts_provider_for_voice(self, voice: VoicePreset) -> str:
|
||||
if self._should_use_melotts_tts(voice):
|
||||
return "melotts"
|
||||
if self._should_use_higgs_tts(voice):
|
||||
return "higgs"
|
||||
if self._should_use_poc_sample_tts(voice):
|
||||
|
|
@ -1267,14 +1299,27 @@ class VoiceService:
|
|||
return "openai" if self._api_key else "unavailable"
|
||||
|
||||
def tts_model_for_voice(self, voice: VoicePreset) -> str:
|
||||
if self._should_use_melotts_tts(voice):
|
||||
return MELOTTS_TTS_MODEL
|
||||
return HIGGS_TTS_MODEL if self._should_use_higgs_tts(voice) else TTS_MODEL
|
||||
|
||||
def tts_media_type_for_voice(self, voice: VoicePreset) -> str:
|
||||
return "audio/wav" if self._should_use_higgs_tts(voice) else "audio/mpeg"
|
||||
if self._should_use_melotts_tts(voice) or self._should_use_higgs_tts(voice):
|
||||
return "audio/wav"
|
||||
return "audio/mpeg"
|
||||
|
||||
def _higgs_enabled(self) -> bool:
|
||||
return self._tts_provider == "higgs" and self._environment == "dev"
|
||||
|
||||
def _melotts_enabled(self) -> bool:
|
||||
# MIT 라이선스라 환경 제한이 없다. Higgs 와 달리 운영에서도 쓸 수 있다.
|
||||
return self._tts_provider == "melotts" and bool(self._melotts_base_url)
|
||||
|
||||
def _should_use_melotts_tts(self, voice: VoicePreset) -> bool:
|
||||
# 사전학습 다화자 모델이라 프리셋별 reference 제약이 없다.
|
||||
del voice
|
||||
return self._melotts_enabled()
|
||||
|
||||
def _should_use_higgs_tts(self, voice: VoicePreset) -> bool:
|
||||
# 현재 권리 안전한 synthetic reference는 P1 서연 프리셋만 보유한다.
|
||||
return self._higgs_enabled() and voice.preset == POC_SAMPLE_TTS_PRESET
|
||||
|
|
@ -1387,6 +1432,10 @@ class VoiceService:
|
|||
text = speakable_text(text)
|
||||
if not text:
|
||||
return
|
||||
if self._should_use_melotts_tts(voice):
|
||||
async for chunk in self._synthesize_melotts_tts(text, voice):
|
||||
yield chunk
|
||||
return
|
||||
if self._should_use_higgs_tts(voice):
|
||||
async for chunk in self._synthesize_higgs_tts(text, voice):
|
||||
yield chunk
|
||||
|
|
@ -1441,6 +1490,41 @@ class VoiceService:
|
|||
if chunk:
|
||||
yield TTSChunk(audio=chunk)
|
||||
|
||||
@property
|
||||
def _melotts_http(self) -> httpx.AsyncClient:
|
||||
if not self._melotts_enabled():
|
||||
raise VoiceUnavailable("MeloTTS provider is not configured")
|
||||
if self._melotts_client is None:
|
||||
self._melotts_client = httpx.AsyncClient(
|
||||
base_url=self._melotts_base_url,
|
||||
timeout=httpx.Timeout(self._melotts_timeout_seconds, connect=3.0),
|
||||
)
|
||||
return self._melotts_client
|
||||
|
||||
async def _synthesize_melotts_tts(
|
||||
self, text: str, voice: VoicePreset
|
||||
) -> AsyncIterator[TTSChunk]:
|
||||
payload = {"text": speakable_text(text), "speed": _clamp_speed(voice.rate)}
|
||||
try:
|
||||
async with self._melotts_http.stream(
|
||||
"POST", MELOTTS_TTS_ENDPOINT, json=payload
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
async for chunk in response.aiter_bytes(
|
||||
chunk_size=POC_SAMPLE_TTS_CHUNK_SIZE
|
||||
):
|
||||
if chunk:
|
||||
yield TTSChunk(audio=chunk)
|
||||
except httpx.HTTPStatusError as exc:
|
||||
body = ""
|
||||
try:
|
||||
body = (await exc.response.aread()).decode("utf-8", "ignore")[:200]
|
||||
except Exception:
|
||||
pass
|
||||
raise RuntimeError(f"MeloTTS {exc.response.status_code}: {body}") from exc
|
||||
except httpx.HTTPError as exc:
|
||||
raise RuntimeError(f"MeloTTS transport error: {exc}") from exc
|
||||
|
||||
async def _synthesize_higgs_tts(
|
||||
self, text: str, voice: VoicePreset
|
||||
) -> AsyncIterator[TTSChunk]:
|
||||
|
|
@ -1529,6 +1613,7 @@ __all__ = [
|
|||
"TranscriptWord",
|
||||
"StreamingTranscriptEvent",
|
||||
"DeepgramStreamingSession",
|
||||
"MELOTTS_TTS_MODEL",
|
||||
"LocalWhisperStreamingSession",
|
||||
"EndOfTurnDecision",
|
||||
"TTSChunk",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue