The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tools): iter-sentinel drain, fold ogg repair guard, speaker init tuple, PEP8 blank fix
Teknium5752c2dd68a8
diff --git a/tools/tts_tool_delivery.py b/tools/tts_tool_delivery.pyindex 5cb5cd69172..44ac43c5e7d 100644--- a/tools/tts_tool_delivery.py+++ b/tools/tts_tool_delivery.py@@ -344,9 +344,7 @@ def _sniff_audio_container(path: str) -> str:def _repair_ogg_container(file_str: str) -> str:"""Ensure a ``.ogg`` path really holds Ogg: transcode in place, else rename to the sniffedreal extension so platforms get an honest file instead of a 0-second voice bubble."""- if not file_str.endswith(".ogg"):- return file_str- container = _sniff_audio_container(file_str)+ container = _sniff_audio_container(file_str) if file_str.endswith(".ogg") else "ogg"if container in ("ogg", "unknown"):return file_strlogger.info("TTS wrote %s bytes into a .ogg path (%s) — transcoding to real Ogg/Opus", container, file_str)diff --git a/tools/tts_tool_local.py b/tools/tts_tool_local.pyindex beb42c7172f..96a08d2445a 100644--- a/tools/tts_tool_local.py+++ b/tools/tts_tool_local.py@@ -179,6 +179,7 @@ def _load_kittentts_model_for_config(tts_config: Dict[str, Any]) -> Tuple[Any, Dm = KittenTTS(model_name)logger.info("[KittenTTS] Model loaded successfully")return m+return _tts_cache_get_or_load(_kittentts_model_cache, model_name, _load_kittentts_model), kt_configdiff --git a/tools/tts_tool_providers.py b/tools/tts_tool_providers.pyindex edf27dce890..348a1ef5b8e 100644--- a/tools/tts_tool_providers.py+++ b/tools/tts_tool_providers.py@@ -450,7 +450,7 @@ def _generate_mistral_tts(text: str, output_path: str, tts_config: Dict[str, Anyclient_kwargs: Dict[str, Any] = {"api_key": api_key}if mi_config.get("base_url"):client_kwargs["server_url"] = mi_config["base_url"] # the Mistral SDK calls it server_url- Mistral = _origin()._import_mistral_client()+ Mistral = _origin()._import_mistral_client() # ImportError must escape the RuntimeError wraptry:with Mistral(**client_kwargs) as client:response = client.audio.speech.complete(diff --git a/tools/tts_tool_speaker.py b/tools/tts_tool_speaker.pyindex 43013048b43..bb764d7e8c2 100644--- a/tools/tts_tool_speaker.py+++ b/tools/tts_tool_speaker.py@@ -68,12 +68,7 @@ def _play_via_tempfile(audio_iter: Iterable[bytes], stop_evt: threading.Event, sdef _drain_chunks(chunk_queue: "queue.Queue[Optional[bytes]]") -> List[bytes]:"""Collect one sentence's PCM chunks up to the ``None`` sentinel."""- chunks: List[bytes] = []- while True:- chunk = chunk_queue.get()- if chunk is None:- return chunks- chunks.append(chunk)+ return list(iter(chunk_queue.get, None))class _SyncSentencePipeline:@@ -142,8 +137,7 @@ class _StreamerPlayback:_CHUNK_QUEUE_MAX = 64def __init__(self, streamer, stop_event: threading.Event):- self.streamer = streamer- self.stop_event = stop_event+ self.streamer, self.stop_event = streamer, stop_eventself.output_stream = self._open_output_stream()self._audio_queue: "queue.Queue[Optional[queue.Queue[Optional[bytes]]]]" = queue.Queue()self._prefetch_threads: List[threading.Thread] = []@@ -217,6 +211,7 @@ class _StreamerPlayback:def _write_pcm(self, buf: bytes) -> None:self._current_stream.write(self._np.frombuffer(buf, dtype="<i2").reshape(-1, 1))+def _recover_stream(self) -> bool:"""Close the broken PortAudio stream and open a fresh one after a failed write; False once``_MAX_REINIT`` is exhausted (remaining sentences go through temp files)."""