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§
Sourcefn supported_input_formats(&self) -> Vec<AudioFormat>
fn supported_input_formats(&self) -> Vec<AudioFormat>
Get supported input audio formats.
Sourcefn supported_output_formats(&self) -> Vec<AudioFormat>
fn supported_output_formats(&self) -> Vec<AudioFormat>
Get supported output audio formats.
Sourcefn available_voices(&self) -> Vec<&str>
fn available_voices(&self) -> Vec<&str>
Get available voices for this model.
Sourcefn 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,
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§
Sourcefn supports_realtime(&self) -> bool
fn supports_realtime(&self) -> bool
Check if this model supports realtime streaming.