Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

perf(wake): GPU-turbo custom-phrase wake — instant + reliable, capability-gated

Ruben Lütkeb4197a988bd1
diff --git a/jarvis/plugins/stt/__init__.py b/jarvis/plugins/stt/__init__.py
index f16162f06a..737a26162e 100644
--- a/jarvis/plugins/stt/__init__.py
+++ b/jarvis/plugins/stt/__init__.py
@@ -7,6 +7,7 @@ detector path keeps working when no cloud provider is registered.
"""
from __future__ import annotations
+from functools import lru_cache
from importlib import metadata as importlib_metadata
from typing import Any
@@ -121,8 +122,30 @@ def build_stt_from_config(stt_cfg: Any) -> Any:
)
+@lru_cache(maxsize=1)
+def _wake_cuda_available() -> bool:
+ """True iff a CUDA device is usable by the CTranslate2 / faster-whisper backend.
+
+ Cached — the device count is stable for the process lifetime. Any import or
+ probe error is treated as "no CUDA", so a host without the GPU stack degrades
+ to the cloud-first CPU default instead of raising. This is the capability
+ probe behind the wake-Whisper GPU auto-upgrade (AP-21: gate on a capability,
+ never on a provider/hardware name).
+ """
+ try:
+ import ctranslate2
+
+ return ctranslate2.get_cuda_device_count() > 0
+ except Exception: # noqa: BLE001 - any failure means "treat as no GPU"
+ return False
+
+
def build_wake_whisper(
- stt_cfg: Any, *, language: str | None = None, wake_phrase: str | None = None
+ stt_cfg: Any,
+ *,
+ language: str | None = None,
+ wake_phrase: str | None = None,
+ cuda_available: bool | None = None,
) -> Any:
"""Build the LOCAL wake-match / live-preview Whisper.
@@ -164,11 +187,36 @@ def build_wake_whisper(
"""
from jarvis.plugins.stt.fwhisper import FasterWhisperProvider
+ model = getattr(stt_cfg, "wake_model", "base")
+ device = getattr(stt_cfg, "wake_device", "cpu")
+ compute = getattr(stt_cfg, "wake_compute_type", "int8")
+
+ # Capability-gated GPU upgrade (forensic 2026-06-24). On the cloud-first CPU
+ # defaults (base/cpu) AND a usable CUDA device, transcribe the wake on the GPU
+ # with a fast MULTILINGUAL turbo model. Measured on the user's REAL "Hey Ruben"
+ # clips: ~150 ms/window vs ~750 ms-1.4 s on base/cpu, AND it hears the German
+ # proper noun reliably where base/cpu mis-hears it as "Ruhm"/"Tavis"/"Thomas"
+ # (the strict matcher then never fires -> "the wake word doesn't work"). Only
+ # the stt_match custom-phrase path on a GPU box is affected; the bundled
+ # "Hey Jarvis"/openWakeWord path and every CPU/VPS host keep base/cpu. An
+ # explicit wake_model/wake_device wins — only the untouched base/cpu pair
+ # auto-upgrades. large-v3-turbo is MULTILINGUAL (NOT distil-large-v3, which is
+ # English-only and would hallucinate German into "Thank you").
+ if cuda_available is None:
+ cuda_available = _wake_cuda_available()
+ if model == "base" and device == "cpu" and cuda_available:
+ model, device, compute = "large-v3-turbo", "cuda", "int8_float16"
+ logger.info(
+ "Wake-Whisper: CUDA device present -> GPU turbo "
+ "(large-v3-turbo/cuda/int8_float16) for a fast multilingual "
+ "custom-phrase wake (set wake_model explicitly to override)."
+ )
+
bias = wake_phrase.strip() if wake_phrase and wake_phrase.strip() else None
return FasterWhisperProvider(
- model=getattr(stt_cfg, "wake_model", "base"),
- device=getattr(stt_cfg, "wake_device", "cpu"),
- compute_type=getattr(stt_cfg, "wake_compute_type", "int8"),
+ model=model,
+ device=device,
+ compute_type=compute,
language=language,
initial_prompt=bias,
)
diff --git a/jarvis/speech/rolling_whisper_wake.py b/jarvis/speech/rolling_whisper_wake.py
index 1bc82dca07..76b9a1efdc 100644
--- a/jarvis/speech/rolling_whisper_wake.py
+++ b/jarvis/speech/rolling_whisper_wake.py
@@ -106,7 +106,14 @@ class RollingWhisperWake:
# ``.search(text)`` returning an object with ``.group(0)``.
pattern: Any = DEFAULT_PATTERN,
window_s: float = 1.8, # kürzer = weniger Stille-Anteil = höhere avg-RMS
- poll_interval_s: float = 0.3, # schnellere Wake-Reaktion
+ # 2026-06-24: the wake-reaction latency is dominated by the ~1.4s CPU
+ # base-Whisper transcription itself (measured: beam_size has no effect —
+ # the cost is the encoder pass over the ``window_s`` audio, not the
+ # decoder). The poll interval is the only *artificial* idle gap on the
+ # serialized ``sleep -> transcribe`` cadence, so keep it small. 0.3 -> 0.15
+ # trims ~150ms off every cycle for free; it does not add load on a slow
+ # box (there the transcription, not the sleep, paces the loop).
+ poll_interval_s: float = 0.15, # schnellere Wake-Reaktion (transcribe-bound)
cooldown_s: float = 5.0, # längerer Cooldown → weniger Over-Triggering
sample_rate: int = 16_000,
# 2026-04-22 (3. Iteration): RMS/Peak-Gates zurueck auf niedrig. Die
@@ -132,13 +139,15 @@ class RollingWhisperWake:
# chunks: live, cleanly-heard custom-name wakes land at ~0.28-0.52 (real
# samples 2026-06-23: "Ruben." 0.318, "Hey Ruhm" 0.365, "Hey Ruben" 0.52).
# A 0.45 floor rejected EVERY genuine wake (142 rejects / 0 accepts in one
- # evening). That floor was built to suppress *prompt-bias* hallucinations,
- # but the bias is now disabled (build_wake_whisper passes initial_prompt
- # =None), so the pattern itself is the hallucination guard — a random
- # mis-hear does not match the specific wake phrase — and the
- # ``max_no_speech_prob`` gate below still rejects silence/noise. Keep only
- # a low sanity floor that still drops a near-zero-confidence transcript
- # (regression: a 0.2-confidence match must stay rejected).
+ # evening). That floor was built to suppress *prompt-bias* hallucinations.
+ # The bias is ON again (2026-06-23: build_wake_whisper seeds the wake
+ # phrase as ``initial_prompt`` — without it the base/cpu model heard "Hey
+ # Ruben" as "Space"/"Ego" -> 2-13% recall, with it 83%). The hallucination
+ # guard is therefore NOT the confidence floor but the strict pattern (a
+ # random mis-hear does not match the specific adjacent "hey ruben") plus
+ # the ``max_no_speech_prob``/RMS/peak gates. Keep only a low sanity floor
+ # that still drops a near-zero-confidence transcript (regression: a
+ # 0.2-confidence match must stay rejected).
min_wake_confidence: float = 0.28,
max_no_speech_prob: float = 0.6,
) -> None:
@@ -166,6 +175,13 @@ class RollingWhisperWake:
self._max_rms = 0.0
self._last_transcript = ""
self._last_heartbeat_t = time.time()
+ # Windows dropped pre-Whisper by the rms/peak gate since the last
+ # heartbeat. Surfaced in the heartbeat so a "wake never fires" report is
+ # diagnosable: a high gated-out count means the mic is too quiet (the gate
+ # eats real wakes), as opposed to a low count with many "rejected
+ # unreliable" lines, which points at the model/confidence (forensic
+ # 2026-06-24 — these quiet drops were previously a silent ``continue``).
+ self._gated_out = 0
async def detect(
self, chunks: AsyncIterator[AudioChunk]
@@ -212,16 +228,18 @@ class RollingWhisperWake:
dbfs = 20.0 * np.log10(max(self._max_rms, 1e-12))
log.info(
"💓 wake-heartbeat: chunks=%d bytes=%dKB "
- "max-rms=%.4f (%.1f dBFS) last-transcript=%r",
+ "max-rms=%.4f (%.1f dBFS) gated-out=%d last-transcript=%r",
self._chunks_seen,
self._total_bytes // 1024,
self._max_rms,
dbfs,
+ self._gated_out,
self._last_transcript[:80],
)
self._chunks_seen = 0
self._total_bytes = 0
self._max_rms = 0.0
+ self._gated_out = 0
self._last_heartbeat_t = now_hb
# Ältere Samples rauswerfen wenn Buffer zu lang
@@ -265,12 +283,14 @@ class RollingWhisperWake:
# Lautstärke-Check (RMS) — kein Whisper-Call bei Stille
rms = float(np.sqrt(np.mean(audio_np * audio_np) + 1e-12))
if rms < self._min_rms:
+ self._gated_out += 1 # observability (surfaced in heartbeat)
continue
# Peak-Gate: bei reinem Rauschen gar nicht erst Whisper bemühen
peak = float(np.max(np.abs(audio_np)))
if peak < self._min_peak:
# Kein Whisper-Call — zu leise für Sprache
+ self._gated_out += 1 # observability (surfaced in heartbeat)
continue
# Whisper-Call mit Peak-Normalization (dynamischer Gain)
diff --git a/tests/unit/plugins/stt/test_wake_whisper_build.py b/tests/unit/plugins/stt/test_wake_whisper_build.py
index 0ccc31cddd..1fa6655447 100644
--- a/tests/unit/plugins/stt/test_wake_whisper_build.py
+++ b/tests/unit/plugins/stt/test_wake_whisper_build.py
@@ -32,7 +32,9 @@ def test_build_wake_whisper_uses_wake_fields_not_utterance_model() -> None:
wake_device="cpu",
wake_compute_type="int8",
)
- p = build_wake_whisper(cfg)
+ # cuda_available=False isolates this from the GPU auto-upgrade below — here we
+ # only assert the wake instance does not inherit the heavy *utterance* fields.
+ p = build_wake_whisper(cfg, cuda_available=False)
assert isinstance(p, FasterWhisperProvider)
# The wake instance must NOT inherit the heavy utterance model / cuda.
@@ -41,8 +43,37 @@ def test_build_wake_whisper_uses_wake_fields_not_utterance_model() -> None:
assert p._compute_type == "int8"
+def test_build_wake_whisper_upgrades_to_gpu_turbo_when_cuda_available() -> None:
+ # Capability-gated speed+reliability upgrade (forensic 2026-06-24): on the
+ # cloud-first CPU defaults (base/cpu) AND a CUDA device, the custom-phrase wake
+ # transcribes on the GPU with a fast MULTILINGUAL turbo model. Measured on the
+ # user's real "Hey Ruben" clips: ~150ms/window (vs ~750ms-1.4s on base/cpu) AND
+ # it hears the German proper noun where base/cpu mis-hears it ("Ruhm"/"Tavis").
+ p = build_wake_whisper(STTConfig(), cuda_available=True)
+ assert p._model_name == "large-v3-turbo"
+ assert p._device == "cuda"
+ assert p._compute_type == "int8_float16"
+
+
+def test_build_wake_whisper_stays_cpu_base_without_cuda() -> None:
+ # No GPU (VPS / fresh slim box): the cloud-first floor is untouched.
+ p = build_wake_whisper(STTConfig(), cuda_available=False)
+ assert p._model_name == "base"
+ assert p._device == "cpu"
+ assert p._compute_type == "int8"
+
+
+def test_build_wake_whisper_respects_explicit_non_default_over_gpu_auto() -> None:
+ # An explicit wake_model wins over the auto-upgrade even on a CUDA box — the
+ # upgrade only fires for the untouched base/cpu defaults.
+ cfg = STTConfig(wake_model="small", wake_device="cpu", wake_compute_type="int8")
+ p = build_wake_whisper(cfg, cuda_available=True)
+ assert p._model_name == "small"
+ assert p._device == "cpu"
+
+
def test_build_wake_whisper_passes_language() -> None:
- p = build_wake_whisper(STTConfig(), language="de")
+ p = build_wake_whisper(STTConfig(), language="de", cuda_available=False)
assert p._language == "de"
@@ -51,7 +82,7 @@ def test_build_wake_whisper_tolerates_missing_wake_fields() -> None:
class _Bare:
pass
- p = build_wake_whisper(_Bare())
+ p = build_wake_whisper(_Bare(), cuda_available=False)
assert p._model_name == "base"
assert p._device == "cpu"
assert p._compute_type == "int8"
@@ -68,13 +99,17 @@ def test_build_wake_whisper_biases_prompt_with_custom_phrase() -> None:
# no_speech_prob/RMS gates: false-wake stayed ~0% on real speech. So the bias
# is re-enabled on this path. It is scoped to the custom phrase only -- the
# OWW/"Hey Jarvis" paths pass no phrase and stay unbiased (test below).
- p = build_wake_whisper(STTConfig(), language="de", wake_phrase="Hey Ruben")
+ p = build_wake_whisper(
+ STTConfig(), language="de", wake_phrase="Hey Ruben", cuda_available=False
+ )
assert p._initial_prompt == "Hey Ruben"
def test_build_wake_whisper_default_has_no_prompt_bias() -> None:
- p = build_wake_whisper(STTConfig(), language="de")
+ p = build_wake_whisper(STTConfig(), language="de", cuda_available=False)
assert p._initial_prompt is None
- p_blank = build_wake_whisper(STTConfig(), language="de", wake_phrase=" ")
+ p_blank = build_wake_whisper(
+ STTConfig(), language="de", wake_phrase=" ", cuda_available=False
+ )
assert p_blank._initial_prompt is None
diff --git a/tests/unit/speech/test_rolling_whisper_wake.py b/tests/unit/speech/test_rolling_whisper_wake.py
index c15ce70d2e..29c3ed93f2 100644
--- a/tests/unit/speech/test_rolling_whisper_wake.py
+++ b/tests/unit/speech/test_rolling_whisper_wake.py
@@ -330,6 +330,85 @@ async def test_detect_rejects_matching_high_no_speech_transcript() -> None:
pass
+def test_default_poll_interval_is_responsive() -> None:
+ """The poll cadence sets the idle gap before a fresh window is transcribed.
+
+ Forensic 2026-06-24: the wake-reaction latency is dominated by the ~1.4s CPU
+ base-Whisper transcription itself (beam_size has no measurable effect — the
+ cost is the encoder pass over the window, not the decoder). The poll interval
+ is the only *artificial* idle gap on the cadence, so keep it small. This locks
+ in the faster default and guards against a regression back to the sluggish
+ 0.3-0.5s cadence.
+ """
+ wake = RollingWhisperWake(_PhraseSTT("hi"), save_debug_wavs=False)
+ assert wake._poll_interval_s <= 0.15
+
+
+async def test_gated_out_windows_are_counted_for_observability() -> None:
+ """A too-quiet window is dropped *before* Whisper — and must be observable.
+
+ Forensic 2026-06-24: the rms/peak gate skips the transcription with a bare
+ ``continue`` and no log, so a user whose mic is too quiet sees "it never
+ fires" with zero evidence in the log (both deep-dive passes flagged this as
+ the blind spot). The drop must bump a counter the heartbeat can surface, so a
+ future "doesn't fire" turn is diagnosable (high gated-out = mic too quiet vs.
+ low gated-out + high rejects = model/confidence).
+ """
+ stt = _PhraseSTT("should not be called")
+ wake = RollingWhisperWake(
+ stt,
+ pattern=_NeverMatch(),
+ poll_interval_s=0.01,
+ cooldown_s=0.0,
+ save_debug_wavs=False,
+ # Floors well above the (near-silent) quiet chunks below, so every poll
+ # is gated out pre-Whisper.
+ min_rms=0.5,
+ min_peak=0.5,
+ )
+
+ src: asyncio.Queue = asyncio.Queue()
+ stop_feed = asyncio.Event()
+
+ async def _quiet_feeder() -> None:
+ # ~ -60 dBFS noise: passes the >=1s buffer fill, fails the rms/peak gate.
+ i = 0
+ while not stop_feed.is_set():
+ arr = np.full(1600, 30, dtype=np.int16) # tiny amplitude
+ await src.put(
+ AudioChunk(pcm=arr.tobytes(), sample_rate=16000, timestamp_ns=i)
+ )
+ i += 1
+ await asyncio.sleep(0.002)
+
+ async def _iter():
+ while True:
+ chunk = await src.get()
+ if chunk is None:
+ return
+ yield chunk
+
+ async def _drive() -> None:
+ async for _kw in wake.detect(_iter()):
+ pass
+
+ feeder = asyncio.create_task(_quiet_feeder())
+ detect_task = asyncio.create_task(_drive())
+ try:
+ await asyncio.sleep(0.4)
+ assert wake._gated_out >= 1, "quiet windows were not counted as gated-out"
+ finally:
+ stop_feed.set()
+ await src.put(None)
+ feeder.cancel()
+ detect_task.cancel()
+ for t in (feeder, detect_task):
+ try:
+ await t
+ except (asyncio.CancelledError, Exception): # noqa: BLE001, S110
+ pass
+
+
async def test_consumer_keeps_draining_while_transcription_is_in_flight() -> None:
stt = _GatedSTT()
wake = RollingWhisperWake(