From be8788e4da21cfe2047f29c62f17dbcb95ddc79f Mon Sep 17 00:00:00 2001 From: Dan Berg Date: Tue, 15 Apr 2025 16:02:22 +0200 Subject: [PATCH] Push gladia translations as a TranscriptionFrame --- src/pipecat/services/gladia/stt.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pipecat/services/gladia/stt.py b/src/pipecat/services/gladia/stt.py index df8038bd3..61fffc846 100644 --- a/src/pipecat/services/gladia/stt.py +++ b/src/pipecat/services/gladia/stt.py @@ -384,16 +384,31 @@ class GladiaSTTService(STTService): if content["type"] == "transcript": utterance = content["data"]["utterance"] confidence = utterance.get("confidence", 0) + language = utterance["language"] transcript = utterance["text"] if confidence >= self._confidence: if content["data"]["is_final"]: await self.push_frame( - TranscriptionFrame(transcript, "", time_now_iso8601()) + TranscriptionFrame(transcript, "", time_now_iso8601(), language) ) else: await self.push_frame( - InterimTranscriptionFrame(transcript, "", time_now_iso8601()) + InterimTranscriptionFrame( + transcript, "", time_now_iso8601(), language + ) ) + elif content["type"] == "translation": + translated_utterance = content["data"]["translated_utterance"] + original_language = content["data"]["original_language"] + translated_language = translated_utterance["language"] + confidence = translated_utterance.get("confidence", 0) + translation = translated_utterance["text"] + if translated_language != original_language and confidence >= self._confidence: + await self.push_frame( + TranscriptionFrame( + translation, "", time_now_iso8601(), translated_language + ) + ) except websockets.exceptions.ConnectionClosed: # Expected when closing the connection pass