agentscope-ai/agentscope · error · RuntimeError

TTS synthesis failed: no audio after {self.max_retries} atte

Error message

TTS synthesis failed: no audio after {self.max_retries} attempts

What it means

Realtime DashScope TTS synthesis sent the full text but received no audio within the retry loop; after max_retries attempts (with reconnect + exponential backoff) the model resets state and raises. Distinct from a timeout: the flow completed but zero audio bytes arrived.

Source

Thrown at src/agentscope/tts/_dashscope/_realtime_model.py:433

                    self._callback.finish_event.wait,
                )

                if full_text and not self._callback.has_audio_data():
                    if attempt < self.max_retries - 1:
                        logger.warning(
                            "TTS: no audio received, retrying (%d/%d) in "
                            "%.1fs...",
                            attempt + 1,
                            self.max_retries,
                            delay,
                        )
                        await asyncio.sleep(delay)
                        await self._reconnect()
                        unsent = full_text
                        delay *= 2
                        continue
                    self._reset_state()
                    raise RuntimeError(
                        f"TTS synthesis failed: no audio after "
                        f"{self.max_retries} attempts",
                    )
                break

            except WebSocketConnectionClosedException:
                if attempt < self.max_retries - 1:
                    logger.warning(
                        "TTS WebSocket closed, retrying (%d/%d) in %.1fs...",
                        attempt + 1,
                        self.max_retries,
                        delay,
                    )
                    await asyncio.sleep(delay)
                    await self._reconnect()
                    unsent = full_text
                    delay *= 2
                else:

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Verify DASHSCOPE_API_KEY validity and quota.
  2. Confirm the voice/model combination is supported.
  3. Inspect websocket close codes/error messages logged near the failure.
  4. Retry at the call site with fresh connect(); if persistent, fall back to non-realtime synthesis.
  5. Report/check dashscope status page for outages.

Example fix

# before
audio = await model.synthesize(text)

# after
try:
    audio = await model.synthesize(text)
except RuntimeError:
    await model.disconnect()
    await model.connect()
    audio = await model.synthesize(text)
Defensive patterns

Strategy: fallback

Try / catch

try:
    audio = await model.synthesize(text)
except RuntimeError as e:
    if "no audio after" in str(e):
        await model.disconnect()
        await model.connect()
        audio = await model.synthesize(text)
    else:
        raise

Prevention

When it happens

Trigger: Calling synthesize() on the realtime model where the websocket accepts text but no binary audio frames come back, on the final retry attempt. Caused by auth failures, unsupported voice/model params, server errors, or a half-dead connection.

Common situations: Bad or quota-exhausted DASHSCOPE_API_KEY, mismatched voice for the model, dashscope service incidents, network middleboxes that allow the handshake but drop binary frames.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/c02e021a809c2019. Report an issue: GitHub.