I'm using 11lab as my TTS provider. I don't see an...
# ask-ai
c
I'm using 11lab as my TTS provider. I don't see any issues with the voice agent but the 11labs request logs show all the websocket requests as failures with code 1006. Is there an error with the way I'm handling the socker closure? I don't see anything in my logs as well. I'm running this on livekit python worker.
✅ 1
t
Thanks for reaching out, Bharath. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m sorry you’re seeing those 1006 failures. I’m happy to help debug. I don’t yet have enough detail to tell whether the socket closure handling is the problem, so a few targeted questions and requests will help narrow this down: • Which LiveKit Python worker / SDK version are you running? • Can you share the code snippet that opens, writes to, and closes the ElevenLabs WebSocket (redact any secrets)? • Do you call a clean close (e.g., `close()`/send close frame) from the worker, or are you simply terminating the process/thread? • Are there any relevant worker logs around the time of the 1006s (connection open, send, close, exceptions)? Please paste short excerpts. • Do the failures happen immediately on connect or after some streaming activity? Is it reproducible every time? • Are you behind a proxy or using any keepalive/timeout settings on the socket? What I can do after you send that: • Review the snippet for improper close handling or missing await/flush steps. • Suggest concrete changes (clean close sequence, keepalives, exception handling) and sample code for the worker. • Point out where to add short logging to capture the socket lifecycle if logs are missing. Send the version, code, and a short log excerpt and I’ll take a look. Sources: ElevenLabs TTS | LiveKit Documentation | LMNT TTS plugin guide | LiveKit Documentation, with interactive elements
c
These are the versions:
Copy code
livekit-plugins-elevenlabs==1.5.1
livekit == 1.1.3
Copy code
elevenlabs.TTS(
        voice_id=selectedVoice,
        model=config['elevenLabs.model'],
        voice_settings=voiceSettingsObj,
        enable_ssml_parsing=True
        )
to iniialize
t
Thanks — and thanks for the versions and init snippet. I’ll help narrow this down. A few quick clarifying items and a short checklist will let me diagnose whether socket closure is the problem. Quick clarifying questions • Does the 1006 failure occur immediately on connect or only after some audio is streamed? Is it reproducible every time? • Can you paste the code that performs the actual synth/stream call and any close/cleanup code (redact keys)? • Share a short log excerpt (10–20 lines) showing the connection open/send/close timeframe and any exceptions from the worker. • Are you running the worker on a machine behind a proxy, load balancer, or short TCP idle timeout? Immediate checklist to try now • Ensure you perform a clean WebSocket close rather than abruptly killing the process: await any streaming coroutine to finish, then call the plugin/stream close method (or
close()
if exposed) and wait for confirmation. • Add explicit try/except around the streaming call and log exceptions and finalization steps (open, send start, send end, close). • Add short lifecycle logs around connect/send/close with timestamps so we can see whether the remote closed unexpectedly. • If there’s an intermediate proxy/load balancer, enable TCP/HTTP keepalives or lower idle timeouts to prevent intermediates from dropping the socket. • Reproduce with verbose network logging (or run locally) to see whether the socket is closed by the server or by an intermediate. What I can do once you share the code + logs • Review the synth/stream and close sequence for missing awaits or abrupt termination. • Suggest exact code changes (where to add await/close and logging) for livekit-plugins-elevenlabs==1.5.1 + livekit==1.1.3. • Recommend further network-level checks if the close appears to be caused by an intermediate. Send the synth/stream + close code and a short log excerpt and I’ll review. Sources: ElevenLabs TTS | LiveKit Documentation, with interactive elements
c
is there a way to enable debug logs for elevenlabs?
t
Short answer: There is no ElevenLabs-specific debug flag in the LiveKit ElevenLabs TTS plugin. What you can do now • Enable LiveKit agent debug logs: ◦ CLI: run the agent with
--log-level=DEBUG
◦ Env var:
LIVEKIT_LOG_LEVEL=DEBUG
before starting the agent (These will surface broader runtime and networking details that may include ElevenLabs interactions.) • Add explicit logging around the ElevenLabs calls in your worker using Python’s `logging`: ◦ Log connection open, send/start-of-stream, end-of-stream, and close events and any caught exceptions. ◦ Example:
Copy code
import logging
    logger = logging.getLogger("elevenlabs")
    logger.setLevel(logging.DEBUG)

    try:
        logger.debug("Starting TTS synth...")
        # call into elevenlabs TTS
        logger.debug("TTS synth finished, closing stream")
    except Exception as e:
        logger.exception("ElevenLabs TTS error")
• Check network factors: proxies, load balancers, or TCP idle timeouts can cause WebSocket 1006; enabling keepalives or lowering idle timeouts may help. If you want, paste a short log snippet or the synth/close code and I’ll point out where to add logging or what to look for in the debug output. Sources: ElevenLabs TTS | LiveKit Documentation | Server options | LiveKit Documentation | Ultravox plugin guide | LiveKit Documentation | Where to find your Agent Logs | LiveKit, with interactive elements