Add TranscriptionProcessor
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, List, Mapping, Optional, Tuple
|
||||
from typing import Any, List, Literal, Mapping, Optional, Tuple, TypeAlias
|
||||
|
||||
from pipecat.audio.vad.vad_analyzer import VADParams
|
||||
from pipecat.clocks.base_clock import BaseClock
|
||||
@@ -195,7 +195,8 @@ class TranscriptionFrame(TextFrame):
|
||||
@dataclass
|
||||
class InterimTranscriptionFrame(TextFrame):
|
||||
"""A text frame with interim transcription-specific data. Will be placed in
|
||||
the transport's receive queue when a participant speaks."""
|
||||
the transport's receive queue when a participant speaks.
|
||||
"""
|
||||
|
||||
text: str
|
||||
user_id: str
|
||||
@@ -206,6 +207,34 @@ class InterimTranscriptionFrame(TextFrame):
|
||||
return f"{self.name}(user: {self.user_id}, text: [{self.text}], language: {self.language}, timestamp: {self.timestamp})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class TranscriptionMessage:
|
||||
"""A message in a conversation transcript containing the role and content.
|
||||
|
||||
Messages are in standard format with roles normalized to user/assistant.
|
||||
"""
|
||||
|
||||
role: Literal["user", "assistant"]
|
||||
content: str
|
||||
timestamp: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class TranscriptionUpdateFrame(DataFrame):
|
||||
"""A frame containing new messages added to the conversation transcript.
|
||||
|
||||
This frame is emitted when new messages are added to the conversation history,
|
||||
containing only the newly added messages rather than the full transcript.
|
||||
Messages have normalized roles (user/assistant) regardless of the LLM service used.
|
||||
"""
|
||||
|
||||
messages: List[TranscriptionMessage]
|
||||
|
||||
def __str__(self):
|
||||
pts = format_pts(self.pts)
|
||||
return f"{self.name}(pts: {pts}, messages: {len(self.messages)})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class LLMMessagesFrame(DataFrame):
|
||||
"""A frame containing a list of LLM messages. Used to signal that an LLM
|
||||
@@ -546,7 +575,8 @@ class EndFrame(ControlFrame):
|
||||
@dataclass
|
||||
class LLMFullResponseStartFrame(ControlFrame):
|
||||
"""Used to indicate the beginning of an LLM response. Following by one or
|
||||
more TextFrame and a final LLMFullResponseEndFrame."""
|
||||
more TextFrame and a final LLMFullResponseEndFrame.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user