From 5dc8b48fbe353b97048a018320eaa5f83fe3dda4 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Tue, 18 Mar 2025 09:42:03 -0400 Subject: [PATCH] Fix an issue where GoogleSTTService would timeout due to stream inactivity --- CHANGELOG.md | 6 ++++++ src/pipecat/services/google/google.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d200ab87..7afea60be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,6 +122,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed an issue with the `GoogleSTTService` where stream timeouts during + periods of inactivity were causing connection failures. The service now + properly detects timeout errors and handles reconnection gracefully, + ensuring continuous operation even after periods of silence or when using an + `STTMuteFilter`. + - Fixed an issue in `RimeTTSService` where the last line of text sent didn't result in an audio output being generated. diff --git a/src/pipecat/services/google/google.py b/src/pipecat/services/google/google.py index 9d4a0a8a8..b2af64b57 100644 --- a/src/pipecat/services/google/google.py +++ b/src/pipecat/services/google/google.py @@ -1972,7 +1972,8 @@ class GoogleSTTService(STTService): break except Exception as e: - logger.error(f"Stream error, attempting to reconnect: {e}") + logger.warning(f"{self} Reconnecting: {e}") + await asyncio.sleep(1) # Brief delay before reconnecting self._stream_start_time = int(time.time() * 1000) continue @@ -2025,3 +2026,6 @@ class GoogleSTTService(STTService): except Exception as e: logger.error(f"Error processing Google STT responses: {e}") + + # Re-raise the exception to let it propagate (e.g. in the case of a timeout, propagate to _stream_audio to reconnect) + raise