Skip to content

The agent that grows with you

fix: pin tts.streaming.min_len at the speaker and speak-stream entry points

teknium186bb3eb7c571
diff --git a/tests/hermes_cli/test_web_server_speak_stream.py b/tests/hermes_cli/test_web_server_speak_stream.py
index 33a9e079527..1d44bf4e4ac 100644
--- a/tests/hermes_cli/test_web_server_speak_stream.py
+++ b/tests/hermes_cli/test_web_server_speak_stream.py
@@ -77,6 +77,25 @@ def test_streams_pcm_frames_then_end(stream_client, monkeypatch):
assert streamer.requests == ["Hello there."]
+def test_short_cjk_opener_is_synthesized_alone_with_configured_min_len(stream_client, monkeypatch):
+ """speak_stream_ws cuts with the requesting profile's tts.streaming.min_len (#96927): a 7-char
+ CJK opener gets its own provider request instead of riding behind the second sentence."""
+ streamer = _FakeStreamer([b"\x00\x00"])
+ _patch_provider(monkeypatch, streamer)
+ monkeypatch.setattr("tools.tts_tool._load_tts_config", lambda: {"streaming": {"min_len": 6}})
+
+ with stream_client.websocket_connect(_url()) as conn:
+ assert conn.receive_json()["type"] == "start"
+ conn.send_text(json.dumps({"text": "记得,叫团团. 然后我们再说第二句话,这一句要长一些才行. ", "done": True}))
+ while True:
+ message = conn.receive()
+ if message.get("bytes") is None:
+ assert json.loads(message["text"]) == {"type": "end"}
+ break
+
+ assert streamer.requests[0] == "记得,叫团团.", streamer.requests
+
+
diff --git a/tests/tools/test_tts_streaming.py b/tests/tools/test_tts_streaming.py
index 3a4e5e35409..da901daba6f 100644
--- a/tests/tools/test_tts_streaming.py
+++ b/tests/tools/test_tts_streaming.py
@@ -44,16 +44,6 @@ class TestSentenceChunker:
"A paragraph without punctuation\n\n"
]
- def test_from_config_reads_streaming_min_len(self):
- """tts.streaming.min_len decides whether a short CJK opener is spoken alone (#96927);
- unset/invalid keep the English default of 20, 0 floors to 1."""
- assert ts.SentenceChunker.from_config({}).min_len == 20
- assert ts.SentenceChunker.from_config({"streaming": {"min_len": "abc"}}).min_len == 20
- assert ts.SentenceChunker.from_config({"streaming": {"min_len": 0}}).min_len == 1
- c = ts.SentenceChunker.from_config({"streaming": {"min_len": 6}})
- assert c.feed("记得,叫团团. ") == ["记得,叫团团. "]
- assert ts.SentenceChunker().feed("记得,叫团团. ") == []
-
# ── Interruption latch ───────────────────────────────────────────────────
@@ -539,6 +529,43 @@ def test_hybrid_first_sentence_streamed_individually(monkeypatch):
assert done.is_set()
+ sys.platform == "darwin",
+ reason="macOS deliberately skips the sounddevice OutputStream path (PR #62601)",
+)
+def test_speaker_honours_tts_streaming_min_len_for_short_cjk_opener(monkeypatch):
+ """The CLI/TUI speaker cuts with the profile's tts.streaming.min_len (#96927): a 7-char CJK
+ opener is streamed on its own instead of riding behind the second sentence."""
+ from tools import tts_tool
+ from tools.tts_tool_speaker import stream_tts_to_speaker
+
+ stream_calls: list[str] = []
+
+ class _Tracking(ts.StreamingTTSProvider):
+ sample_rate = 24000
+
+ @staticmethod
+ def available():
+ return True
+
+ def stream(self, text):
+ stream_calls.append(text)
+ yield b"\x00\x00" * 10
+
+ sd, _out = _sd_mock()
+ q = _drain_queue(["记得,叫团团. ", "然后我们再说第二句话,这一句要长一些才行. "])
+ stop, done = threading.Event(), threading.Event()
+
+ with patch("tools.tts_streaming.resolve_streaming_provider",
+ return_value=_Tracking({}, {})), \
+ patch.object(tts_tool, "_load_tts_config", return_value={"streaming": {"min_len": 6}}), \
+ patch.object(tts_tool, "_import_sounddevice", return_value=sd):
+ stream_tts_to_speaker(q, stop, done)
+
+ assert stream_calls[0] == "记得,叫团团.", stream_calls
+ assert done.is_set()
+
+
@pytest.mark.skipif(
sys.platform == "darwin",
reason="macOS deliberately skips the sounddevice OutputStream path (PR #62601)",