Skip to content
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

Improve websocket based TTS service reconnection logic #962

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

markbackman
Copy link
Contributor

@markbackman markbackman commented Jan 10, 2025

Please describe the changes in your PR. If it is addressing an issue, please reference that as well.

The reconnection logic used by the websocket based TTS services had an issue—the retry countered wouldn't reset after a successful connection. That was pointed out in the following issue: #471 (comment). This is most likely to impact Cartesia, as it attempts to disconnect the websocket after 5 minutes of reactivity.

This change adds a new WebsocketServer base class used by TTS services. The logic contains retry logic used by all of the services.

In addition, the LMNTTTSService was refactored to use a websocket connection. This allows the LMNTTTSService to use the retry logic in the base class.

For the retry logic, I moved away from tenacity as it was reluctant to reset the counters. The state persisted across connections. So, I removed it and opted to add in custom code to handle this.

@nikcaryo-super
Copy link

thanks for the quick change!

@markbackman markbackman force-pushed the mb/improve-tts-reconnection-logic branch from 4769663 to 43b3f8f Compare January 10, 2025 18:31
- Added `session_timeout` to `FastAPIWebsocketTransport` and `WebsocketServerTransport`
for configuring session timeouts (in seconds). Triggers `on_session_timeout` for custom timeout handling.
See [examples/websocket-server/bot.py](https://github.com/pipecat-ai/pipecat/blob/main/examples/websocket-server/bot.py).
- Added `session_timeout` to `FastAPIWebsocketTransport` and
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miscellaneous CHANGELOG cleanup.

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

Successfully merging this pull request may close these issues.

2 participants