Skip to content

The agent that grows with you

refactor(tools): wrap over-long tts call lines (AST-neutral)

Teknium636bf247e8da
diff --git a/tools/tts_tool.py b/tools/tts_tool.py
index 9b82f51632a..5a78e3196d5 100644
--- a/tools/tts_tool.py
+++ b/tools/tts_tool.py
@@ -355,7 +355,8 @@ def _text_to_speech_single(
try:
if command_provider_config is not None:
logger.info("Generating speech with command TTS provider '%s'...", provider)
- file_str = _generate_command_tts(text, file_str, provider, command_provider_config, tts_config)
+ file_str = _generate_command_tts(
+ text, file_str, provider, command_provider_config, tts_config)
elif provider not in BUILTIN_TTS_PROVIDERS and (
_plugin_path := _dispatch_to_plugin_provider(text, file_str, provider, tts_config)
) is not None:
@@ -370,7 +371,8 @@ def _text_to_speech_single(
# Sniff once for every provider: MP3/WAV bytes in a .ogg path render as 0-second bubbles.
file_str = _repair_ogg_container(file_str)
- file_str, voice_compatible = _finalize_voice_delivery(file_str, provider, command_provider_config, want_opus)
+ file_str, voice_compatible = _finalize_voice_delivery(
+ file_str, provider, command_provider_config, want_opus)
logger.info("TTS audio saved: %s (%s bytes, provider: %s)", file_str, f"{os.path.getsize(file_str):,}", provider)
return json.dumps({
"success": True, "file_path": file_str, "media_tag": _media_tag([file_str], voice_compatible),
@@ -446,7 +448,8 @@ def text_to_speech_tool(
provider, len(chunks), len(text), max_len)
platform, want_opus = _session_platform()
delivery_profile = _resolve_audio_delivery_profile(platform, tts_config)
- base_path, error = _resolve_output_base(output_path, provider, command_provider_config, want_opus)
+ base_path, error = _resolve_output_base(
+ output_path, provider, command_provider_config, want_opus)
if error:
return error
generated_artifacts: set[str] = set()
diff --git a/tools/tts_tool_delivery.py b/tools/tts_tool_delivery.py
index 0abba118ecd..f823e06101c 100644
--- a/tools/tts_tool_delivery.py
+++ b/tools/tts_tool_delivery.py
@@ -252,7 +252,9 @@ def _finalize_wav_output(wav_path: str, output_path: str) -> str:
return output_path
ffmpeg = shutil.which("ffmpeg")
if ffmpeg:
- _ffmpeg_run(ffmpeg, ["-i", wav_path, "-y", "-loglevel", "error", output_path], check=True, capture=False)
+ _ffmpeg_run(
+ ffmpeg, ["-i", wav_path, "-y", "-loglevel", "error", output_path], check=True,
+ capture=False)
_remove_quietly(wav_path)
else:
os.rename(wav_path, output_path)
@@ -288,7 +290,8 @@ def _write_wav_bytes_as(wav_bytes: bytes, output_path: str) -> str:
ffmpeg = shutil.which("ffmpeg")
if ffmpeg:
opus = _OPUS_VOICE_ARGS if output_path.lower().endswith(".ogg") else []
- result = _ffmpeg_run(ffmpeg, ["-i", wav_path, *opus, "-y", "-loglevel", "error", output_path])
+ result = _ffmpeg_run(
+ ffmpeg, ["-i", wav_path, *opus, "-y", "-loglevel", "error", output_path])
if result.returncode != 0:
stderr = result.stderr.decode("utf-8", errors="ignore")[:300]
raise RuntimeError(f"ffmpeg conversion failed: {stderr}")
diff --git a/tools/tts_tool_local.py b/tools/tts_tool_local.py
index ffa2e93557d..beb42c7172f 100644
--- a/tools/tts_tool_local.py
+++ b/tools/tts_tool_local.py
@@ -33,7 +33,8 @@ _TTS_MODEL_CACHE_MAX = 3
# (+cuda flag); KittenTTS on model name.
_piper_voice_cache: Dict[str, Any] = {}
_kittentts_model_cache: Dict[str, Any] = {}
-_LOCAL_TTS_MODEL_CACHES: Dict[str, Dict[str, Any]] = {"piper": _piper_voice_cache, "kittentts": _kittentts_model_cache}
+_LOCAL_TTS_MODEL_CACHES: Dict[str, Dict[str, Any]] = {
+ "piper": _piper_voice_cache, "kittentts": _kittentts_model_cache}
def _tts_cache_get_or_load(cache: Dict[str, Any], key: str, load: Callable[[], Any]) -> Any:
diff --git a/tools/tts_tool_providers.py b/tools/tts_tool_providers.py
index 42a5d3d26bf..5420bbf549b 100644
--- a/tools/tts_tool_providers.py
+++ b/tools/tts_tool_providers.py
@@ -309,7 +309,8 @@ def _generate_xai_tts(text: str, output_path: str, tts_config: Dict[str, Any]) -
optimize_streaming_latency = _clamped_number(
xai_config.get("optimize_streaming_latency", tts_config.get("optimize_streaming_latency")),
int, 0, 2)
- text_normalization = _config_bool(xai_config.get("text_normalization"), DEFAULT_XAI_TEXT_NORMALIZATION_DEFAULT)
+ text_normalization = _config_bool(
+ xai_config.get("text_normalization"), DEFAULT_XAI_TEXT_NORMALIZATION_DEFAULT)
if creds.get("provider") == "xai-oauth":
base_url = creds.get("base_url")
else:
@@ -571,7 +572,8 @@ def _generate_gemini_tts(text: str, output_path: str, tts_config: Dict[str, Any]
tts_script = text
if _gemini_audio_tags_enabled(gemini_config, model):
tts_script = _rewrite_gemini_tts_audio_tags(text, persona_prompt=persona_prompt)
- prompt_text = _compose_gemini_tts_prompt(tts_script, gemini_config, persona_prompt=persona_prompt)
+ prompt_text = _compose_gemini_tts_prompt(
+ tts_script, gemini_config, persona_prompt=persona_prompt)
max_len = origin._resolve_max_text_length("gemini", tts_config)
if len(prompt_text) > max_len:
raise ValueError(
diff --git a/tools/tts_tool_speaker.py b/tools/tts_tool_speaker.py
index 15810b65c2f..32bc8e524ce 100644
--- a/tools/tts_tool_speaker.py
+++ b/tools/tts_tool_speaker.py
@@ -154,7 +154,8 @@ class _StreamerPlayback:
def _create_output_stream(self):
sd = _origin()._import_sounddevice()
- stream = sd.OutputStream(samplerate=self.streamer.sample_rate, channels=self.streamer.channels, dtype="int16")
+ stream = sd.OutputStream(
+ samplerate=self.streamer.sample_rate, channels=self.streamer.channels, dtype="int16")
stream.start()
return stream
@@ -207,7 +208,8 @@ class _StreamerPlayback:
self._prefetch_sem.release()
def _play_sentence_via_tempfile(self, chunk_queue) -> None:
- _play_via_tempfile(iter(_drain_chunks(chunk_queue)), self.stop_event, self.streamer.sample_rate)
+ _play_via_tempfile(
+ iter(_drain_chunks(chunk_queue)), self.stop_event, self.streamer.sample_rate)
def _for_each_sentence(self, play: Callable[[queue.Queue], None]) -> None:
"""Feed queued sentences to *play* in order until the end sentinel; stopped sentences are skipped."""
@@ -305,7 +307,8 @@ def stream_tts_to_speaker(
sync_pipeline = _SyncSentencePipeline(stop_event)
else:
with contextlib.suppress(Exception):
- stream_max_len = origin._resolve_max_text_length(provider or origin._get_provider(tts_config), tts_config)
+ stream_max_len = origin._resolve_max_text_length(
+ provider or origin._get_provider(tts_config), tts_config)
playback = _StreamerPlayback(streamer, stop_event)
chunker = SentenceChunker()
spoken_sentences: list[str] = [] # skip duplicate/near-duplicate sentences (LLM repetition)