From 0a89933f9b44659c03f24cb21f5e8302156d6277 Mon Sep 17 00:00:00 2001 From: 0xbyt4 <35742124+0xbyt4@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:30:12 +0300 Subject: [PATCH] fix: add STT timeout, move finally restart to thread, guard exit on recording MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- cli.py | 16 ++++++++++------ tools/transcription_tools.py | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cli.py b/cli.py index 98476a42..f874448f 100755 --- a/cli.py +++ b/cli.py @@ -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).""" diff --git a/tools/transcription_tools.py b/tools/transcription_tools.py index 7f217bc7..d7c0a84b 100644 --- a/tools/transcription_tools.py +++ b/tools/transcription_tools.py @@ -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(