agentscope-ai/agentscope · error · RuntimeError
CosyVoice TTS synthesis failed: no audio after {self.max_ret
Error message
CosyVoice TTS synthesis failed: no audio after {self.max_retries} attempts What it means
CosyVoice real-time TTS finished sending text but no audio bytes were ever received, even after max_retries reconnect attempts. The library tracks whether any audio arrived via _callback.has_audio_data(); if empty after the final retry it aborts. Typical of server rejecting the request silently (auth, voice/model mismatch) or a dead connection.
Source
Thrown at src/agentscope/tts/_dashscope/_cosyvoice_model.py:338
raise RuntimeError(
"CosyVoice TTS synthesis timed out after 30s",
)
if full_text and not self._callback.has_audio_data():
if attempt < self.max_retries - 1:
logger.warning(
"CosyVoice 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
raise RuntimeError(
f"CosyVoice TTS synthesis failed: no audio after "
f"{self.max_retries} attempts",
)
break
except RuntimeError:
raise
except Exception as e:
if attempt < self.max_retries - 1:
logger.warning(
"CosyVoice TTS error, retrying (%d/%d) in "
"%.1fs: %s",
attempt + 1,
self.max_retries,
delay,
e,
)
await asyncio.sleep(delay)View on GitHub (pinned to e90f1c7592)
Solutions
- Validate DASHSCOPE_API_KEY and that the CosyVoice model/voice pair is enabled for the account.
- Check the voice parameter matches a voice supported by the configured model.
- Log and inspect the websocket close/error frames around the failure to see the server reason.
- Increase max_retries if failures are transient.
- Fall back to a non-realtime TTS model (e.g. dashscope HTTP synthesis) when realtime yields no audio.
Example fix
# before model = DashScopeCosyVoiceTTSModel(voice="unknown-voice") # after model = DashScopeCosyVoiceTTSModel(voice="longwan_v2") # a voice supported by the model
Defensive patterns
Strategy: retry
Try / catch
try:
audio = await tts.synthesize(text)
except RuntimeError as e:
if "no audio after" in str(e):
log.error("CosyVoice returned no audio; check API key/voice")
audio = await fallback_tts.synthesize(text)
else:
raise Prevention
- Use a voice name confirmed supported by the chosen CosyVoice model.
- Keep the API key valid with remaining quota.
- Have a non-realtime TTS fallback configured.
When it happens
Trigger: Calling synthesize() on the realtime CosyVoice model where full_text was sent but the callback never received audio data on the last retry attempt. Common with wrong voice/model parameters, missing API key, or service-side errors that close the stream without audio frames.
Common situations: Invalid DASHSCOPE_API_KEY, unsupported voice name for the chosen model, model not enabled for the account, or regional endpoint mismatch. Also after network interruptions where reconnect succeeds but the session state is lost.
Related errors
- TTS synthesis failed: no audio after {self.max_retries} atte
- CosyVoice TTS synthesis timed out after 30s
- TTS model is not connected. Call `connect()` first.
- TTS model is not connected. Call `connect()` first.
- 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/65ac97c9ac3b09ea.
Report an issue: GitHub.