Files
ai-video-fullstack/backend/services/realtime/protocol.py
T

43 lines
1.4 KiB
Python
Raw Normal View History

"""Neutral extension point between a transport protocol and the voice pipeline."""
from __future__ import annotations
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import Literal, Protocol
from pipecat.frames.frames import Frame, SystemFrame
from pipecat.processors.frame_processor import FrameProcessor
@dataclass(frozen=True)
class PipelineProtocolRuntime:
"""Operations a wire-protocol adapter may request from a running pipeline."""
queue_frame: Callable[[Frame], Awaitable[None]]
set_external_turn_control: Callable[[bool], Awaitable[None]]
set_response_interruption: Callable[[bool], Awaitable[None]]
commit_audio: Callable[[], Awaitable[None]]
clear_audio: Callable[[], Awaitable[None]]
request_response: Callable[[], Awaitable[None]]
cancel_response: Callable[[], Awaitable[None]]
@dataclass
class RealtimeProviderControlFrame(SystemFrame):
"""Ordered control sent to a speech-to-speech provider after prior input."""
action: Literal["commit_audio", "clear_audio", "request_response"]
class PipelineProtocolAdapter(Protocol):
"""A protocol adapter only translates frames; it does not own the assistant."""
def input_processors(self) -> list[FrameProcessor]: ...
def inference_processors(self) -> list[FrameProcessor]: ...
def output_processors(self) -> list[FrameProcessor]: ...
async def bind(self, runtime: PipelineProtocolRuntime) -> None: ...