pub struct RealtimeSession { /* private fields */ }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 LE mono PCM (16 kHz) audio; it is wrapped in a WAV
header, base64-encoded, and uploaded via input_audio_buffer.append.
Sourcepub async fn commit_audio(&self) -> ZaiResult<()>
pub async fn commit_audio(&self) -> ZaiResult<()>
Commit buffered audio for inference (client-VAD). Server-VAD commits automatically; calling this is harmless.
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 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 = ServerEvent> + Send + '_>>
pub fn events(&self) -> Pin<Box<dyn Stream<Item = ServerEvent> + Send + '_>>
Stream of all server events (transcripts, response lifecycle, errors,
heartbeats). Late subscribers miss events broadcast before they joined;
subscribe before driving commands when ordering matters. Transient
Lagged gaps (slow consumer) are dropped rather than erroring.
Sourcepub fn audio_stream(&self) -> Pin<Box<dyn Stream<Item = Bytes> + Send + '_>>
pub fn audio_stream(&self) -> Pin<Box<dyn Stream<Item = Bytes> + Send + '_>>
Stream of decoded audio output chunks (PCM/MP3 bytes, per
output_audio_format).
Sourcepub fn model_name(&self) -> &str
pub fn model_name(&self) -> &str
The model id this session was opened for (metadata; the protocol does not transmit it on the wire).