Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(voice): delegate wake-word sequencing to the module

Steven Enamakel13d806c05f5a
diff --git a/crates/openhuman-core/src/modules/voice.rs b/crates/openhuman-core/src/modules/voice.rs
index 18786fbe52..8b6953d089 100644
--- a/crates/openhuman-core/src/modules/voice.rs
+++ b/crates/openhuman-core/src/modules/voice.rs
@@ -87,6 +87,9 @@ fn hallucination_mode_wire(mode: HallucinationMode) -> &'static str {
/// the agent, rather than failing to decode.
pub use tinyvoice_bus::VoiceIntent;
+/// Recording-session vocabulary shared with the loaded TinyVoice module.
+pub use tinyvoice_bus::{GateVerdict, RecordingGates, UtteranceDisposition};
+
/// Native capture lease types shared with the loaded TinyVoice module.
pub use tinyvoice_bus::capture::{
CaptureBatch, CaptureError, CaptureFormat, CaptureHandle, CapturePollRequest, CaptureResult,
@@ -141,42 +144,55 @@ fn clamped(intent: VoiceIntent) -> VoiceIntent {
}
}
-/// Apply the wake-word gate, returning the command that followed it.
+/// Sequence a transcript through the wake-word gate.
///
-/// `None` means the utterance was not addressed to the agent, or the wake word
-/// arrived with nothing after it. Those are the same outcome for a caller, and
-/// the module represents both as an empty string.
+/// The module decides whether an utterance is ignored, a command with the wake
+/// phrase stripped, or a bare wake word; the host only acts on the answer.
///
/// # Errors
///
-/// [`VoiceCallError`] when the module is unavailable or the call fails.
-pub async fn extract_command(
+/// [`VoiceCallError`] when the module is unavailable or the call fails. The
+/// caller must treat that as "ignore": this gate keeps a passing conversation
+/// out of the assistant, so it fails closed.
+pub async fn sequence_utterance(
config: &Config,
transcript: &str,
wake_word: &str,
-) -> Result<Option<String>, VoiceCallError> {
- let command: String = call(config, methods::EXTRACT_COMMAND, (transcript, wake_word)).await?;
- Ok(if command.is_empty() {
- None
- } else {
- Some(command)
- })
+) -> Result<UtteranceDisposition, VoiceCallError> {
+ let json: String = call(
+ config,
+ methods::SEQUENCE_UTTERANCE,
+ (transcript, wake_word),
+ )
+ .await?;
+ serde_json::from_str(&json)
+ .map_err(|e| VoiceCallError::Failed(format!("could not decode disposition: {e}")))
}
-/// Whether the wake word appears near the start of a transcript.
-///
-/// Distinguished from [`extract_command`] so a caller can acknowledge a bare
-/// "Hey Tiny", which otherwise reads to the user as a dead microphone.
+/// Apply the pre-transcription recording gates (minimum duration, silence).
///
/// # Errors
///
/// [`VoiceCallError`] when the module is unavailable or the call fails.
-pub async fn wake_word_present(
+pub async fn gate_recording(
config: &Config,
- transcript: &str,
- wake_word: &str,
-) -> Result<bool, VoiceCallError> {
- call(config, methods::WAKE_WORD_PRESENT, (transcript, wake_word)).await
+ duration_secs: f32,
+ peak_rms: f32,
+ gates: RecordingGates,
+) -> Result<GateVerdict, VoiceCallError> {
+ let json: String = call(
+ config,
+ methods::GATE_RECORDING,
+ (
+ duration_secs,
+ peak_rms,
+ gates.min_duration_secs,
+ gates.silence_threshold,
+ ),
+ )
+ .await?;
+ serde_json::from_str(&json)
+ .map_err(|e| VoiceCallError::Failed(format!("could not decode verdict: {e}")))
}
/// Whether an STT transcript looks like a hallucination rather than speech.
diff --git a/crates/openhuman-core/src/modules/voice_tests.rs b/crates/openhuman-core/src/modules/voice_tests.rs
index 19ad043245..b25e770433 100644
--- a/crates/openhuman-core/src/modules/voice_tests.rs
+++ b/crates/openhuman-core/src/modules/voice_tests.rs
@@ -110,11 +110,20 @@ async fn a_disabled_host_reports_unavailable_without_starting_a_broker() {
Err(VoiceCallError::Unavailable(_))
));
assert!(matches!(
- super::extract_command(&config, "hey tiny pause", "Hey Tiny").await,
+ super::sequence_utterance(&config, "hey tiny pause", "Hey Tiny").await,
Err(VoiceCallError::Unavailable(_))
));
assert!(matches!(
- super::wake_word_present(&config, "hey tiny", "Hey Tiny").await,
+ super::gate_recording(
+ &config,
+ 1.0,
+ 0.5,
+ super::RecordingGates {
+ min_duration_secs: 0.3,
+ silence_threshold: 0.01
+ }
+ )
+ .await,
Err(VoiceCallError::Unavailable(_))
));
assert!(matches!(
@@ -193,20 +202,39 @@ async fn the_published_module_answers_through_this_client() {
VoiceIntent::Unknown
);
assert_eq!(
- super::extract_command(&config, "hey tiny open slack", "Hey Tiny")
+ super::sequence_utterance(&config, "hey tiny open slack", "Hey Tiny")
.await
- .expect("extract"),
- Some("open slack".to_string())
+ .expect("sequence"),
+ super::UtteranceDisposition::Command {
+ command: "open slack".to_string()
+ }
);
assert_eq!(
- super::extract_command(&config, "open slack", "Hey Tiny")
+ super::sequence_utterance(&config, "open slack", "Hey Tiny")
.await
- .expect("extract"),
- None
+ .expect("sequence"),
+ super::UtteranceDisposition::Ignored
);
- assert!(super::wake_word_present(&config, "hey tiny", "Hey Tiny")
+ assert_eq!(
+ super::sequence_utterance(&config, "hey tiny", "Hey Tiny")
+ .await
+ .expect("sequence"),
+ super::UtteranceDisposition::BareWake
+ );
+ assert_eq!(
+ super::gate_recording(
+ &config,
+ 0.1,
+ 0.5,
+ super::RecordingGates {
+ min_duration_secs: 0.3,
+ silence_threshold: 0.01
+ }
+ )
.await
- .expect("present"));
+ .expect("gate"),
+ super::GateVerdict::TooShort
+ );
// The mode split is the reason this call takes a mode at all.
assert!(
@@ -355,7 +383,7 @@ async fn every_entry_point_degrades_rather_than_hanging_when_the_module_is_gone(
Err(VoiceCallError::Unavailable(_))
));
assert!(matches!(
- super::extract_command(&config, "hey tiny pause", "Hey Tiny").await,
+ super::sequence_utterance(&config, "hey tiny pause", "Hey Tiny").await,
Err(VoiceCallError::Unavailable(_))
));
diff --git a/crates/openhuman-core/src/voice/always_on/README.md b/crates/openhuman-core/src/voice/always_on/README.md
index 5d9e2223e6..508bd3003c 100644
--- a/crates/openhuman-core/src/voice/always_on/README.md
+++ b/crates/openhuman-core/src/voice/always_on/README.md
@@ -17,7 +17,7 @@ The split follows the audio callback, not the cost of a call. A module call is a
| [`capture.rs`](./capture.rs) | Reserves and starts a module-owned stream, polls at most two chunks per call, and forwards ordered batches through a bounded host queue. Cancellation releases the opaque lease; failed cleanup remains tracked for retry. |
| [`lock_watcher.rs`](./lock_watcher.rs) | The macOS screen-lock privacy hook. `spawn_lock_watcher` polls `CGSessionCopyCurrentDictionary` every two seconds and flips `PAUSED` on lock/unlock transitions. Other platforms log that the watcher is unavailable and never pause (no lock signal yet). |
| [`processor.rs`](./processor.rs) | Owns the enabled/paused gates, VAD session and transcription tasks. Toggle-off and sign-out stop capture, cancel pending transcriptions and drain the processor before restart. |
-| [`transcribe.rs`](./transcribe.rs) | Transcribes a finished utterance through the configured STT provider (the same factory dispatch `voice.stt_dispatch` uses), applies the wake-word gate (`tinyvoice::extract_command`), and routes recognized commands either to a local fast path (`execute_intent`, media transport and volume via `osascript` on macOS) or, for `VoiceIntent::Unknown` or a failed local execution, to the agent via `crate::voice::dictation_listener::publish_transcription`. |
+| [`transcribe.rs`](./transcribe.rs) | Transcribes a finished utterance through the configured STT provider (the same factory dispatch `voice.stt_dispatch` uses), applies the wake-word gate (`tinyvoice::sequence_utterance`), and routes recognized commands either to a local fast path (`execute_intent`, media transport and volume via `osascript` on macOS) or, for `VoiceIntent::Unknown` or a failed local execution, to the agent via `crate::voice::dictation_listener::publish_transcription`. |
`always_on.rs` (one level up, in `voice/`) is the module entry point: it declares these four submodules, re-exports `start_if_enabled`/`stop`, and holds the shared `LOG_PREFIX` constant.
@@ -30,7 +30,7 @@ The split follows the audio callback, not the cost of a call. A module call is a
## Wake word and privacy
-Transcription is forced to English (`Some("en")`) because auto-detect rendered the wake word in non-Latin scripts that could never match. The wake-word gate fails closed: if `tinyvoice::extract_command` errors, the utterance is dropped rather than delivered unaddressed to the agent. Logs never include the raw transcript or spoken command, only lengths and intent kinds, per the PII-safe logging rule.
+Transcription is forced to English (`Some("en")`) because auto-detect rendered the wake word in non-Latin scripts that could never match. The wake-word gate fails closed: if `tinyvoice::sequence_utterance` errors, the utterance is dropped rather than delivered unaddressed to the agent. Logs never include the raw transcript or spoken command, only lengths and intent kinds, per the PII-safe logging rule.
## Configuration
diff --git a/crates/openhuman-core/src/voice/always_on/transcribe.rs b/crates/openhuman-core/src/voice/always_on/transcribe.rs
index f9a9063e7a..b452fcb807 100644
--- a/crates/openhuman-core/src/voice/always_on/transcribe.rs
+++ b/crates/openhuman-core/src/voice/always_on/transcribe.rs
@@ -62,17 +62,15 @@ pub(super) async fn transcribe_and_deliver(config: &Config, samples_16k: Vec<f32
log::info!("{LOG_PREFIX} empty transcript dropped");
return;
}
- // Wake-word gate: only act on utterances addressed to the agent
- // ("Hey Tiny, …"). Strip the wake phrase and deliver the command.
- // A module failure here must not deliver an unaddressed utterance
- // to the agent: this gate is what keeps a passing conversation out
- // of the assistant, so it fails CLOSED — the opposite of the
- // hallucination filter, where the risk runs the other way.
- let gated =
- match tinyvoice::extract_command(config, &text, &config.voice_server.wake_word)
+ // Wake-word sequencing is owned by the tinyvoice module. A module
+ // failure must not deliver an unaddressed utterance to the agent:
+ // this gate fails CLOSED.
+ use crate::modules::voice::UtteranceDisposition as UD;
+ let disposition =
+ match tinyvoice::sequence_utterance(config, &text, &config.voice_server.wake_word)
.await
{
- Ok(gated) => gated,
+ Ok(d) => d,
Err(error) => {
log::warn!(
"{LOG_PREFIX} wake-word gate unavailable ({error}); dropping the utterance"
@@ -80,35 +78,26 @@ pub(super) async fn transcribe_and_deliver(config: &Config, samples_16k: Vec<f32
return;
}
};
- match gated {
- Some(cmd) => {
+ match disposition {
+ UD::Command { command } => {
// Redacted: never log the raw spoken command (always-on mic PII).
- log::info!("{LOG_PREFIX} wake word matched → cmd_len={}", cmd.len());
+ log::info!("{LOG_PREFIX} wake word matched → cmd_len={}", command.len());
notch_status("Processing", 12000); // pill: running the command
- deliver_command(config, cmd).await;
+ deliver_command(config, command).await;
}
- None => {
- // Presence is only used to choose between acknowledging and
- // staying silent, so an error here degrades to silence.
- let present =
- tinyvoice::wake_word_present(config, &text, &config.voice_server.wake_word)
- .await
- .unwrap_or(false);
- if present {
- // Wake word spoken with no trailing command ("Hey Tiny").
- // Acknowledge with an agent turn so the user gets a reply
- // instead of silence, then they can follow up.
- log::info!("{LOG_PREFIX} bare wake word → acknowledging");
- notch_status("Listening…", 8000);
- deliver_command(config, "hello".to_string()).await;
- } else {
- // Visible at info so the user can see WHAT was heard when the
- // wake word didn't match (diagnoses "Hey Tiny not responding").
- log::info!(
- "{LOG_PREFIX} no wake word ({:?}) in transcript={text:?}; ignored",
- config.voice_server.wake_word
- );
- }
+ UD::BareWake => {
+ // Wake word spoken with no trailing command ("Hey Tiny").
+ // Acknowledge with an agent turn so the user gets a reply.
+ log::info!("{LOG_PREFIX} bare wake word → acknowledging");
+ notch_status("Listening…", 8000);
+ deliver_command(config, "hello".to_string()).await;
+ }
+ UD::Ignored => {
+ log::info!(
+ "{LOG_PREFIX} no wake word ({:?}) in transcript_len={}; ignored",
+ config.voice_server.wake_word,
+ text.len()
+ );
}
}
}