mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add /voice settings to choose a voice for future conversations (#44622)
## Why The TUI has no voice picker, and realtime start requests omit the voice preference. Voice selection also needs to reflect the active project's effective server settings, which can differ from cached local settings. ## What changed - Add `/voice settings` with the server's voice catalog and current effective selection, falling back to the built-in catalog when unavailable. - Save `realtime.voice` through the app server and reread effective settings before confirming the selection. Report save failures and overrides. - Resolve the effective voice for each realtime start. Apply selections to the next voice conversation without interrupting live audio, and retain compatibility with servers that lack `config/read` or return unknown voice names. ## Testing Add picker and confirmation snapshots, plus request tests covering persistence, server defaults, catalog fallback, unknown voices, config read failures, overrides, and project settings after thread switches. GitOrigin-RevId: d47e3da6c1164053c5be9d1da0f5932f2a09261f
This commit is contained in:
1 parent
5c013177d8
commit
9c9451131f
25 files changed
+781
-48
No files matched your search
@@ -0,0 +1,54 @@
|
||||
//! Voice selection for subsequent conversations; saving never interrupts live audio.
|
||||
|
||||
use super::*;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::RealtimeVoicesList;
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn open_realtime_settings(
|
||||
&mut self,
|
||||
current: Option<RealtimeVoice>,
|
||||
voices: RealtimeVoicesList,
|
||||
) {
|
||||
// The TUI uses V3, which shares the V1 voice catalog.
|
||||
let items = voices
|
||||
.v1
|
||||
.into_iter()
|
||||
.map(|voice| SelectionItem {
|
||||
name: voice.wire_name().to_string(),
|
||||
is_current: Some(voice) == current,
|
||||
actions: vec![Box::new(move |tx| {
|
||||
tx.send(AppEvent::PersistRealtimeVoiceSelection { voice });
|
||||
})],
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
title: Some("Select voice".to_string()),
|
||||
subtitle: Some("Applies to your next voice conversation.".to_string()),
|
||||
footer_hint: Some(standard_popup_hint_line()),
|
||||
items,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn set_realtime_voice(&mut self, voice: Option<RealtimeVoice>) {
|
||||
self.config.realtime.voice = voice;
|
||||
}
|
||||
|
||||
pub(crate) fn on_realtime_voice_saved(&mut self, voice: RealtimeVoice) {
|
||||
self.set_realtime_voice(Some(voice));
|
||||
self.add_info_message(
|
||||
format!(
|
||||
"Voice set to {}. Applies to your next voice conversation.",
|
||||
voice.wire_name()
|
||||
),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "realtime_settings_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,71 @@
|
||||
//! Voice picker rendering and selection routing without audio hardware.
|
||||
|
||||
use super::*;
|
||||
use crate::chatwidget::tests::make_chatwidget_manual_with_sender;
|
||||
use crate::chatwidget::tests::render_bottom_popup;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn voice_settings_selects_a_voice_without_starting_audio() {
|
||||
let (mut chat, _sender, mut events, mut ops) = make_chatwidget_manual_with_sender().await;
|
||||
chat.config
|
||||
.features
|
||||
.enable(Feature::RealtimeConversation)
|
||||
.unwrap();
|
||||
chat.config.realtime.voice = Some(RealtimeVoice::Maple);
|
||||
chat.dispatch_command_with_args(SlashCommand::Voice, "settings".to_string(), Vec::new());
|
||||
assert!(
|
||||
std::iter::from_fn(|| events.try_recv().ok())
|
||||
.any(|event| matches!(event, AppEvent::OpenRealtimeSettings))
|
||||
);
|
||||
chat.open_realtime_settings(Some(RealtimeVoice::Maple), RealtimeVoicesList::builtin());
|
||||
insta::assert_snapshot!("voice_settings", render_bottom_popup(&chat, /*width*/ 80));
|
||||
chat.bottom_pane
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Home, KeyModifiers::NONE));
|
||||
chat.bottom_pane
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
let voice = std::iter::from_fn(|| events.try_recv().ok()).find_map(|event| match event {
|
||||
AppEvent::PersistRealtimeVoiceSelection { voice } => Some(voice),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(voice, Some(RealtimeVoice::Juniper));
|
||||
assert_eq!(chat.config.realtime.voice, Some(RealtimeVoice::Maple));
|
||||
assert!(ops.try_recv().is_err());
|
||||
assert!(!chat.realtime_conversation_is_running());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_voice_confirmation_snapshot() {
|
||||
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
|
||||
while events.try_recv().is_ok() {}
|
||||
chat.on_realtime_voice_saved(RealtimeVoice::Juniper);
|
||||
let lines = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => Some(cell.display_lines(/*width*/ 80)),
|
||||
_ => None,
|
||||
})
|
||||
.flatten()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!("saved_voice_confirmation", lines);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn voice_settings_uses_server_catalog() {
|
||||
let (mut chat, _sender, _events, _ops) = make_chatwidget_manual_with_sender().await;
|
||||
chat.open_realtime_settings(
|
||||
Some(RealtimeVoice::Cove),
|
||||
RealtimeVoicesList {
|
||||
v1: vec![RealtimeVoice::Cove, RealtimeVoice::Maple],
|
||||
..RealtimeVoicesList::builtin()
|
||||
},
|
||||
);
|
||||
insta::assert_snapshot!(
|
||||
"voice_settings_server_catalog",
|
||||
render_bottom_popup(&chat, /*width*/ 80)
|
||||
);
|
||||
}
|
||||
@@ -755,9 +755,10 @@ impl ChatWidget {
|
||||
}
|
||||
}
|
||||
SlashCommand::Voice => match trimmed.to_ascii_lowercase().as_str() {
|
||||
"settings" => self.app_event_tx.send(AppEvent::OpenRealtimeSettings),
|
||||
"mute" => self.toggle_realtime_microphone(),
|
||||
"stop" => self.stop_realtime_conversation(),
|
||||
_ => self.add_error_message("Usage: /voice [mute|stop]".to_string()),
|
||||
_ => self.add_error_message("Usage: /voice [settings|mute|stop]".to_string()),
|
||||
},
|
||||
SlashCommand::Ide => {
|
||||
self.handle_ide_command_args(trimmed);
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: tui/src/chatwidget/realtime_settings_tests.rs
|
||||
assertion_line: 46
|
||||
expression: lines
|
||||
---
|
||||
• Voice set to juniper. Applies to your next voice conversation.
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/chatwidget/realtime_settings_tests.rs
|
||||
assertion_line: 17
|
||||
expression: "render_bottom_popup(&chat, 80)"
|
||||
---
|
||||
Select voice
|
||||
Applies to your next voice conversation.
|
||||
|
||||
1. juniper
|
||||
› 2. maple (current)
|
||||
3. spruce
|
||||
4. ember
|
||||
5. vale
|
||||
6. breeze
|
||||
7. arbor
|
||||
8. sol
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
---
|
||||
source: tui/src/chatwidget/realtime_settings_tests.rs
|
||||
assertion_line: 67
|
||||
expression: "render_bottom_popup(&chat, 80)"
|
||||
---
|
||||
Select voice
|
||||
Applies to your next voice conversation.
|
||||
|
||||
› 1. cove (current)
|
||||
2. maple
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
Reference in new issue
Block a user