Skip to content

11Labs websocket connection #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
EdgarMMProsper opened this issue Mar 28, 2025 · 3 comments
Open

11Labs websocket connection #1467

EdgarMMProsper opened this issue Mar 28, 2025 · 3 comments

Comments

@EdgarMMProsper
Copy link

Pipecat version: 0.0.60

I know there has been a lot of working around websocket connections. I am sharing this in case someone else has seen this and we can deepdive together. At certain points my elevenlabs connection falls and is unable to reconnect:

2025-03-27 14:09:50.774 | ERROR | pipecat.services.websocket_service:_receive_task_handler:77 - CustomElevenLabsTTSService#0 error receiving messages: no close frame received or sent
2025-03-27 14:09:50.774 | WARNING | pipecat.services.websocket_service:_receive_task_handler:85 - CustomElevenLabsTTSService#0 connection error, will retry: no close frame received or sent
2025-03-27 14:09:50.775 | WARNING | pipecat.pipeline.task:_process_up_queue:479 - Something went wrong: ErrorFrame#0(error: CustomElevenLabsTTSService#0 error receiving messages: no close frame received or sent, fatal: False)
2025-03-27 14:09:50.776 | DEBUG | pipecat.services.elevenlabs:_disconnect_websocket:374 - Disconnecting from ElevenLabs
2025-03-27 14:09:50.776 | ERROR | pipecat.services.elevenlabs:_disconnect_websocket:381 - CustomElevenLabsTTSService#0 error closing websocket: no close frame received or sent
2025-03-27 14:09:50.776 | WARNING | pipecat.services.websocket_service:_reconnect_websocket:51 - CustomElevenLabsTTSService#0 reconnecting (attempt: 1)
2025-03-27 14:09:50.777 | ERROR | pipecat.services.websocket_service:_verify_connection:39 - CustomElevenLabsTTSService#0 connection verification failed: no close frame received or sent
2025-03-27 14:09:50.813 | WARNING | pipecat.services.elevenlabs:_keepalive_task_handler:409 - CustomElevenLabsTTSService#0 keepalive error: no close frame received or sent
2025-03-27 14:09:54.778 | ERROR | pipecat.services.websocket_service:_receive_task_handler:77 - CustomElevenLabsTTSService#0 error receiving messages: no close frame received or sent
2025-03-27 14:09:54.778 | WARNING | pipecat.services.websocket_service:_receive_task_handler:85 - CustomElevenLabsTTSService#0 connection error, will retry: no close frame received or sent
2025-03-27 14:09:54.779 | DEBUG | pipecat.services.elevenlabs:_disconnect_websocket:374 - Disconnecting from ElevenLabs
2025-03-27 14:09:54.779 | WARNING | pipecat.pipeline.task:_process_up_queue:479 - Something went wrong: ErrorFrame#1(error: CustomElevenLabsTTSService#0 error receiving messages: no close frame received or sent, fatal: False)
2025-03-27 14:09:54.779 | WARNING | pipecat.services.websocket_service:_reconnect_websocket:51 - CustomElevenLabsTTSService#0 reconnecting (attempt: 2)
2025-03-27 14:09:54.781 | ERROR | pipecat.services.elevenlabs:_disconnect_websocket:381 - CustomElevenLabsTTSService#0 error closing websocket: no close frame received or sent
2025-03-27 14:09:54.781 | ERROR | pipecat.services.websocket_service:_verify_connection:39 - CustomElevenLabsTTSService#0 connection verification failed: no close frame received or sent
2025-03-27 14:09:58.782 | ERROR | pipecat.pipeline.task:_process_up_queue:473 - A fatal error occurred: ErrorFrame#2(error: CustomElevenLabsTTSService#0 error receiving messages: no close frame received or sent, fatal: True)
2025-03-27 14:09:58.782 | ERROR | pipecat.services.websocket_service:_receive_task_handler:77 - CustomElevenLabsTTSService#0 error receiving messages: no close frame received or sent
2025-03-27 14:09:58.784 | DEBUG | pipecat.services.elevenlabs:_disconnect_websocket:374 - Disconnecting from ElevenLabs
2025-03-27 14:09:58.784 | ERROR | pipecat.services.elevenlabs:_disconnect_websocket:381 - CustomElevenLabsTTSService#0 error closing websocket: no close frame received or sent

If I understand it right no close frame received or sent means that we can not connect succesfully from our side the 11labs server. I might try to make MAX_RETRIES to a higher number but the wait time is already 4 seconds so I guess that it is odd that the connection is off for that long time. Anyone has seen this / any thoughts?

@EdgarMMProsper
Copy link
Author

Okay I think I found something. I think that ElevenLabsTTSService._disconnect_websocket should be

  async def _disconnect_websocket(self):
       try:
           await self.stop_all_metrics()

           if self._websocket:
               logger.debug("Disconnecting from ElevenLabs")
               await self._websocket.send(json.dumps({"text": ""}))
               await self._websocket.close()
               self._websocket = None

           self._started = False
       except Exception as e:
           logger.error(f"{self} error closing websocket: {e}")
           # CUSTOM CODE: if the websocket can not disconnect, force it to be None
           self._websocket = None

This is because when we get an error so bad that we can not even disconnect, we need to force the disconnection

@aweitz
Copy link

aweitz commented Apr 1, 2025

We just started seeing this behavior with the ElevenLabsTTSService, but only for one voice out of 5 tested. Pipecat version 0.0.61.

Edit: The above suggestion seems to work (avoids the fatal error).

@YongeBai
Copy link

YongeBai commented Apr 7, 2025

I've ran into this issue before. I believe it's due to using a voice Id that is not added to your 11labs library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants