feat(tts): speech toggles warm up and unload local TTS engines (#100881)
Desktop "Read replies aloud" / voice conversation, TUI and CLI /voice tts now hold a lease on the TTS engine. Acquiring pre-loads the configured provider (piper/kittentts model into the same LRU slot synthesis reads; lazily-installed cloud SDKs), so the first spoken reply no longer pays the model load as dead air. Releasing the last lease across surfaces unloads resident local models. - tools/tts_tool.py: warm_tts_provider / release_tts_provider / acquire_tts_lease / release_tts_lease over a _LOCAL_TTS_MODEL_CACHES registry; piper/kittentts loaders extracted so warm-up and synthesis share one resolution path. - web_server: POST /api/audio/tts-lease (profile-scoped, off-loop, failures reported in body never as HTTP errors). - tui_gateway voice.toggle + cli.py /voice tts|on|off wire the lease. - desktop: lib/tts-lease.ts (dedupe, per-lease serialization, latest intent wins) driven from useComposerVoice; setTtsLease API client. - docs: features/tts.md section. Live (real piper, isolated HERMES_HOME): first synthesis 988ms cold → 92ms after the toggle warmed the engine; release drops the model.
This commit is contained in:
@@ -15765,6 +15765,10 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
|
||||
# _voice_message_prefix property and its usage in _process_message().
|
||||
|
||||
tts_status = " (TTS enabled)" if self._voice_tts else ""
|
||||
if self._voice_tts:
|
||||
# Speech output is on from the start — warm the engine now so the
|
||||
# first spoken reply doesn't pay the model load as dead air.
|
||||
self._tts_lease_async(True)
|
||||
# Use the startup-pinned cache so the advertised shortcut always
|
||||
# matches the live prompt_toolkit binding — reading live config
|
||||
# here would drift after a mid-session config edit (Copilot
|
||||
@@ -15823,6 +15827,11 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
|
||||
self._voice_tts = False
|
||||
self._voice_continuous = False
|
||||
|
||||
# Speech output is off with the mode — release the TTS engine lease so
|
||||
# a resident local model (piper/kittentts) is freed once nothing else
|
||||
# in this process still needs it.
|
||||
self._tts_lease_async(False)
|
||||
|
||||
# Shut down the persistent audio stream in background
|
||||
if recorder is not None:
|
||||
def _bg_shutdown(rec=recorder):
|
||||
@@ -16070,6 +16079,29 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
|
||||
if not owned:
|
||||
_cprint(f" {_DIM}Enable with /wake on{_RST}")
|
||||
|
||||
def _tts_lease_async(self, active: bool) -> None:
|
||||
"""Acquire/release this CLI's TTS engine lease in the background.
|
||||
|
||||
The /voice tts toggle (and voice-mode on/off with speech output set)
|
||||
is the "TTS is about to be needed / no longer needed" signal:
|
||||
acquiring pre-loads the configured provider so the first reply starts
|
||||
hot; releasing lets the last-holder path unload resident local models.
|
||||
Never blocks the toggle and never fails it.
|
||||
"""
|
||||
|
||||
def _run():
|
||||
try:
|
||||
from tools.tts_tool import acquire_tts_lease, release_tts_lease
|
||||
|
||||
if active:
|
||||
acquire_tts_lease("cli:voice-tts")
|
||||
else:
|
||||
release_tts_lease("cli:voice-tts")
|
||||
except Exception as e:
|
||||
logger.debug("voice: tts lease active=%s failed: %s", active, e)
|
||||
|
||||
threading.Thread(target=_run, name="tts-lease-cli", daemon=True).start()
|
||||
|
||||
def _toggle_voice_tts(self):
|
||||
"""Toggle TTS output for voice mode."""
|
||||
if not self._voice_mode:
|
||||
@@ -16085,6 +16117,10 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
|
||||
if not check_tts_requirements():
|
||||
_cprint(f"{_DIM}Warning: No TTS provider available. Install edge-tts or set API keys.{_RST}")
|
||||
|
||||
# Toggle = warm-up / release signal for the TTS engine (see
|
||||
# tools.tts_tool.acquire_tts_lease).
|
||||
self._tts_lease_async(self._voice_tts)
|
||||
|
||||
_cprint(f"{_ACCENT}Voice TTS {status}.{_RST}")
|
||||
|
||||
def _show_voice_status(self):
|
||||
|
||||
Reference in New Issue
Block a user