Skip to content

base

base

Abstract realtime voice session.

Classes

SessionEvent dataclass

SessionEvent(
    kind: EventKind,
    text: str = "",
    role: str = "",
    final: bool = False,
    replace: bool = False,
    audio_b64: str = "",
    sample_rate: int = 24000,
    detail: str = "",
    tool_name: str = "",
    tool_ok: bool = False,
    raw: Optional[dict[str, Any]] = None,
)

Normalized event emitted by a provider session toward the UI.

RealtimeVoiceSession

Bases: ABC

Provider-agnostic duplex voice session.

Methods:
connect abstractmethod async
connect() -> None

Open the provider connection and finish setup.

Source code in src/diapason/speech/realtime/base.py
@abstractmethod
async def connect(self) -> None:
    """Open the provider connection and finish setup."""
send_audio abstractmethod async
send_audio(pcm16: bytes) -> None

Send a chunk of mono PCM16 at input_sample_rate.

Source code in src/diapason/speech/realtime/base.py
@abstractmethod
async def send_audio(self, pcm16: bytes) -> None:
    """Send a chunk of mono PCM16 at ``input_sample_rate``."""
send_text abstractmethod async
send_text(text: str) -> None

Optional text turn (debug / typed barge).

Source code in src/diapason/speech/realtime/base.py
@abstractmethod
async def send_text(self, text: str) -> None:
    """Optional text turn (debug / typed barge)."""
interrupt abstractmethod async
interrupt() -> None

Cancel current model speech (barge-in).

Source code in src/diapason/speech/realtime/base.py
@abstractmethod
async def interrupt(self) -> None:
    """Cancel current model speech (barge-in)."""
events abstractmethod
events() -> AsyncIterator[SessionEvent]

Async iterator of normalized session events.

Source code in src/diapason/speech/realtime/base.py
@abstractmethod
def events(self) -> AsyncIterator[SessionEvent]:
    """Async iterator of normalized session events."""
close abstractmethod async
close() -> None

Tear down the provider connection.

Source code in src/diapason/speech/realtime/base.py
@abstractmethod
async def close(self) -> None:
    """Tear down the provider connection."""