Skip to content

Commit d629466

Browse files
AngeloGiaccolouisjoecodes
authored andcommitted
fix: handle end call gracefully
1 parent 805f529 commit d629466

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/elevenlabs/conversational_ai/conversation.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from concurrent.futures import ThreadPoolExecutor
88

99
from websockets.sync.client import connect
10+
from websockets.exceptions import ConnectionClosedOK
1011

1112
from ..base_client import BaseElevenLabs
1213

@@ -284,13 +285,16 @@ def _run(self, ws_url: str):
284285
)
285286

286287
def input_callback(audio):
287-
ws.send(
288-
json.dumps(
289-
{
290-
"user_audio_chunk": base64.b64encode(audio).decode(),
291-
}
288+
try:
289+
ws.send(
290+
json.dumps(
291+
{
292+
"user_audio_chunk": base64.b64encode(audio).decode(),
293+
}
294+
)
292295
)
293-
)
296+
except ConnectionClosedOK:
297+
self.end_session()
294298

295299
self.audio_interface.start(input_callback)
296300
while not self._should_stop.is_set():
@@ -299,6 +303,8 @@ def input_callback(audio):
299303
if self._should_stop.is_set():
300304
return
301305
self._handle_message(message, ws)
306+
except ConnectionClosedOK as e:
307+
self.end_session()
302308
except TimeoutError:
303309
pass
304310

0 commit comments

Comments
 (0)