Improve websocket based TTS service reconnection logic #962
+236
−178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theLMNTTTSService
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.