fix: add STT timeout, move finally restart to thread, guard exit on recording

- Set OpenAI client timeout=30s in transcribe_audio() — default 600s
  blocks _voice_processing for 10 min if Groq/OpenAI stalls
- Move _voice_start_recording in _voice_stop_and_transcribe finally
  block to a daemon thread (same pattern as Ctrl+B handler and
  process_loop)
- Add _should_exit guard at top of _voice_start_recording so all 4
  call sites respect shutdown without individual checks
This commit is contained in:
0xbyt4 2026-03-10 14:30:12 +03:00
parent bcf4513cb3
commit 0a89933f9b
2 changed files with 11 additions and 7 deletions

16
cli.py
View file

@ -3544,6 +3544,8 @@ class HermesCLI:
def _voice_start_recording(self):
"""Start capturing audio from the microphone."""
if getattr(self, '_should_exit', False):
return
from tools.voice_mode import AudioRecorder, check_voice_requirements
reqs = check_voice_requirements()
@ -3691,12 +3693,14 @@ class HermesCLI:
# (When transcript IS submitted, process_loop handles restart
# after chat() completes.)
if self._voice_continuous and not submitted and not self._voice_recording:
try:
self._voice_start_recording()
if hasattr(self, '_app') and self._app:
self._app.invalidate()
except Exception:
pass
def _restart_recording():
try:
self._voice_start_recording()
if hasattr(self, '_app') and self._app:
self._app.invalidate()
except Exception:
pass
threading.Thread(target=_restart_recording, daemon=True).start()
def _voice_speak_response(self, text: str):
"""Speak the agent's response aloud using TTS (runs in background thread)."""

View file

@ -150,7 +150,7 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> Dict[str, A
try:
from openai import OpenAI, APIError, APIConnectionError, APITimeoutError
client = OpenAI(api_key=api_key, base_url=base_url)
client = OpenAI(api_key=api_key, base_url=base_url, timeout=30)
with open(file_path, "rb") as audio_file:
transcription = client.audio.transcriptions.create(