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
DashScope CosyVoice TTS raises RuntimeError from push() when you push incremental text deltas for realtime synthesis before the underlying realtime session is connected. The model requires connect() to establish the websocket session first.
Source
Thrown at src/agentscope/tts/_dashscope/_cosyvoice_model.py:230
except Exception:
pass
self._connected = False
self._cold_start_buffer = ""
self._cold_start_done = False
await self.connect()
async def push(
self,
text: str,
**kwargs: Any,
) -> TTSResponse:
"""Push an incremental text delta for realtime synthesis."""
del kwargs
if not self.realtime:
return await super().push(text)
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 self._cold_start_done:
text_to_send = text
else:
self._cold_start_buffer += text
if (
self.cold_start_length
and len(self._cold_start_buffer) < self.cold_start_length
) or (
self.cold_start_words
and len(self._cold_start_buffer.split())View on GitHub (pinned to e90f1c7592)
Solutions
- Call `await model.connect()` and await it fully before the first push()
- After any disconnect or error, re-run connect() before pushing again
- If you don't need streaming, construct/use the model without realtime mode so push() goes through the non-realtime path
Example fix
# before
async for delta in stream:
resp = await tts.push(delta) # RuntimeError: not connected
# after
await tts.connect()
async for delta in stream:
resp = await tts.push(delta) Defensive patterns
Strategy: validation
Validate before calling
if not tts._connected:
await tts.connect()
resp = await tts.push(delta) Try / catch
try:
resp = await tts.push(delta)
except RuntimeError as e:
if 'not connected' in str(e):
await tts.connect()
resp = await tts.push(delta)
else:
raise Prevention
- Await connect() in the same async setup that creates the TTS model
- Track session state and reconnect before pushing after any error/disconnect
When it happens
Trigger: Calling await model.push(delta) with realtime=True before ever calling await model.connect(), or after disconnect()/a dropped session (the _connected flag is False).
Common situations: Streaming pipelines that start pushing text immediately without awaiting connect(); reconnect logic that forgets to re-connect after a drop; using the realtime code path when you meant one-shot synthesize (which doesn't need a session).
Related errors
- CosyVoice TTS synthesis timed out after 30s
- CosyVoice TTS synthesis failed: no audio after {self.max_ret
- TTS synthesis failed: no audio after {self.max_retries} atte
- TTS model is not connected. Call `connect()` first.
- Text embedding model {self.model!r} only accepts str inputs,
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/1a489575b2c65e6c.
Report an issue: GitHub.