Skip to main content

RealtimeModel

Trait RealtimeModel 

Source
pub trait RealtimeModel: Send + Sync {
    // Required methods
    fn provider(&self) -> &str;
    fn model_id(&self) -> &str;
    fn supported_input_formats(&self) -> Vec<AudioFormat>;
    fn supported_output_formats(&self) -> Vec<AudioFormat>;
    fn available_voices(&self) -> Vec<&str>;
    fn connect<'life0, 'async_trait>(
        &'life0 self,
        config: RealtimeConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn RealtimeSession>, RealtimeError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided method
    fn supports_realtime(&self) -> bool { ... }
}
Available on crate feature realtime only.
Expand description

A factory for creating real-time sessions.

Each provider (OpenAI, Gemini, etc.) implements this trait to provide their specific realtime connection logic.

§Example

use adk_realtime::{RealtimeModel, RealtimeConfig};
use adk_realtime::openai::OpenAIRealtimeModel;

#[tokio::main]
async fn main() -> Result<()> {
    let model = OpenAIRealtimeModel::new(api_key, "gpt-4o-realtime-preview-2024-12-17");

    let config = RealtimeConfig::default()
        .with_instruction("You are a helpful assistant.")
        .with_voice("alloy");

    let session = model.connect(config).await?;

    // Use the session...

    session.close().await?;
    Ok(())
}

Required Methods§

Source

fn provider(&self) -> &str

Get the provider name (e.g., “openai”, “gemini”).

Source

fn model_id(&self) -> &str

Get the model identifier.

Source

fn supported_input_formats(&self) -> Vec<AudioFormat>

Get supported input audio formats.

Source

fn supported_output_formats(&self) -> Vec<AudioFormat>

Get supported output audio formats.

Source

fn available_voices(&self) -> Vec<&str>

Get available voices for this model.

Source

fn connect<'life0, 'async_trait>( &'life0 self, config: RealtimeConfig, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn RealtimeSession>, RealtimeError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Connect and create a new realtime session.

This establishes a WebSocket connection to the provider and configures the session with the provided settings.

Provided Methods§

Source

fn supports_realtime(&self) -> bool

Check if this model supports realtime streaming.

Implementors§