pub struct RealtimeSession { /* private fields */ }realtime only.Expand description
An active realtime session.
Cheap to share indirectly via the channels it owns; call
RealtimeSession::close to terminate the background task.
Implementations§
Source§impl RealtimeSession
impl RealtimeSession
Sourcepub async fn send_audio(&self, pcm: Bytes) -> ZaiResult<()>
pub async fn send_audio(&self, pcm: Bytes) -> ZaiResult<()>
Send raw 16-bit little-endian mono PCM.
With InputAudioFormat::Wav (the default), the bytes are wrapped in a
16 kHz WAV container. With Pcm16 or Pcm24, they are sent as raw PCM
and the selected format declares the corresponding sample rate.
Sourcepub async fn send_video_frame(&self, jpeg: Bytes) -> ZaiResult<()>
pub async fn send_video_frame(&self, jpeg: Bytes) -> ZaiResult<()>
Upload a JPEG frame for passive-video mode.
Sourcepub async fn commit_audio(&self) -> ZaiResult<()>
pub async fn commit_audio(&self) -> ZaiResult<()>
Commit buffered audio for inference in client-VAD mode. Server-VAD commits automatically and normally does not need this command.
Sourcepub async fn clear_audio(&self) -> ZaiResult<()>
pub async fn clear_audio(&self) -> ZaiResult<()>
Clear audio buffered by the server without triggering inference.
Sourcepub async fn send_text(&self, text: impl Into<String>) -> ZaiResult<()>
pub async fn send_text(&self, text: impl Into<String>) -> ZaiResult<()>
Inject a user text message into the conversation history.
Sourcepub async fn send_function_output(
&self,
call_name: impl Into<String>,
output: impl Into<String>,
) -> ZaiResult<()>
pub async fn send_function_output( &self, call_name: impl Into<String>, output: impl Into<String>, ) -> ZaiResult<()>
Feed back a function-call result.
Sourcepub async fn delete_item(&self, item_id: impl Into<String>) -> ZaiResult<()>
pub async fn delete_item(&self, item_id: impl Into<String>) -> ZaiResult<()>
Delete an item from the server-side conversation history.
Sourcepub async fn retrieve_item(&self, item_id: impl Into<String>) -> ZaiResult<()>
pub async fn retrieve_item(&self, item_id: impl Into<String>) -> ZaiResult<()>
Ask the server to emit the current representation of one conversation
item via ServerEvent::ConversationItemRetrieved.
Sourcepub async fn create_response(&self) -> ZaiResult<()>
pub async fn create_response(&self) -> ZaiResult<()>
Trigger model inference (response.create).
Sourcepub async fn cancel(&self) -> ZaiResult<()>
pub async fn cancel(&self) -> ZaiResult<()>
Cancel the in-flight response (response.cancel), e.g. on interruption.
Sourcepub fn events(
&self,
) -> Pin<Box<dyn Stream<Item = ZaiResult<ServerEvent>> + Send + '_>>
pub fn events( &self, ) -> Pin<Box<dyn Stream<Item = ZaiResult<ServerEvent>> + Send + '_>>
Stream of server metadata events (transcripts, response lifecycle,
errors, heartbeats). Audio deltas are decoded only onto
Self::audio_stream to avoid retaining a second base64 copy. The
first subscriber receives events buffered since session creation;
later subscribers start at the live tail. A lagged consumer or
background session failure is surfaced as an error instead of silently
losing protocol events.
Sourcepub fn audio_stream(
&self,
) -> Pin<Box<dyn Stream<Item = ZaiResult<RealtimeAudioChunk>> + Send + '_>>
pub fn audio_stream( &self, ) -> Pin<Box<dyn Stream<Item = ZaiResult<RealtimeAudioChunk>> + Send + '_>>
Stream of decoded 24 kHz, mono, 16-bit PCM output chunks.
Lag is an error because dropping a PCM chunk would silently corrupt the resulting audio stream.
Sourcepub fn model_name(&self) -> &str
pub fn model_name(&self) -> &str
The model id sent in the initial session.update event.
Sourcepub async fn request_close(&self) -> ZaiResult<()>
pub async fn request_close(&self) -> ZaiResult<()>
Signal the background task to close without awaiting it.
Use when the session is shared (e.g. behind an Arc), driven from a
tokio::select!, or closed reactively on a shutdown signal. This only
signals a dedicated shutdown channel; the background loop observes it
independently of the bounded outbound queue and exits.
For deterministic, awaited teardown use RealtimeSession::close.