agentscope-ai/agentscope · error · RuntimeError
TTS model is not connected. Call `connect()` first.
Error message
TTS model is not connected. Call `connect()` first.
What it means
push() was called on the realtime DashScope TTS model before connect() established the websocket. The model guards public methods with a _connected flag; push() checks it before sending text frames and raises RuntimeError.
Source
Thrown at src/agentscope/tts/_dashscope/_realtime_model.py:326
text: str,
**kwargs: Any,
) -> TTSResponse:
"""Push an incremental text delta for realtime synthesis.
Args:
text (`str`):
An incremental text chunk (delta) to append.
**kwargs (`Any`):
Additional keyword arguments (unused).
Returns:
`TTSResponse`:
Audio accumulated so far, or empty if not yet available.
"""
from websocket import WebSocketConnectionClosedException
if not self._connected:
raise RuntimeError(
"TTS model is not connected. Call `connect()` first.",
)
if not text:
return TTSResponse(content=None)
self._accumulated_text += text
if not self._cold_start_done:
self._cold_start_buffer += text
ready = True
if (
self.cold_start_length
and len(self._cold_start_buffer) < self.cold_start_length
):
ready = False
if (
readyView on GitHub (pinned to e90f1c7592)
Solutions
- Call await model.connect() (and await it successfully) before push().
- Check model.is_connected() (or the _connected state via public API) before pushing.
- Wrap connect() in try/except and abort the workflow if it fails instead of continuing.
- If connection dropped, reconnect before pushing.
Example fix
# before
await model.push("hello")
# after
if not model.is_connected():
await model.connect()
await model.push("hello") Defensive patterns
Strategy: validation
Validate before calling
if not model.is_connected():
await model.connect()
await model.push(text) Try / catch
try:
await model.push(text)
except RuntimeError as e:
if "not connected" in str(e):
await model.connect()
await model.push(text)
else:
raise Prevention
- Always connect() in the agent's startup hook and disconnect() on teardown.
- Treat connect() failures as fatal; don't proceed in except: pass.
When it happens
Trigger: Calling await model.push(text) (or interrupt/clear flows that route through push) without a prior successful await model.connect(), or after the connection dropped and _connected became False.
Common situations: Forgetting connect() in async startup code, connect() failing silently in a try block and the caller continuing, or using the model after a disconnect/reconnect cycle.
Related errors
- TTS synthesis failed: no audio after {self.max_retries} atte
- TTS model is not connected. Call `connect()` first.
- CosyVoice TTS synthesis timed out after 30s
- CosyVoice TTS synthesis failed: no audio after {self.max_ret
- Feishu channel requires 'lark-oapi' (pip install lark-oapi).
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/60b60a598c391391.
Report an issue: GitHub.