Skip to content

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

feat: move hotkey listeners to TinyVoice module

Steven Enamakel4191c2076e65
diff --git a/Cargo.lock b/Cargo.lock
index 6cb561efe4..1e59f4e76c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -511,12 +511,6 @@ dependencies = [
"digest 0.10.7",
]
-[[package]]
-name = "block"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
-
[[package]]
name = "block-buffer"
version = "0.10.4"
@@ -930,21 +924,6 @@ version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
-[[package]]
-name = "cocoa"
-version = "0.22.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7"
-dependencies = [
- "bitflags 1.3.2",
- "block",
- "core-foundation 0.9.4",
- "core-graphics 0.21.0",
- "foreign-types",
- "libc",
- "objc",
-]
-
[[package]]
name = "coins-bip32"
version = "0.13.2"
@@ -1121,23 +1100,13 @@ dependencies = [
"unicode-segmentation",
]
-[[package]]
-name = "core-foundation"
-version = "0.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
-dependencies = [
- "core-foundation-sys 0.7.0",
- "libc",
-]
-
[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"libc",
]
@@ -1147,46 +1116,16 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6"
dependencies = [
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"libc",
]
-[[package]]
-name = "core-foundation-sys"
-version = "0.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
-
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
-[[package]]
-name = "core-graphics"
-version = "0.19.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923"
-dependencies = [
- "bitflags 1.3.2",
- "core-foundation 0.7.0",
- "foreign-types",
- "libc",
-]
-
-[[package]]
-name = "core-graphics"
-version = "0.21.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978"
-dependencies = [
- "bitflags 1.3.2",
- "core-foundation 0.9.4",
- "foreign-types",
- "libc",
-]
-
[[package]]
name = "coreaudio-rs"
version = "0.14.2"
@@ -2705,7 +2644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
dependencies = [
"android_system_properties",
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
@@ -3450,15 +3389,6 @@ dependencies = [
"hashify",
]
-[[package]]
-name = "malloc_buf"
-version = "0.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
-dependencies = [
- "libc",
-]
-
[[package]]
name = "matchers"
version = "0.2.0"
@@ -3913,15 +3843,6 @@ dependencies = [
"libc",
]
-[[package]]
-name = "objc"
-version = "0.2.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
-dependencies = [
- "malloc_buf",
-]
-
[[package]]
name = "objc2"
version = "0.6.4"
@@ -5296,22 +5217,6 @@ dependencies = [
"unicode-width",
]
-[[package]]
-name = "rdev"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00552ca2dc2f93b84cd7b5581de49549411e4e41d89e1c691bcb93dc4be360c3"
-dependencies = [
- "cocoa",
- "core-foundation 0.7.0",
- "core-foundation-sys 0.7.0",
- "core-graphics 0.19.2",
- "lazy_static",
- "libc",
- "winapi",
- "x11",
-]
-
[[package]]
name = "redox_syscall"
version = "0.5.18"
@@ -5655,7 +5560,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1167586491e2b18b8bfbb293e8180ec17c201c4f076d7cb3070ca964e7598f98"
dependencies = [
"core-foundation 0.10.1",
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"jni",
"log",
"once_cell",
@@ -5781,7 +5686,7 @@ checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
dependencies = [
"bitflags 2.13.2",
"core-foundation 0.9.4",
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"libc",
"security-framework-sys",
]
@@ -5794,7 +5699,7 @@ checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
dependencies = [
"bitflags 2.13.2",
"core-foundation 0.10.1",
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"libc",
"security-framework-sys",
]
@@ -5805,7 +5710,7 @@ version = "2.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3"
dependencies = [
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"libc",
]
@@ -6479,7 +6384,7 @@ version = "0.33.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fc858248ea01b66f19d8e8a6d55f41deaf91e9d495246fd01368d99935c6c01"
dependencies = [
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"libc",
"memchr",
"ntapi",
@@ -6503,7 +6408,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
dependencies = [
- "core-foundation-sys 0.8.7",
+ "core-foundation-sys",
"libc",
]
@@ -7613,13 +7518,11 @@ checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee"
[[package]]
name = "tinyvoice"
-version = "0.1.12"
+version = "0.1.14"
dependencies = [
"cpal",
"log",
"parking_lot",
- "rdev",
- "serde",
"thiserror 2.0.20",
"tinyvoice-bus",
"tokio",
@@ -9262,16 +9165,6 @@ dependencies = [
"tap",
]
-[[package]]
-name = "x11"
-version = "2.21.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e"
-dependencies = [
- "libc",
- "pkg-config",
-]
-
[[package]]
name = "x25519-dalek"
version = "2.0.1"
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index 7a3749a877..5f4f48182a 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -465,11 +465,10 @@ tinydocs-bus = { path = "../../vendor/tinydocs/crates/tinydocs-bus", optional =
# Optional: exclusive to the `voice` feature — default-OFF, product-ON, the
# same split as `documents` above.
tinyvoice-bus = { path = "../../vendor/tinyvoice/crates/tinyvoice-bus", optional = true }
-# The global push-to-talk hotkey listener (`voice::hotkey`) and the `cpal`
-# microphone capture (`voice::audio_capture`, `voice::always_on`) live in the
-# `tinyvoice` library behind its off-by-default `hotkey` and `capture` features (it owns the
-# `rdev` dependency). Linked as a library, not loaded as the module.
-tinyvoice = { path = "../../vendor/tinyvoice/crates/tinyvoice", default-features = false, features = ["hotkey", "capture"], optional = true }
+# `cpal` microphone capture (`voice::audio_capture`, `voice::always_on`) remains
+# on the library path until its module-owned lifecycle contract is released.
+# Hotkeys are already owned by the loaded TinyVoice module.
+tinyvoice = { path = "../../vendor/tinyvoice/crates/tinyvoice", default-features = false, features = ["capture"], optional = true }
# TinyJuice — the compression wire contract, and nothing else.
#
diff --git a/crates/openhuman-core/src/modules/registry/records_voice.rs b/crates/openhuman-core/src/modules/registry/records_voice.rs
index fe48582a37..5afb945e17 100644
--- a/crates/openhuman-core/src/modules/registry/records_voice.rs
+++ b/crates/openhuman-core/src/modules/registry/records_voice.rs
@@ -13,71 +13,72 @@ use crate::modules::types::{LoadPolicy, ModuleRecord, PlatformAsset};
/// — so a session that never speaks should not pay a download or a `dlopen`.
///
/// **The VAD deliberately does not come through here.** A segmenter is driven
-/// once per 20 ms frame from inside a `cpal` callback, and a bus round trip at
-/// that cadence would cost more than the sixty-line state machine it replaces.
-/// `voice::always_on` keeps its own; see [`super::voice`].
+/// Continuous capture and its device callback are module-owned and read in
+/// bounded batches. The VAD remains in the host because it is a local
+/// per-frame policy loop; captured samples cross the bus in bounded batches,
+/// never through a call made from the audio callback. See [`super::voice`].
pub(crate) const TINYVOICE: ModuleRecord = ModuleRecord {
id: "tinyvoice",
description: "Wake-word gating, command routing, hallucination detection, capture audio",
bus_name: "ai.tinyhumans.tinyvoice.Voice",
object_path: "/ai/tinyhumans/tinyvoice/Voice",
- version: "0.1.12",
- release_url: "https://github.com/tinyhumansai/tinyvoice/releases/tag/v0.1.12",
+ version: "0.1.14",
+ release_url: "https://github.com/tinyhumansai/tinyvoice/releases/tag/v0.1.14",
assets: &[
PlatformAsset {
host_key: "ubuntu-24.04-x86_64",
- archive: "tinyvoice-module-0.1.12-ubuntu-24.04-x86_64.tar.gz",
- sha256: "7aa0efa8ca6bd9553c7c318f1c96d7535917fbdf7f4e73e6af0bfe69fac42f67",
+ archive: "tinyvoice-module-0.1.14-ubuntu-24.04-x86_64.tar.gz",
+ sha256: "682b56ec246e021708a71a587a9fa55625c3964b10676f9d1220ee4eccdd55a1",
},
PlatformAsset {
host_key: "ubuntu-24.04-arm64",
- archive: "tinyvoice-module-0.1.12-ubuntu-24.04-arm64.tar.gz",
- sha256: "0035bd13161dca209ee96fc971025c0387fc58d30ef9d5c79ac8e4b0e522ff9e",
+ archive: "tinyvoice-module-0.1.14-ubuntu-24.04-arm64.tar.gz",
+ sha256: "87cde6de6da8c9d9f392fe43a8547be861363596f64a326cf9deb985e260762d",
},
PlatformAsset {
host_key: "ubuntu-22.04-x86_64",
- archive: "tinyvoice-module-0.1.12-ubuntu-22.04-x86_64.tar.gz",
- sha256: "ff201a53f4370c79c0ea70cb3649641f48f941022db86ae8f382098ec88c0f27",
+ archive: "tinyvoice-module-0.1.14-ubuntu-22.04-x86_64.tar.gz",
+ sha256: "9bab7b7d6d5e36526f13a02209cd3454ea53ecf8ba68894ffa5f2376765cab71",
},
PlatformAsset {
host_key: "ubuntu-22.04-arm64",
- archive: "tinyvoice-module-0.1.12-ubuntu-22.04-arm64.tar.gz",
- sha256: "d49fba688acf2779b551c2799f0fecd2afe4fe1ce72c5c37980a51999eb0eb55",
+ archive: "tinyvoice-module-0.1.14-ubuntu-22.04-arm64.tar.gz",
+ sha256: "2c77ed20a9745086a1d8e481a7719accaff82464b546671b0070b78610e77628",
},
PlatformAsset {
host_key: "macos-26-arm64",
- archive: "tinyvoice-module-0.1.12-macos-26-arm64.tar.gz",
- sha256: "88bcaefbbef19a208b7c7c43739f2f39081a44f335105bdd4ce85b54945e8ffb",
+ archive: "tinyvoice-module-0.1.14-macos-26-arm64.tar.gz",
+ sha256: "f2856e78eda2f53cacc4799c2a068a5626779f01bff60a792c1f7e37c56324cb",
},
PlatformAsset {
host_key: "macos-26-x86_64",
- archive: "tinyvoice-module-0.1.12-macos-26-x86_64.tar.gz",
- sha256: "32054a8c995106cb7af21b4fc2b66772b67b85b41a280d457337480ecab4d395",
+ archive: "tinyvoice-module-0.1.14-macos-26-x86_64.tar.gz",
+ sha256: "e4ff4337bcb4fa60c3549e83fe573060d8669b744996fa75d321542b8e6841f3",
},
PlatformAsset {
host_key: "macos-15-arm64",
- archive: "tinyvoice-module-0.1.12-macos-15-arm64.tar.gz",
- sha256: "1444a6dda431b83ab719ecc0d098b58af8ede42f652ed806fb259968d94ce9c1",
+ archive: "tinyvoice-module-0.1.14-macos-15-arm64.tar.gz",
+ sha256: "c3e6a29cd39617d91463d4315e1dfe432a12f0579116173efac4406a9e2d65a7",
},
PlatformAsset {
host_key: "macos-15-x86_64",
- archive: "tinyvoice-module-0.1.12-macos-15-x86_64.tar.gz",
- sha256: "0e2a3f11e333324837748b55562a64279cb01d33826a07f2258b8fb1fedfbee3",
+ archive: "tinyvoice-module-0.1.14-macos-15-x86_64.tar.gz",
+ sha256: "86d9e654391cf09dc40ac27e0128d614b03ff3853e9bb010b9b31d914e0b1f23",
},
PlatformAsset {
host_key: "windows-2025-x86_64",
- archive: "tinyvoice-module-0.1.12-windows-2025-x86_64.zip",
- sha256: "475389e407754c3c73adb5e61bc3113b9538e50c50e71c23ea5f92d6b934ccd8",
+ archive: "tinyvoice-module-0.1.14-windows-2025-x86_64.zip",
+ sha256: "f6a636891710c7443306fdcf6067f24b72b1b98a9873596669377540da0b037b",
},
PlatformAsset {
host_key: "windows-2022-x86_64",
- archive: "tinyvoice-module-0.1.12-windows-2022-x86_64.zip",
- sha256: "43149836ee514f27fd5f639cd7b84d287df689cc8658c45e1a41d6960fbfc387",
+ archive: "tinyvoice-module-0.1.14-windows-2022-x86_64.zip",
+ sha256: "e5b538e69dfc0cec83adcb6240f09d6d0cb126df76621f8eb63b5da901119baa",
},
PlatformAsset {
host_key: "windows-11-arm64",
- archive: "tinyvoice-module-0.1.12-windows-11-arm64.zip",
- sha256: "d11e59f3e16aab98f699edb37e3d6716469f278a961d39794f832000296be315",
+ archive: "tinyvoice-module-0.1.14-windows-11-arm64.zip",
+ sha256: "8452b6099a0a1debe412e3e69f8591756c5ea49f9e5a112f138fe2e590a0a418",
},
],
load: LoadPolicy::Lazy,
diff --git a/crates/openhuman-core/src/modules/voice.rs b/crates/openhuman-core/src/modules/voice.rs
index f24c1a0a7d..b215cc5412 100644
--- a/crates/openhuman-core/src/modules/voice.rs
+++ b/crates/openhuman-core/src/modules/voice.rs
@@ -87,6 +87,19 @@ fn hallucination_mode_wire(mode: HallucinationMode) -> &'static str {
/// the agent, rather than failing to decode.
pub use tinyvoice_bus::VoiceIntent;
+/// Native capture lease types shared with the loaded TinyVoice module.
+pub use tinyvoice_bus::capture::{
+ CaptureBatch, CaptureError, CaptureFormat, CaptureHandle, CapturePollRequest, CaptureResult,
+ CaptureStream, MicrophonePermission, RawChunk, RecordingFinishRequest, RecordingStartRequest,
+};
+
+/// Hotkey lifecycle types shared with the loaded TinyVoice module.
+pub use tinyvoice_bus::hotkey::{
+ ActivationMode, HostKeyFact, HotkeyBatch, HotkeyError, HotkeyEvent, HotkeyFeedRequest,
+ HotkeyHandle, HotkeyHandleRequest, HotkeyReadRequest, HotkeyReply, HotkeyRequest,
+ HotkeyReserveRequest, HotkeySource, HotkeyStartRequest, HotkeyState, SequencedHostFact,
+};
+
/// Classify a command transcript into a fast-path intent.
///
/// The transcript should already have had its wake word removed by
@@ -433,6 +446,122 @@ pub async fn ensure_ready(config: &Config) -> Result<(), VoiceCallError> {
.map_err(VoiceCallError::Unavailable)
}
+/// Reserve an opaque handle before native microphone startup.
+pub async fn reserve_capture(
+ config: &Config,
+ permission: MicrophonePermission,
+) -> Result<CaptureResult<CaptureHandle>, VoiceCallError> {
+ call(
+ config,
+ methods::RESERVE_CAPTURE,
+ (RecordingStartRequest {
+ permission,
+ handle: None,
+ },),
+ )
+ .await
+}
+
+/// Start module-owned continuous capture under a known reservation.
+pub async fn start_capture(
+ config: &Config,
+ handle: CaptureHandle,
+ permission: MicrophonePermission,
+) -> Result<CaptureResult<CaptureStream>, VoiceCallError> {
+ call(
+ config,
+ methods::CAPTURE_START,
+ (RecordingStartRequest {
+ permission,
+ handle: Some(handle),
+ },),
+ )
+ .await
+}
+
+/// Read at most two native audio chunks in one bounded bus request.
+pub async fn poll_capture(
+ config: &Config,
+ request: CapturePollRequest,
+) -> Result<CaptureResult<CaptureBatch>, VoiceCallError> {
+ call(config, methods::CAPTURE_POLL, (request,)).await
+}
+
+/// Stop one capture stream and wait for native resource cleanup.
+pub async fn stop_capture(
+ config: &Config,
+ handle: CaptureHandle,
+) -> Result<CaptureResult<()>, VoiceCallError> {
+ call(config, methods::CAPTURE_STOP, (handle,)).await
+}
+
+/// Shut down all capture leases and wait for their native cleanup.
+pub async fn shutdown_capture(config: &Config) -> Result<CaptureResult<()>, VoiceCallError> {
+ call(config, methods::CAPTURE_SHUTDOWN, ()).await
+}
+
+/// Reserve a native or host-fed hotkey listener before startup.
+pub async fn reserve_hotkey(
+ config: &Config,
+ request: HotkeyRequest,
+) -> Result<Result<HotkeyHandle, HotkeyError>, VoiceCallError> {
+ call(
+ config,
+ methods::HOTKEY_RESERVE,
+ (HotkeyReserveRequest { request },),
+ )
+ .await
+}
+
+/// Start a reserved listener. Repeated starts recover a lost reply.
+pub async fn start_hotkey(
+ config: &Config,
+ handle: HotkeyHandle,
+) -> Result<Result<HotkeyReply, HotkeyError>, VoiceCallError> {
+ call(
+ config,
+ methods::HOTKEY_START,
+ (HotkeyStartRequest { handle },),
+ )
+ .await
+}
+
+/// Read an acknowledged/replayable batch of activation events.
+pub async fn read_hotkey(
+ config: &Config,
+ request: HotkeyReadRequest,
+) -> Result<Result<HotkeyBatch, HotkeyError>, VoiceCallError> {
+ call(config, methods::HOTKEY_READ, (request,)).await
+}
+
+/// Feed a bounded batch of host-owned generic key facts.
+pub async fn feed_hotkey(
+ config: &Config,
+ request: HotkeyFeedRequest,
+) -> Result<Result<HotkeyReply, HotkeyError>, VoiceCallError> {
+ call(config, methods::HOTKEY_FEED, (request,)).await
+}
+
+/// Stop a listener after its native hook has been removed and joined.
+pub async fn stop_hotkey(
+ config: &Config,
+ handle: HotkeyHandle,
+) -> Result<Result<HotkeyReply, HotkeyError>, VoiceCallError> {
+ call(
+ config,
+ methods::HOTKEY_STOP,
+ (HotkeyHandleRequest { handle },),
+ )
+ .await
+}
+
+/// Shut down every listener and wait for native cleanup.
+pub async fn shutdown_hotkeys(
+ config: &Config,
+) -> Result<Result<HotkeyReply, HotkeyError>, VoiceCallError> {
+ call(config, methods::HOTKEY_SHUTDOWN, ()).await
+}
+
/// Base64 little-endian `f32`, which is how the interface carries samples.
fn encode_samples(samples: &[f32]) -> String {
use base64::Engine as _;
diff --git a/crates/openhuman-core/src/security/credentials/ops/gated_services.rs b/crates/openhuman-core/src/security/credentials/ops/gated_services.rs
index 36e5997fe8..78075d4a9c 100644
--- a/crates/openhuman-core/src/security/credentials/ops/gated_services.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/gated_services.rs
@@ -206,7 +206,7 @@ pub async fn stop_credential_gated_services(config: &Config) {
// 5. Dictation listener — abort the hotkey forwarder task so it doesn't
// accumulate duplicate rdev listeners across logout → login cycles.
- crate::voice::dictation_listener::stop();
+ crate::voice::dictation_listener::stop().await;
// 6. Always-on listening — disable the runtime gate so the mic capture loop
// stops transcribing/delivering after logout (no audio processed while
diff --git a/crates/openhuman-core/src/voice/README.md b/crates/openhuman-core/src/voice/README.md
index 9391c3e13b..3ec56be016 100644
--- a/crates/openhuman-core/src/voice/README.md
+++ b/crates/openhuman-core/src/voice/README.md
@@ -141,8 +141,8 @@ through `publish_transcription` / `subscribe_transcription_results`. The
Socket.IO server in `crates/openhuman-rpc/src/server/socketio.rs` subscribes to
both and forwards them to clients, which is how hotkeys and results reach the
frontend without Tauri-side shortcut registration. The same file starts and
-stops the core-side rdev listener (`start_if_enabled` / `stop`) and normalizes
-hotkey strings with `normalize_hotkey_for_rdev`.
+stops TinyVoice's native listener (`start_if_enabled` / `stop`) and normalizes
+product hotkey strings before passing them to the module.
Typed events go through the process-wide `BUS`. [`bus.rs`](./bus.rs) publishes
`DomainEvent::Voice(VoiceEvent::PttTranscriptCommitted)` with the thread id,
@@ -245,8 +245,8 @@ per tick would multiply request count for text the client discards.
| [`server.rs`](./server.rs), [`server/`](./server/) | The `VoiceServer` dictation runtime: hotkey loop, recording lifecycle, gates, delivery, global singleton. [README](server/README.md). |
| [`always_on.rs`](./always_on.rs), [`always_on/`](./always_on/) | VAD-driven continuous listening, screen-lock pause, wake word and intent routing. [README](always_on/README.md). |
| [`audio_capture.rs`](./audio_capture.rs) | Microphone recording to 16 kHz mono WAV (`start_recording`, `RecordingHandle`, `RecordingResult`, `list_input_devices`) with peak RMS and the host microphone-permission policy. The `cpal` stream is `tinyvoice::capture`. |
-| [`hotkey.rs`](./hotkey.rs) | Re-export of `tinyvoice::hotkey`: `ActivationMode`, `HotkeyEvent`, `HotkeyCombination`, `parse_hotkey`, `start_listener`. Its tests live in tinyvoice. |
-| [`dictation_listener.rs`](./dictation_listener.rs) | The two broadcast channels and the core-side rdev listener lifecycle. |
+| [`hotkey.rs`](./hotkey.rs) | Re-export of TinyVoice bus hotkey vocabulary. TinyVoice owns native listener parsing and lifecycle. |
+| [`dictation_listener.rs`](./dictation_listener.rs) | The two broadcast channels and host event-forwarding lifecycle over TinyVoice's native listener. |
| [`bus.rs`](./bus.rs) | `publish_ptt_transcript_committed`. |
| `live/` | Live voice agents: `providers.rs`, `session.rs`, `ws.rs` (`http-server` only), `persist.rs`, `ops.rs` / `schemas.rs` (`voice.live_*`), `types.rs`, `error.rs`, and `prompt.md` (voice guidance for the model). |
| [`realtime.rs`](./realtime.rs) | `mint_voice_agent_signed_url`: a short-lived signed WebSocket URL from the backend's `/voice-agent/get-signed-url`. The provider API key never leaves the server. |
@@ -333,9 +333,9 @@ count, rolling recent-transcript buffer) behind a `OnceCell` singleton.
`crate::modules::voice` with its contract in `tinyvoice-bus`) owns frame
preparation, resampling, energies, WAV encoding, the VAD session, wake-word
detection, command/intent routing and `is_hallucinated`. The `tinyvoice`
- library, linked directly with its `hotkey` and `capture` features, owns the
- `rdev` listener and the `cpal` stream. This folder owns only the policy
- around them.
+ module owns native hotkey parsing, event capture and listener cleanup. The
+ library capture feature still owns the `cpal` stream until the module capture
+ lifecycle cut lands; this folder owns microphone permission policy.
- The compiled TinyComputer module owns text insertion, focused-text inspection,
permission decisions and the macOS Swift Globe listener. OpenHuman uses
`tinycomputer-bus` vocabulary and confidential focus/paste calls. Globe events
@@ -380,12 +380,12 @@ server, listener and always-on mode when gating credentials change),
- `voice` pulls in `inference`, `modules`, `tinyvoice`
and the email channel (for `audio_toolkit`), so a voice-less build sheds a
large dependency stack. `streaming` additionally needs `http-server`.
-- macOS hotkeys (#2677): rdev's CGEventTap callback calls
+- macOS hotkeys (#2677): rdev's former CGEventTap callback called
`TSMGetInputSourceProperty` off the main thread, which crashes with
`EXC_BREAKPOINT` on macOS 26. On macOS `dictation_listener::start_if_enabled`
is a no-op and the dictation server accepts only the `fn` (Globe) key through
- the Swift listener; any other key returns an error. Other platforms use rdev
- for all keys.
+ the Swift listener; any other key returns an error. Other platforms use the
+ TinyVoice module's native listener.
- Approval classification differs by path. Reply speech is internal: if it is
ever wrapped in a `Tool`, `external_effect()` must stay `false` so TTS never
prompts (#1339, #1206). Realtime harness and live turns are external-channel
diff --git a/crates/openhuman-core/src/voice/dictation_listener.rs b/crates/openhuman-core/src/voice/dictation_listener.rs
index ef695cd7fe..d967a2c801 100644
--- a/crates/openhuman-core/src/voice/dictation_listener.rs
+++ b/crates/openhuman-core/src/voice/dictation_listener.rs
@@ -1,6 +1,6 @@
//! Core-side dictation hotkey listener.
//!
-//! Reads the `DictationConfig` from config, starts an `rdev`-based global
+//! Reads the `DictationConfig` from config, starts a module-owned global
//! hotkey listener on the core process, and broadcasts `dictation:toggle`
//! events over a `tokio::sync::broadcast` channel that the Socket.IO
//! bridge subscribes to — so the frontend receives hotkey presses without
@@ -11,20 +11,20 @@ use serde::Serialize;
use std::sync::Mutex;
use tokio::sync::broadcast;
use tokio::task::JoinHandle;
+use tokio_util::sync::CancellationToken;
use crate::config::Config;
-// The rdev-based listener (non-macOS) resolves the hotkey combo + activation mode
-// against the cross-platform `hotkey` module. macOS uses a separate path and
-// never compiles `start_rdev_listener`, so gate the import to avoid an unused
-// import warning there.
+// macOS keeps the Tauri-owned global shortcut. Other platforms use TinyVoice's
+// module-owned native listener through the same adapter as the voice server.
#[cfg(not(target_os = "macos"))]
-use super::hotkey::{self, ActivationMode, HotkeyEvent};
+use super::hotkey::{ActivationMode, HotkeyEvent};
const LOG_PREFIX: &str = "[dictation_listener]";
// ── Listener task handle (for stop support) ─────────────────────────
-static LISTENER_HANDLE: Lazy<Mutex<Option<JoinHandle<()>>>> = Lazy::new(|| Mutex::new(None));
+static LISTENER_HANDLE: Lazy<Mutex<Option<(CancellationToken, JoinHandle<()>)>>> =
+ Lazy::new(|| Mutex::new(None));
// ── Broadcast channel for dictation events ────────────────────────────
@@ -129,41 +129,42 @@ pub async fn start_if_enabled(config: &Config) {
);
}
- // Non-macOS: start the rdev-based listener.
+ // Non-macOS: start the TinyVoice-owned native listener.
#[cfg(not(target_os = "macos"))]
- start_rdev_listener(hotkey_str, config).await;
+ start_module_listener(hotkey_str, config).await;
}
#[cfg(not(target_os = "macos"))]
-async fn start_rdev_listener(hotkey_str: String, config: &Config) {
+async fn start_module_listener(hotkey_str: String, config: &Config) {
// Map DictationActivationMode to our hotkey ActivationMode.
let mode = match config.dictation.activation_mode {
crate::config::DictationActivationMode::Push => ActivationMode::Push,
crate::config::DictationActivationMode::Toggle => ActivationMode::Tap,
};
- // Normalize the hotkey string for rdev (CmdOrCtrl → ctrl on non-macOS).
- let normalized = normalize_hotkey_for_rdev(&hotkey_str);
+ // Normalize the product spelling before passing it to TinyVoice.
+ let normalized = normalize_hotkey(&hotkey_str);
log::info!(
"{LOG_PREFIX} starting dictation hotkey listener: hotkey={normalized} (raw={hotkey_str}) mode={mode:?}"
);
- let combo = match hotkey::parse_hotkey(&normalized) {
- Ok(c) => c,
- Err(e) => {
- log::warn!("{LOG_PREFIX} failed to parse hotkey '{normalized}': {e}");
- return;
- }
- };
-
- let (listener_handle, mut hotkey_rx) = match hotkey::start_listener(combo, mode) {
- Ok(pair) => pair,
- Err(e) => {
- log::warn!("{LOG_PREFIX} failed to start hotkey listener: {e}");
- return;
- }
- };
+ let cancel = CancellationToken::new();
+ let (listener, mut hotkey_rx) =
+ match crate::voice::server::hotkey_listener::start_hotkey_listener(
+ config,
+ &normalized,
+ mode,
+ &cancel,
+ )
+ .await
+ {
+ Ok(pair) => pair,
+ Err(e) => {
+ log::warn!("{LOG_PREFIX} failed to start hotkey listener: {e}");
+ return;
+ }
+ };
let mode_str = match mode {
ActivationMode::Tap => "toggle",
@@ -173,11 +174,16 @@ async fn start_rdev_listener(hotkey_str: String, config: &Config) {
log::info!("{LOG_PREFIX} dictation hotkey active: {normalized}");
// Forward hotkey events to the broadcast channel.
+ let task_cancel = cancel.clone();
let task = tokio::spawn(async move {
- // Keep the listener handle alive for the lifetime of this task.
- let _handle = listener_handle;
-
- while let Some(event) = hotkey_rx.recv().await {
+ loop {
+ let event = tokio::select! {
+ _ = task_cancel.cancelled() => break,
+ event = hotkey_rx.recv() => match event {
+ Some(event) => event,
+ None => break,
+ },
+ };
let event_type = match event {
HotkeyEvent::Pressed => "pressed",
HotkeyEvent::Released => "released",
@@ -192,33 +198,39 @@ async fn start_rdev_listener(hotkey_str: String, config: &Config) {
});
}
- log::warn!("{LOG_PREFIX} hotkey event channel closed, listener stopping");
+ listener.stop().await;
+ log::debug!("{LOG_PREFIX} hotkey listener stopped");
});
// Store handle so `stop()` can abort it on logout.
if let Ok(mut guard) = LISTENER_HANDLE.lock() {
- *guard = Some(task);
+ *guard = Some((cancel, task));
}
}
/// Stop the dictation hotkey listener if running.
///
-/// Aborts the spawned forwarder task and drops the `rdev` listener handle,
-/// preventing duplicate hotkey listeners from accumulating across
-/// logout → login cycles.
-pub fn stop() {
- if let Ok(mut guard) = LISTENER_HANDLE.lock() {
- if let Some(handle) = guard.take() {
- handle.abort();
+/// Cancels the event forwarder and joins TinyVoice's native listener cleanup,
+/// preventing duplicate hooks from accumulating across logout → login cycles.
+pub async fn stop() {
+ let listener = LISTENER_HANDLE
+ .lock()
+ .ok()
+ .and_then(|mut guard| guard.take());
+ if let Some((cancel, handle)) = listener {
+ cancel.cancel();
+ if let Err(error) = handle.await {
+ log::warn!("{LOG_PREFIX} dictation listener task ended: {error}");
+ } else {
log::info!("{LOG_PREFIX} dictation listener stopped");
}
}
}
-/// Normalize a Tauri-style hotkey string to rdev-compatible format.
+/// Normalize the host-style hotkey spelling for TinyVoice's portable parser.
///
/// Converts `CmdOrCtrl+Shift+D` → `cmd+shift+d` (macOS) or `ctrl+shift+d` (other).
-fn normalize_hotkey_for_rdev(hotkey: &str) -> String {
+fn normalize_hotkey(hotkey: &str) -> String {
let parts: Vec<&str> = hotkey.split('+').map(|s| s.trim()).collect();
let mut result = Vec::new();
diff --git a/crates/openhuman-core/src/voice/dictation_listener_tests.rs b/crates/openhuman-core/src/voice/dictation_listener_tests.rs
index 0100f8a22d..659935235f 100644
--- a/crates/openhuman-core/src/voice/dictation_listener_tests.rs
+++ b/crates/openhuman-core/src/voice/dictation_listener_tests.rs
@@ -2,7 +2,7 @@ use super::*;
#[test]
fn normalize_cmdorctrl_macos() {
- let result = normalize_hotkey_for_rdev("CmdOrCtrl+Shift+D");
+ let result = normalize_hotkey("CmdOrCtrl+Shift+D");
if cfg!(target_os = "macos") {
assert_eq!(result, "cmd+shift+d");
} else {
@@ -12,12 +12,12 @@ fn normalize_cmdorctrl_macos() {
#[test]
fn normalize_plain_keys() {
- assert_eq!(normalize_hotkey_for_rdev("Ctrl+Space"), "ctrl+space");
+ assert_eq!(normalize_hotkey("Ctrl+Space"), "ctrl+space");
}
#[test]
fn normalize_preserves_structure() {
- assert_eq!(normalize_hotkey_for_rdev("Alt+Shift+F5"), "alt+shift+f5");
+ assert_eq!(normalize_hotkey("Alt+Shift+F5"), "alt+shift+f5");
}
#[test]
@@ -48,7 +48,7 @@ fn publish_transcription_reaches_subscriber() {
#[test]
fn normalize_commandorcontrol_alias() {
- let result = normalize_hotkey_for_rdev("CommandOrControl+Alt+K");
+ let result = normalize_hotkey("CommandOrControl+Alt+K");
if cfg!(target_os = "macos") {
assert_eq!(result, "cmd+alt+k");
} else {
@@ -130,22 +130,22 @@ async fn start_if_enabled_is_noop_on_macos_with_fn_hotkey() {
#[test]
fn normalize_maps_shift_and_alt_verbatim() {
- let result = normalize_hotkey_for_rdev("Shift+Alt+D");
+ let result = normalize_hotkey("Shift+Alt+D");
assert_eq!(result, "shift+alt+d");
}
#[test]
fn normalize_handles_lowercase_input() {
- assert_eq!(normalize_hotkey_for_rdev("cmd+d"), "cmd+d");
+ assert_eq!(normalize_hotkey("cmd+d"), "cmd+d");
}
#[test]
fn normalize_preserves_function_keys() {
- assert_eq!(normalize_hotkey_for_rdev("F12"), "f12");
+ assert_eq!(normalize_hotkey("F12"), "f12");
}
#[test]
fn normalize_trims_whitespace_between_segments() {
- let result = normalize_hotkey_for_rdev(" cmd + shift + d ");
+ let result = normalize_hotkey(" cmd + shift + d ");
assert_eq!(result, "cmd+shift+d");
}
diff --git a/crates/openhuman-core/src/voice/hotkey.rs b/crates/openhuman-core/src/voice/hotkey.rs
index 3b38621b9e..85fea6c913 100644
--- a/crates/openhuman-core/src/voice/hotkey.rs
+++ b/crates/openhuman-core/src/voice/hotkey.rs
@@ -1,9 +1,7 @@
//! Global hotkey listener.
//!
-//! The rdev-based listener, the key-name table, `ActivationMode`,
-//! `HotkeyEvent`, `HotkeyCombination`, `parse_hotkey` and `start_listener` live
-//! in the `tinyvoice` library (`tinyvoice::hotkey`, behind its `hotkey`
-//! feature). This module keeps the `crate::voice::hotkey` path stable for the
-//! dictation server and CLI.
+//! `ActivationMode` and `HotkeyEvent` are shared wire vocabulary from the
+//! TinyVoice bus contract. Native listeners and key parsing live inside the
+//! loaded TinyVoice module.
-pub use tinyvoice::hotkey::*;
+pub use tinyvoice_bus::hotkey::*;
diff --git a/crates/openhuman-core/src/voice/server.rs b/crates/openhuman-core/src/voice/server.rs
index 48cf16278f..91dc3812f5 100644
--- a/crates/openhuman-core/src/voice/server.rs
+++ b/crates/openhuman-core/src/voice/server.rs
@@ -8,13 +8,13 @@
//! ## Module layout
//!
//! - [`types`] — run state, status snapshot, and server config.
-//! - [`hotkey_listener`] — rdev vs. the macOS Swift globe listener.
+//! - [`hotkey_listener`] — TinyVoice native listeners and the macOS Globe composition.
//! - [`pipeline`] — the background recording → transcription pass.
//! - [`runtime`] — the hotkey event loop that drives a `VoiceServer`.
//! - [`singleton`] — the process-global instance, auto-start, and the
//! standalone (CLI) entry point.
-mod hotkey_listener;
+pub(crate) mod hotkey_listener;
mod pipeline;
mod runtime;
mod singleton;
diff --git a/crates/openhuman-core/src/voice/server/hotkey_listener.rs b/crates/openhuman-core/src/voice/server/hotkey_listener.rs
index 4d325ed981..7a391661d0 100644
--- a/crates/openhuman-core/src/voice/server/hotkey_listener.rs
+++ b/crates/openhuman-core/src/voice/server/hotkey_listener.rs
@@ -1,5 +1,5 @@
-//! Hotkey listener dispatch: rdev everywhere except the macOS Fn/Globe key,
-//! which needs the Swift-based globe listener instead.
+//! Hotkey listener dispatch. TinyVoice owns native listeners; macOS Globe
+//! input remains a host-fed composition over TinyComputer facts.
#[cfg(any(target_os = "macos", test))]
use std::time::Duration;
@@ -14,8 +14,11 @@ use crate::voice::hotkey;
use super::LOG_PREFIX;
/// Opaque handle that keeps the hotkey listener alive. Drop to stop.
-pub(super) enum HotkeyListenerKind {
- Rdev(hotkey::HotkeyListenerHandle),
+pub(crate) enum HotkeyListenerKind {
+ Module {
+ cancel: CancellationToken,
+ task: tokio::task::JoinHandle<()>,
+ },
#[cfg(any(target_os = "macos", test))]
Globe {
cancel: CancellationToken,
@@ -24,9 +27,12 @@ pub(super) enum HotkeyListenerKind {
}
impl HotkeyListenerKind {
- pub(super) async fn stop(self) {
+ pub(crate) async fn stop(self) {
match self {
- HotkeyListenerKind::Rdev(handle) => handle.stop(),
+ HotkeyListenerKind::Module { cancel, task } => {
+ cancel.cancel();
+ let _ = task.await;
+ }
#[cfg(any(target_os = "macos", test))]
HotkeyListenerKind::Globe { cancel, task } => {
cancel.cancel();
@@ -45,7 +51,7 @@ impl HotkeyListenerKind {
/// `dispatch_assert_queue(main_queue)` inside that API and kills the process
/// with `EXC_BREAKPOINT` (`dispatch_assert_queue_fail`). Configure
/// `hotkey = "fn"` to avoid this. (#2677)
-pub(super) async fn start_hotkey_listener(
+pub(crate) async fn start_hotkey_listener(
config: &crate::config::Config,
hotkey_str: &str,
mode: hotkey::ActivationMode,
@@ -75,29 +81,225 @@ pub(super) async fn start_hotkey_listener(
))
}
- // Non-macOS: rdev-based listener for all keys.
+ // Non-macOS: TinyVoice owns its native listener and cleanup worker.
#[cfg(not(target_os = "macos"))]
{
- // `server_cancel` is only consumed by the macOS Swift-globe listener
- // branch above; the rdev listener manages its own lifecycle, so bind it
- // here to keep the shared signature warning-free on non-macOS.
- let _ = (config, server_cancel);
- let combo = hotkey::parse_hotkey(hotkey_str).map_err(|e| e.to_string())?;
- let (handle, mut source) =
- hotkey::start_listener(combo, mode).map_err(|e| e.to_string())?;
- let (tx, rx) = tokio::sync::mpsc::channel(65);
- tokio::spawn(async move {
- loop {
- let event = tokio::select! {
- _ = tx.closed() => break,
- event = source.recv() => match event { Some(event) => event, None => break },
- };
- if tx.send(event).await.is_err() {
+ start_module_hotkey_listener(config, hotkey_str, mode, server_cancel).await
+ }
+}
+
+#[cfg(not(target_os = "macos"))]
+async fn start_module_hotkey_listener(
+ config: &crate::config::Config,
+ hotkey_str: &str,
+ mode: hotkey::ActivationMode,
+ server_cancel: &CancellationToken,
+) -> Result<
+ (
+ HotkeyListenerKind,
+ tokio::sync::mpsc::Receiver<hotkey::HotkeyEvent>,
+ ),
+ String,
+> {
+ use crate::modules::voice;
+ use std::time::Duration;
+
+ let handle = voice::reserve_hotkey(
+ config,
+ hotkey::HotkeyRequest {
+ key: hotkey_str.to_string(),
+ mode,
+ source: hotkey::HotkeySource::Native,
+ },
+ )
+ .await
+ .map_err(|error| error.to_string())?
+ .map_err(|error| format!("hotkey reservation failed: {error:?}"))?;
+
+ let task_cancel = server_cancel.child_token();
+ let worker_cancel = task_cancel.clone();
+ let task_config = config.clone();
+ let (events_tx, events_rx) = tokio::sync::mpsc::channel(65);
+ let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
+ let worker_handle = handle.clone();
+ let task = tokio::spawn(async move {
+ let generation = loop {
+ if worker_cancel.is_cancelled() || events_tx.is_closed() {
+ break None;
+ }
+ match voice::start_hotkey(&task_config, worker_handle.clone()).await {
+ Ok(Ok(status)) if status.state == hotkey::HotkeyState::Running => {
+ break status.generation;
+ }
+ Ok(Ok(_)) => break None,
+ Ok(Err(error)) => {
+ let _ = ready_tx.send(Err(format!("hotkey startup failed: {error:?}")));
+ close_module_hotkey(&task_config, worker_handle).await;
+ return;
+ }
+ Err(error) => {
+ tokio::select! {
+ _ = worker_cancel.cancelled() => break None,
+ _ = tokio::time::sleep(Duration::from_millis(250)) => {}
+ }
+ log::debug!("{LOG_PREFIX} retrying uncertain hotkey start: {error}");
+ }
+ }
+ };
+ let Some(generation) = generation else {
+ let _ = ready_tx.send(Err("hotkey startup canceled".into()));
+ close_module_hotkey(&task_config, worker_handle).await;
+ return;
+ };
+ if ready_tx.send(Ok(())).is_err() {
+ close_module_hotkey(&task_config, worker_handle).await;
+ return;
+ }
+
+ let mut delivery = HotkeyDelivery::new(generation);
+ let mut interval = tokio::time::interval(Duration::from_millis(25));
+ interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
+ loop {
+ tokio::select! {
+ _ = worker_cancel.cancelled() => break,
+ _ = events_tx.closed() => break,
+ _ = interval.tick() => {}
+ }
+ // A batch is capped at 64 events. Reserve one slot for the
+ // inactive edge delivered when the module reports a reset.
+ if events_tx.capacity() != 65 {
+ continue;
+ }
+ let batch = match voice::read_hotkey(
+ &task_config,
+ hotkey::HotkeyReadRequest {
+ handle: worker_handle.clone(),
+ acknowledged_batch: delivery.acknowledged_batch,
+ },
+ )
+ .await
+ {
+ Ok(Ok(batch)) => batch,
+ Ok(Err(error)) => {
+ log::warn!("{LOG_PREFIX} module hotkey read failed: {error:?}");
+ break;
+ }
+ Err(error) => {
+ log::warn!("{LOG_PREFIX} module hotkey read unavailable: {error}");
+ continue;
+ }
+ };
+ let events = match delivery.accept(&batch) {
+ Ok(events) => events,
+ Err(()) => {
+ log::warn!("{LOG_PREFIX} invalid TinyVoice hotkey batch continuity");
+ break;
+ }
+ };
+ let mut delivered = true;
+ for event in events {
+ if events_tx.send(event).await.is_err() {
+ delivered = false;
break;
}
}
- });
- Ok((HotkeyListenerKind::Rdev(handle), rx))
+ if !delivered {
+ break;
+ }
+ }
+ close_module_hotkey(&task_config, worker_handle).await;
+ });
+
+ tokio::select! {
+ result = ready_rx => result.map_err(|_| "TinyVoice hotkey startup task ended".to_string())??,
+ _ = server_cancel.cancelled() => return Err("hotkey startup canceled".into()),
+ }
+ Ok((
+ HotkeyListenerKind::Module {
+ cancel: task_cancel,
+ task,
+ },
+ events_rx,
+ ))
+}
+
+#[cfg(not(target_os = "macos"))]
+async fn close_module_hotkey(config: &crate::config::Config, handle: hotkey::HotkeyHandle) {
+ loop {
+ match crate::modules::voice::stop_hotkey(config, handle.clone()).await {
+ Ok(Ok(status)) if status.state == hotkey::HotkeyState::Stopped => return,
+ Ok(Ok(status)) => {
+ log::warn!(
+ "{LOG_PREFIX} hotkey cleanup still active: {:?}",
+ status.state
+ )
+ }
+ Ok(Err(hotkey::HotkeyError::UnknownHandle)) => return,
+ Ok(Err(error)) => log::warn!("{LOG_PREFIX} hotkey cleanup pending: {error:?}"),
+ Err(error) => log::warn!("{LOG_PREFIX} hotkey cleanup unavailable: {error}"),
+ }
+ tokio::time::sleep(std::time::Duration::from_millis(250)).await;
+ }
+}
+
+/// Validate and translate one replayable module batch before acknowledging it.
+/// The queue stays bounded to one batch, so acknowledgment means every event
+/// has been admitted to the host's receiver.
+#[cfg(not(target_os = "macos"))]
+struct HotkeyDelivery {
+ generation: u64,
+ acknowledged_batch: Option<u64>,
+ active: bool,
+ last_sequence: Option<u64>,
+}
+
+#[cfg(not(target_os = "macos"))]
+impl HotkeyDelivery {
+ fn new(generation: u64) -> Self {
+ Self {
+ generation,
+ acknowledged_batch: None,
+ active: false,
+ last_sequence: None,
+ }
+ }
+
+ fn accept(&mut self, batch: &hotkey::HotkeyBatch) -> Result<Vec<hotkey::HotkeyEvent>, ()> {
+ if batch.generation != self.generation
+ || batch.events.len() > 64
+ || batch.batch != self.acknowledged_batch.unwrap_or(0).saturating_add(1)
+ {
+ return Err(());
+ }
+
+ let mut active = self.active;
+ let mut last_sequence = self.last_sequence;
+ let mut output = Vec::with_capacity(batch.events.len() + usize::from(batch.reset));
+ if batch.reset {
+ if active {
+ output.push(hotkey::HotkeyEvent::Released);
+ }
+ active = false;
+ last_sequence = None;
+ }
+ for event in &batch.events {
+ if event.generation != self.generation
+ || last_sequence.is_some_and(|last| event.sequence <= last)
+ {
+ return Err(());
+ }
+ active = event.event == hotkey::HotkeyEvent::Pressed;
+ last_sequence = Some(event.sequence);
+ output.push(event.event);
+ }
+ if active != batch.active {
+ return Err(());
+ }
+
+ self.acknowledged_batch = Some(batch.batch);
+ self.active = active;
+ self.last_sequence = last_sequence;
+ Ok(output)
}
}
diff --git a/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs b/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs
index 9935850e17..69fe9f7e6d 100644
--- a/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs
+++ b/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs
@@ -5,6 +5,81 @@ use hotkey::{
};
use tinycomputer_bus::accessibility::GlobeEvent::{Down, Up};
+#[cfg(not(target_os = "macos"))]
+use tinyvoice_bus::hotkey::{HotkeyBatch, SequencedHotkeyEvent};
+
+#[cfg(not(target_os = "macos"))]
+fn batch(
+ generation: u64,
+ batch: u64,
+ events: &[(u64, hotkey::HotkeyEvent)],
+ reset: bool,
+ active: bool,
+) -> HotkeyBatch {
+ HotkeyBatch {
+ generation,
+ batch,
+ events: events
+ .iter()
+ .map(|(sequence, event)| SequencedHotkeyEvent {
+ generation,
+ sequence: *sequence,
+ event: *event,
+ })
+ .collect(),
+ reset,
+ active,
+ }
+}
+
+#[cfg(not(target_os = "macos"))]
+#[test]
+fn native_hotkey_batches_ack_only_after_ordered_event_state_is_valid() {
+ let mut delivery = HotkeyDelivery::new(4);
+ assert_eq!(
+ delivery
+ .accept(&batch(4, 1, &[(1, Pressed)], false, true))
+ .unwrap(),
+ [Pressed]
+ );
+ assert_eq!(delivery.acknowledged_batch, Some(1));
+
+ let invalid = batch(4, 2, &[(2, Released)], false, true);
+ assert!(delivery.accept(&invalid).is_err());
+ assert_eq!(delivery.acknowledged_batch, Some(1));
+ assert!(delivery.active);
+
+ assert_eq!(
+ delivery
+ .accept(&batch(4, 2, &[(2, Released)], false, false))
+ .unwrap(),
+ [Released]
+ );
+ assert_eq!(delivery.acknowledged_batch, Some(2));
+}
+
+#[cfg(not(target_os = "macos"))]
+#[test]
+fn native_hotkey_reset_releases_active_state_and_accepts_fresh_sequence() {
+ let mut delivery = HotkeyDelivery::new(9);
+ delivery
+ .accept(&batch(9, 1, &[(4, Pressed)], false, true))
+ .unwrap();
+ assert_eq!(
+ delivery.accept(&batch(9, 2, &[], true, false)).unwrap(),
+ [Released]
+ );
+ assert_eq!(delivery.acknowledged_batch, Some(2));
+ assert_eq!(
+ delivery
+ .accept(&batch(9, 3, &[(8, Pressed)], false, true))
+ .unwrap(),
+ [Pressed]
+ );
+ assert_eq!(delivery.acknowledged_batch, Some(3));
+ assert!(delivery.active);
+}
+
#[test]
fn overflow_stops_activation_and_waits_for_physical_release() {
for mode in [Push, Tap] {
diff --git a/crates/openhuman-core/src/voice/server/runtime.rs b/crates/openhuman-core/src/voice/server/runtime.rs
index 92bd606426..bd0e9f4162 100644
--- a/crates/openhuman-core/src/voice/server/runtime.rs
+++ b/crates/openhuman-core/src/voice/server/runtime.rs
@@ -161,7 +161,7 @@ impl VoiceServer {
// Forward hotkey event to the dictation bus so Socket.IO
// clients receive dictation:toggle events even when the
- // dictation_listener is not running (single rdev listener).
+ // dictation_listener is not running (single TinyVoice listener).
{
use crate::voice::dictation_listener;
let event_type = match event {
diff --git a/crates/openhuman-core/src/voice/stub.rs b/crates/openhuman-core/src/voice/stub.rs
index 209b3547ba..5d03fe6261 100644
--- a/crates/openhuman-core/src/voice/stub.rs
+++ b/crates/openhuman-core/src/voice/stub.rs
@@ -171,7 +171,7 @@ pub mod dictation_listener {
pub async fn start_if_enabled(_config: &Config) {}
/// No-op: nothing to stop.
- pub fn stop() {}
+ pub async fn stop() {}
}
// ---------------------------------------------------------------------------
diff --git a/vendor/tinyvoice b/vendor/tinyvoice
index 4b2ab94873..5d545f5719 160000
--- a/vendor/tinyvoice
+++ b/vendor/tinyvoice
@@ -1 +1 @@
-Subproject commit 4b2ab948734f4a7312faf61c6d2edf3d0937ebbb
+Subproject commit 5d545f57195e4a6f0ba64b009d514eefd4c1b1d2