-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Bug Description
When using elevenlabs.STT (version 1.3.6) in streaming mode, if the WebSocket connection drops mid-stream (e.g., due to network instability or ElevenLabs service issues), the SpeechStream raises APIStatusError with retryable=True but does not attempt to reconnect. The stream effectively dies, and my transcription becomes non-English characters. I also see LiveKit start repeating the same sentence (I am not sure this repeat behavior is related to stream issue).
Current Behavior
SpeechStream._run()establishes WebSocket connection via_connect_ws()recv_taskmonitors incoming messages- When WebSocket closes unexpectedly,
recv_taskraises:APIStatusError: ElevenLabs STT connection closed unexpectedly (status_code=-1, request_id=None, body=None, retryable=True) - Exception propagates through
task.result()and breaks out of thewhile Trueloop - Stream ends without reconnection attempt
- AgentSession receives error with
recoverable=True
Expected Behavior
Either:
-
Plugin-level:
SpeechStreamshould catch connection errors and attempt reconnection (similar to how_reconnect_eventtriggers reconnection forupdate_options) -
Framework-level:
AgentSessionshould recreate STT streams when receiving recoverable STT errors
Relevant Code
In stt.py, the _run method's reconnection logic only triggers on _reconnect_event:
async def _run(self) -> None:
while True:
try:
ws = await self._connect_ws()
# ... tasks created ...
for task in done:
if task != wait_reconnect_task:
task.result() # <-- Exception raised here breaks out of loop
if wait_reconnect_task not in done:
break # <-- Exits loop on error
self._reconnect_event.clear() # <-- Only reconnects if event was set
Reproduction Steps
- Configure
AgentSessionwithelevenlabs.STT, setrealtimetoTrueto useScribe V2 - Start a voice conversation
- Just talk with agent for a few minutes in LiveKit playground
- Observe error in logs with
retryable=True, and my transcription becomes non-English characters.
This is how I create a session with ElevenLabs STT:
from livekit.plugins import elevenlabs,
params = {"use_realtime": True}
stt = elevenlabs.STT(**params)
...
session = AgentSession[ParticipantData](
userdata=participant_data,
stt=stt, # scribe v2
llm=llm, # OpenAI "gpt-5" model
tts=tts, # eleven_multilingual_v2
)Operating System
MacOS
Models Used
Scribe V2
Package Versions
livekit-agents~=1.3.6
livekit-api~=1.1.0
livekit-plugins-elevenlabs~=1.3.6
Python: 3.11Screenshots and Recordings
