Skip to content

Commit 3cf427a

Browse files
authored
Merge pull request #478: deliver private interactive voice results
Fixes #372. Signed-off-by: Val Alexander <val@opencoven.ai>
2 parents 31e1511 + 2c02422 commit 3cf427a

3 files changed

Lines changed: 260 additions & 61 deletions

File tree

‎src-rust/crates/cli/src/main.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,6 +3447,7 @@ async fn run_interactive(
34473447
app.poll_session_list();
34483448
}
34493449
app.notifications.tick();
3450+
app.poll_voice_events();
34503451

34513452
if handle_file_preparation(&mut app, &mut goal_turn) {
34523453
continue;

‎src-rust/crates/tui/src/app.rs‎

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4038,6 +4038,66 @@ impl App {
40384038
// Voice PTT helpers
40394039
// -----------------------------------------------------------------------
40404040

4041+
/// Drain recorder events without blocking, updating the prompt and notices.
4042+
/// Called before drawing by both interactive event loops.
4043+
pub fn poll_voice_events(&mut self) {
4044+
use claurst_core::voice::VoiceEvent;
4045+
let mut events = Vec::new();
4046+
if let Some(ref mut rx) = self.voice_event_rx {
4047+
while let Ok(ev) = rx.try_recv() {
4048+
events.push(ev);
4049+
}
4050+
}
4051+
for ev in events {
4052+
match ev {
4053+
VoiceEvent::RecordingStarted => {
4054+
self.voice_recording = true;
4055+
self.status_message =
4056+
Some("Recording\u{2026} (Alt+V or Esc to stop)".to_string());
4057+
}
4058+
VoiceEvent::RecordingStopped => {
4059+
self.voice_recording = false;
4060+
self.status_message = Some("Transcribing\u{2026}".to_string());
4061+
}
4062+
VoiceEvent::TranscriptReady(text) => {
4063+
if !text.is_empty() {
4064+
// Append to existing prompt text with a space separator
4065+
// so the user can combine voice + typed input.
4066+
if !self.prompt_input.text.is_empty()
4067+
&& !self.prompt_input.text.ends_with(' ')
4068+
{
4069+
self.prompt_input.paste(" ");
4070+
}
4071+
self.prompt_input.paste(&text);
4072+
self.refresh_prompt_input();
4073+
let preview_end = text
4074+
.char_indices()
4075+
.nth(60)
4076+
.map_or(text.len(), |(index, _)| index);
4077+
self.status_message =
4078+
Some(format!("Transcribed: {}", &text[..preview_end]));
4079+
}
4080+
// Clear the channel once we have the result.
4081+
self.voice_event_rx = None;
4082+
}
4083+
VoiceEvent::Error(msg) => {
4084+
self.voice_recording = false;
4085+
self.voice_event_rx = None;
4086+
// Keep the operation and diagnostic visible in the compact
4087+
// warning row; the Warning severity already signals failure.
4088+
let detail = msg
4089+
.strip_prefix("Transcription failed ")
4090+
.or_else(|| msg.strip_prefix("Transcription API returned "));
4091+
let message = match detail {
4092+
Some(detail) => format!("Voice: Transcription {detail}"),
4093+
None => format!("Voice: {msg}"),
4094+
};
4095+
self.push_notification(NotificationKind::Warning, message, Some(8));
4096+
}
4097+
}
4098+
}
4099+
}
4100+
40414101
/// Start PTT recording: open the microphone capture stream and signal the
40424102
/// UI. No-op when no voice recorder is attached or recording is already
40434103
/// in progress.
@@ -8095,58 +8155,7 @@ impl App {
80958155

80968156
self.poll_session_list();
80978157

8098-
// Drain voice transcription events (non-blocking).
8099-
// When the background recording/transcription task emits a
8100-
// TranscriptReady event we insert the text directly into the
8101-
// prompt so the user can review and submit it.
8102-
{
8103-
use claurst_core::voice::VoiceEvent;
8104-
let mut events = Vec::new();
8105-
if let Some(ref mut rx) = self.voice_event_rx {
8106-
while let Ok(ev) = rx.try_recv() {
8107-
events.push(ev);
8108-
}
8109-
}
8110-
for ev in events {
8111-
match ev {
8112-
VoiceEvent::RecordingStarted => {
8113-
self.voice_recording = true;
8114-
self.status_message =
8115-
Some("Recording\u{2026} (Alt+V or Esc to stop)".to_string());
8116-
}
8117-
VoiceEvent::RecordingStopped => {
8118-
self.voice_recording = false;
8119-
self.status_message = Some("Transcribing\u{2026}".to_string());
8120-
}
8121-
VoiceEvent::TranscriptReady(text) => {
8122-
if !text.is_empty() {
8123-
// Append to existing prompt text with a space separator
8124-
// so the user can combine voice + typed input.
8125-
if !self.prompt_input.text.is_empty()
8126-
&& !self.prompt_input.text.ends_with(' ')
8127-
{
8128-
self.prompt_input.paste(" ");
8129-
}
8130-
self.prompt_input.paste(&text);
8131-
self.refresh_prompt_input();
8132-
self.status_message =
8133-
Some(format!("Transcribed: {}", &text[..text.len().min(60)]));
8134-
}
8135-
// Clear the channel once we have the result.
8136-
self.voice_event_rx = None;
8137-
}
8138-
VoiceEvent::Error(msg) => {
8139-
self.voice_recording = false;
8140-
self.voice_event_rx = None;
8141-
self.push_notification(
8142-
NotificationKind::Warning,
8143-
format!("Voice: {}", msg),
8144-
Some(8),
8145-
);
8146-
}
8147-
}
8148-
}
8149-
}
8158+
self.poll_voice_events();
81508159

81518160
// Draw the frame, and immediately scan the *just-rendered*
81528161
// buffer for URL runs. ratatui swaps its two buffers at the

0 commit comments

Comments
 (0)