From 01262a79eb36ffe4bab6fcb5f94b52744d4e1a59 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 3 Sep 2026 01:21:30 -0700 Subject: [PATCH] refactor(tools): fold sniff/read into one with-block, lifecycle timing locals --- tools/tts_tool_delivery.py | 5 ++--- tools/tts_tool_lifecycle.py | 3 +-- tools/tts_tool_speaker.py | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/tts_tool_delivery.py b/tools/tts_tool_delivery.py index 44ac43c5e7..bae7da2bf0 100644 --- a/tools/tts_tool_delivery.py +++ b/tools/tts_tool_delivery.py @@ -335,10 +335,9 @@ def _sniff_audio_container(path: str) -> str: from tools.audio_container import sniff_container try: with open(path, "rb") as fh: - head = fh.read(12) + return sniff_container(fh.read(12)) or "unknown" except OSError: return "unknown" - return sniff_container(head) or "unknown" def _repair_ogg_container(file_str: str) -> str: @@ -351,7 +350,7 @@ def _repair_ogg_container(file_str: str) -> str: repaired = _ffmpeg_transcode_to_opus(file_str, file_str) if repaired: return repaired - honest = file_str[:-4] + "." + container + honest = f"{file_str[:-4]}.{container}" try: os.replace(file_str, honest) except OSError: diff --git a/tools/tts_tool_lifecycle.py b/tools/tts_tool_lifecycle.py index 37b7ecb766..4df1f1bb6a 100644 --- a/tools/tts_tool_lifecycle.py +++ b/tools/tts_tool_lifecycle.py @@ -89,8 +89,7 @@ def warm_tts_provider(tts_config: Optional[Dict[str, Any]] = None, provider: Opt warmer = _local_tts_warmers().get(name) if warmer is not None: cache = _LOCAL_TTS_MODEL_CACHES.get(name, {}) - before = len(cache) - started = time.monotonic() + before, started = len(cache), time.monotonic() try: warmer(tts_config) except Exception as exc: # engine missing, download failed, bad voice… diff --git a/tools/tts_tool_speaker.py b/tools/tts_tool_speaker.py index bb764d7e8c..f095b46aec 100644 --- a/tools/tts_tool_speaker.py +++ b/tools/tts_tool_speaker.py @@ -183,8 +183,8 @@ class _StreamerPlayback: self._prefetch_sem.acquire() chunk_queue: "queue.Queue[Optional[bytes]]" = queue.Queue(maxsize=self._CHUNK_QUEUE_MAX) self._audio_queue.put(chunk_queue) - self._prefetch_threads.append( - threading.Thread(target=self._consume_to_queue, args=(audio_iter, chunk_queue), daemon=True)) + self._prefetch_threads.append(threading.Thread( + target=self._consume_to_queue, args=(audio_iter, chunk_queue), daemon=True)) self._prefetch_threads[-1].start() def _consume_to_queue(self, audio_iter: Iterator[bytes], chunk_queue: "queue.Queue[Optional[bytes]]") -> None: