Streaming TTS
Error Handling
Common exceptions during streaming TTS and how to handle them gracefully.
Handling example
Wrap your streaming calls in a try/except block to catch and handle errors appropriately.
Error handling
from shunyalabs.exceptions import (
AuthenticationError, ConnectionError, ShunyalabsError
)
try:
async for audio in await client.tts.stream("Hello!", config=config):
process(audio)
except AuthenticationError:
print("Invalid API key — check SHUNYALABS_API_KEY")
except ConnectionError:
print("WebSocket connection failed — check network and retry")
except ShunyalabsError as e:
print(f"SDK error: {e}")Tips
AuthenticationError— verify your API key is set and valid.ConnectionError— the WebSocket connection was lost. Implement reconnection logic for production use.ShunyalabsError— base exception for all SDK errors. Use as a catch-all.