Add TranslationFrame and use in GladiaSTTService; add 13c-gladia-translation.py

This commit is contained in:
Mark Backman
2025-04-17 16:22:33 -04:00
parent 2fb85941d3
commit d1086914fe
4 changed files with 117 additions and 1 deletions

View File

@@ -256,6 +256,22 @@ class InterimTranscriptionFrame(TextFrame):
return f"{self.name}(user: {self.user_id}, text: [{self.text}], language: {self.language}, timestamp: {self.timestamp})"
@dataclass
class TranslationFrame(TextFrame):
"""A text frame with translated transcription data.
Will be placed in the transport's receive queue when a participant speaks.
"""
user_id: str
timestamp: str
language: Optional[Language] = None
def __str__(self):
return f"{self.name}(user: {self.user_id}, text: [{self.text}], language: {self.language}, timestamp: {self.timestamp})"
@dataclass
class OpenAILLMContextAssistantTimestampFrame(DataFrame):
"""Timestamp information for assistant message in LLM context."""

View File

@@ -20,6 +20,7 @@ from pipecat.frames.frames import (
InterimTranscriptionFrame,
StartFrame,
TranscriptionFrame,
TranslationFrame,
)
from pipecat.services.gladia.config import GladiaInputParams
from pipecat.services.stt_service import STTService
@@ -405,7 +406,7 @@ class GladiaSTTService(STTService):
translation = translated_utterance["text"]
if translated_language != original_language and confidence >= self._confidence:
await self.push_frame(
TranscriptionFrame(
TranslationFrame(
translation, "", time_now_iso8601(), translated_language
)
)