Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ SLACK_APP_TOKEN=your-slack-app-level-token
# browser/audio toolchain, which only ships in the container image — locally the
# meeting tools stay unregistered even with a key set.
#
# REALTIME_PROVIDER=openai-realtime # the voice service
# REALTIME_PROVIDER=openai-realtime # the voice service; openai-live for GPT-Live
# OPENAI_LIVE_MODEL=gpt-live-1.1 # openai-live only: the voice
# OPENAI_LIVE_BACKEND_MODEL=gpt-6-sol # openai-live only: reasons and runs the tools
#
# Voice discovers managed OpenAI or Azure independently of the chat provider.
# Select primary first, then provider-list order; keep each endpoint/key paired.
Expand Down
19 changes: 18 additions & 1 deletion backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,20 @@ impl EmbeddingProviderName {
pub enum RealtimeProviderName {
#[serde(rename = "openai-realtime")]
OpenaiRealtime,
#[serde(rename = "openai-live")]
OpenaiLive,
}

pub const REALTIME_PROVIDERS: [RealtimeProviderName; 1] = [RealtimeProviderName::OpenaiRealtime];
pub const REALTIME_PROVIDERS: [RealtimeProviderName; 2] = [
RealtimeProviderName::OpenaiRealtime,
RealtimeProviderName::OpenaiLive,
];

impl RealtimeProviderName {
pub fn as_str(&self) -> &'static str {
match self {
Self::OpenaiRealtime => "openai-realtime",
Self::OpenaiLive => "openai-live",
}
}

Expand Down Expand Up @@ -786,7 +792,14 @@ pub struct Config {
/// `openai_realtime_api_key` is set and the container has the browser and
/// audio toolchain.
pub openai_api_key: Option<String>,
/// The Realtime model: the voice of `openai-realtime`, and the dictation transcriber's
/// session with either provider.
pub openai_realtime_model: String,
/// OPENAI_LIVE_MODEL, default `gpt-live-1.1`: the voice model of `openai-live`.
pub openai_live_model: String,
/// OPENAI_LIVE_BACKEND_MODEL, default `gpt-6-sol`: the Responses model an
/// `openai-live` session runs the agent's tools and reasoning on.
pub openai_live_backend_model: String,
/// Explicit voice override, else capability-based managed discovery or
/// direct voice.
pub openai_realtime_url: Option<String>,
Expand Down Expand Up @@ -1386,6 +1399,8 @@ impl Config {
// Pinned to a snapshot rather than the `gpt-realtime` alias, which follows
// OpenAI's current snapshot and shifts turn-taking under a live deployment.
let openai_realtime_model = e.or_default("OPENAI_REALTIME_MODEL", "gpt-realtime-2.1");
let openai_live_model = e.or_default("OPENAI_LIVE_MODEL", "gpt-live-1.1");
let openai_live_backend_model = e.or_default("OPENAI_LIVE_BACKEND_MODEL", "gpt-6-sol");
// One resolver owns managed discovery and explicit/direct voice.
let realtime_configuration = resolve_realtime_configuration(env)?;
// `auto`, the default, has the voice follow the agent's name: `cedar` for a
Expand Down Expand Up @@ -1872,6 +1887,8 @@ impl Config {
chat_cache_ttl,
openai_api_key,
openai_realtime_model,
openai_live_model,
openai_live_backend_model,
openai_realtime_url: realtime_configuration.url,
openai_realtime_api_key: realtime_configuration.api_key,
realtime_source: realtime_configuration.source,
Expand Down
20 changes: 20 additions & 0 deletions backend/src/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,26 @@ fn pins_the_realtime_model() {
);
}

#[test]
fn selects_gpt_live_and_its_backend_for_the_live_provider() {
let cfg = load(&[("REALTIME_PROVIDER", "openai-live")]);
assert_eq!(cfg.realtime_provider, RealtimeProviderName::OpenaiLive);
assert_eq!(cfg.openai_live_model, "gpt-live-1.1");
assert_eq!(cfg.openai_live_backend_model, "gpt-6-sol");
// Dictation stays on the Realtime transcriber, so its model does not follow the provider.
assert_eq!(cfg.openai_realtime_model, "gpt-realtime-2.1");

let cfg = load(&[
("REALTIME_PROVIDER", "openai-live"),
("OPENAI_REALTIME_MODEL", "gpt-realtime-mini"),
("OPENAI_LIVE_MODEL", "gpt-live-1"),
("OPENAI_LIVE_BACKEND_MODEL", "gpt-6-luna"),
]);
assert_eq!(cfg.openai_realtime_model, "gpt-realtime-mini");
assert_eq!(cfg.openai_live_model, "gpt-live-1");
assert_eq!(cfg.openai_live_backend_model, "gpt-6-luna");
}

#[test]
fn has_the_voice_follow_the_agents_name_when_none_is_set() {
let cfg = load(&[]);
Expand Down
2 changes: 2 additions & 0 deletions backend/src/lib/realtime_providers/get_realtime_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::sync::LazyLock;

use crate::config::{CONFIG, RealtimeProviderName};
use crate::lib::realtime_providers::openai_live::openai_live_provider::OpenAiLiveProvider;
use crate::lib::realtime_providers::openai_realtime::openai_realtime_provider::OpenAiRealtimeProvider;
use crate::lib::realtime_providers::realtime_provider::RealtimeProvider;

Expand All @@ -17,5 +18,6 @@ pub fn get_realtime_provider() -> &'static dyn RealtimeProvider {
fn create(name: RealtimeProviderName) -> Box<dyn RealtimeProvider> {
match name {
RealtimeProviderName::OpenaiRealtime => Box::new(OpenAiRealtimeProvider),
RealtimeProviderName::OpenaiLive => Box::new(OpenAiLiveProvider),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left open for the PR owner. The web suite's mock voice server speaks only Realtime frames. An openai-live configuration needs a second mock for the Live protocol (session.start, response.event delegations, session.thinking.append) and another runtime boot, which is a sizeable e2e addition. The Live protocol paths in this PR (tool runs, held items, the summary, narration replay, the sign-in refusal) have unit tests against a local WebSocket server, with frames shaped like the ones a real gpt-live-1.1 session sent.

}
}
4 changes: 4 additions & 0 deletions backend/src/lib/realtime_providers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// @generated-modules-start
pub mod dictation;
pub mod get_realtime_provider;
pub mod model_audio;
pub mod openai_live;
pub mod openai_realtime;
pub mod realtime_provider;
pub mod room_readings;
pub mod voice_session;
pub mod voice_tools;
// @generated-modules-end
58 changes: 58 additions & 0 deletions backend/src/lib/realtime_providers/model_audio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Audio between the rate a transport speaks and the 24 kHz a voice model speaks.
//!
//! A browser on a virtual audio device speaks 48 kHz; a transport that already speaks
//! the model's 24 kHz makes both directions identity.

use parking_lot::Mutex;

use crate::services::meeting::resampler::{
Downsampler, MEETING_SAMPLE_RATE, REALTIME_SAMPLE_RATE, Upsampler,
};

pub struct ModelAudio {
/// Only `MEETING_SAMPLE_RATE` and `REALTIME_SAMPLE_RATE` are accepted: the resampler
/// is a fixed 2:1 decimation, so any other rate would need a converter that is not
/// here, and silently accepting it would change pitch rather than fail.
passthrough: bool,
downsampler: Mutex<Downsampler>,
upsampler: Mutex<Upsampler>,
}

impl ModelAudio {
/// Fails with `A voice conversation speaks 48000 or 24000 Hz, not {rate}` for any
/// other rate.
pub fn new(rate: u32) -> anyhow::Result<Self> {
if rate != MEETING_SAMPLE_RATE && rate != REALTIME_SAMPLE_RATE {
anyhow::bail!(
"A voice conversation speaks {} or {} Hz, not {}",
MEETING_SAMPLE_RATE,
REALTIME_SAMPLE_RATE,
rate
);
}
Ok(Self {
passthrough: rate == REALTIME_SAMPLE_RATE,
downsampler: Mutex::new(Downsampler::new()),
upsampler: Mutex::new(Upsampler::new()),
})
}

/// Captured audio on its way to the model.
pub fn to_model(&self, pcm: &[u8]) -> Vec<u8> {
if self.passthrough {
pcm.to_vec()
} else {
self.downsampler.lock().process(pcm)
}
}

/// Model speech on its way to playback.
#[allow(clippy::wrong_self_convention)] // Read as "audio from the model".
pub fn from_model(&self, pcm24k: &[u8]) -> Vec<u8> {
if self.passthrough {
pcm24k.to_vec()
} else {
self.upsampler.lock().process(pcm24k)
}
}
}
Loading
Loading