diff --git a/CHANGELOG.md b/CHANGELOG.md index 989cdb14f..9c80ac4fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed an issue where `SmallWebRTCTransport` ended before TTS finished. + - Fixed a `WatchdogPriorityQueue` issue that could cause an exception when compating watchdog cancel sentinel items with other items in the queue. diff --git a/src/pipecat/transports/network/small_webrtc.py b/src/pipecat/transports/network/small_webrtc.py index 140a7b537..ddb8339c9 100644 --- a/src/pipecat/transports/network/small_webrtc.py +++ b/src/pipecat/transports/network/small_webrtc.py @@ -226,6 +226,7 @@ class SmallWebRTCClient: self._audio_in_channels = None self._in_sample_rate = None self._out_sample_rate = None + self._leave_counter = 0 # We are always resampling it for 16000 if the sample_rate that we receive is bigger than that. # otherwise we face issues with Silero VAD @@ -395,6 +396,7 @@ class SmallWebRTCClient: self._in_sample_rate = _params.audio_in_sample_rate or frame.audio_in_sample_rate self._out_sample_rate = _params.audio_out_sample_rate or frame.audio_out_sample_rate self._params = _params + self._leave_counter += 1 async def connect(self): """Establish the WebRTC connection.""" @@ -407,6 +409,10 @@ class SmallWebRTCClient: async def disconnect(self): """Disconnect from the WebRTC peer.""" + self._leave_counter -= 1 + if self._leave_counter > 0: + return + if self.is_connected and not self.is_closing: logger.info(f"Disconnecting to Small WebRTC") self._closing = True