{"record":{"id":"60b60a598c391391","repo":"agentscope-ai/agentscope","slug":"tts-model-is-not-connected-call-connect-first-60b60a","errorCode":null,"errorMessage":"TTS model is not connected. Call `connect()` first.","messagePattern":"TTS model is not connected\\. Call `connect\\(\\)` first\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/tts/_dashscope/_realtime_model.py","lineNumber":326,"sourceCode":"        text: str,\n        **kwargs: Any,\n    ) -> TTSResponse:\n        \"\"\"Push an incremental text delta for realtime synthesis.\n\n        Args:\n            text (`str`):\n                An incremental text chunk (delta) to append.\n            **kwargs (`Any`):\n                Additional keyword arguments (unused).\n\n        Returns:\n            `TTSResponse`:\n                Audio accumulated so far, or empty if not yet available.\n        \"\"\"\n        from websocket import WebSocketConnectionClosedException\n\n        if not self._connected:\n            raise RuntimeError(\n                \"TTS model is not connected. Call `connect()` first.\",\n            )\n\n        if not text:\n            return TTSResponse(content=None)\n\n        self._accumulated_text += text\n\n        if not self._cold_start_done:\n            self._cold_start_buffer += text\n            ready = True\n            if (\n                self.cold_start_length\n                and len(self._cold_start_buffer) < self.cold_start_length\n            ):\n                ready = False\n            if (\n                ready","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/tts/_dashscope/_realtime_model.py#L308-L344","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nawait model.push(\"hello\")\n\n# after\nif not model.is_connected():\n    await model.connect()\nawait model.push(\"hello\")","handlingStrategy":"validation","validationCode":"if not model.is_connected():\n    await model.connect()\nawait model.push(text)","typeGuard":null,"tryCatchPattern":"try:\n    await model.push(text)\nexcept RuntimeError as e:\n    if \"not connected\" in str(e):\n        await model.connect()\n        await model.push(text)\n    else:\n        raise","preventionTips":["Always connect() in the agent's startup hook and disconnect() on teardown.","Treat connect() failures as fatal; don't proceed in except: pass."],"tags":["tts","realtime","websocket","not-connected","precondition"],"backgroundTag":"connection-not-initialized","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}