From ee5fea422138d45d8331dc8c9395e84a805e0060 Mon Sep 17 00:00:00 2001 From: Matej Marinko Date: Thu, 29 May 2025 14:58:35 +0200 Subject: [PATCH] Fix auto finalization cycle --- src/pipecat/services/soniox/stt.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pipecat/services/soniox/stt.py b/src/pipecat/services/soniox/stt.py index fbffd9c19..dd425bcbf 100644 --- a/src/pipecat/services/soniox/stt.py +++ b/src/pipecat/services/soniox/stt.py @@ -45,6 +45,7 @@ FINALIZED_TOKEN = "" def is_end_token(token: dict) -> bool: + """Determine if a token is an end token.""" return token["text"] == END_TOKEN or token["text"] == FINALIZED_TOKEN @@ -270,8 +271,12 @@ class SonioxSTTService(STTService): tokens = content["tokens"] if tokens: - # Got at least one token, so we can reset the auto finalize delay. - self._last_tokens_received = time.time() + if len(tokens) == 1 and tokens[0]["text"] == FINALIZED_TOKEN: + # Ignore finalized token, prevent auto-finalize cycling. + pass + else: + # Got at least one token, so we can reset the auto finalize delay. + self._last_tokens_received = time.time() # We will only send the final tokens after we get the "endpoint" event. non_final_transcription = ""