File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
src/elevenlabs/conversational_ai Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 77from concurrent .futures import ThreadPoolExecutor
88
99from websockets .sync .client import connect
10+ from websockets .exceptions import ConnectionClosedOK
1011
1112from ..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
You can’t perform that action at this time.
0 commit comments