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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
perf: skip duplicate wake transcriptions
Ruben Lütkeb38b88571949
diff --git a/jarvis/speech/rolling_whisper_wake.py b/jarvis/speech/rolling_whisper_wake.pyindex d849f07b4b..6a46af0181 100644--- a/jarvis/speech/rolling_whisper_wake.py+++ b/jarvis/speech/rolling_whisper_wake.py@@ -522,6 +522,11 @@ class RollingWhisperWake:# list so the consumer closure mutates it in place without ``nonlocal``.buffer: deque[np.ndarray] = deque()buf_len = [0]+ # Monotonic audio revision shared with the poll task. A stalled source+ # leaves the rolling window unchanged; re-transcribing that identical+ # PCM every poll only burns inference/API capacity and can delay the+ # authoritative utterance request that follows a real wake.+ buffer_revision = [0]stopped = asyncio.Event()async def _consume() -> None:@@ -531,6 +536,7 @@ class RollingWhisperWake:samples = pcm_bytes_to_np(chunk.pcm)buffer.append(samples)buf_len[0] += len(samples)+ buffer_revision[0] += 1# Update heartbeat statistics (live RMS per chunk)self._chunks_seen += 1@@ -604,6 +610,7 @@ class RollingWhisperWake:warm_wait_t0 = time.time()warm_wait_logged = Falsefallback_warmed = False+ last_polled_revision = -1# Set when recover() dropped the model MID-SESSION: the warm gate then# re-warms immediately (this loop owns it — the boot deferred loader# only runs once) instead of lazily rebuilding INSIDE the next poll's@@ -752,6 +759,12 @@ class RollingWhisperWake:if now - last_trigger_t < self._cooldown_s:self._stat_suppressed_cooldown += 1continue+ # No audio arrived since the previous evaluation. Reusing the+ # exact same window cannot reveal a wake that was not there on+ # the last pass, so avoid a redundant STT request.+ revision = buffer_revision[0]+ if revision == last_polled_revision:+ continue# Not enough audio in the buffer yetif buf_len[0] < self._sample_rate: # mind. 1 Sekcontinue@@ -764,6 +777,7 @@ class RollingWhisperWake:audio_np = np.concatenate(list(buffer))if len(audio_np) < self._sample_rate:continue+ last_polled_revision = revision# A full window reached the audio gates — this is one wake# evaluation attempt (the denominator for the gate counters).self._stat_windows_polled += 1diff --git a/tests/unit/speech/test_rolling_whisper_wake_request_budget.py b/tests/unit/speech/test_rolling_whisper_wake_request_budget.pynew file mode 100644index 0000000000..3748dc0ab1--- /dev/null+++ b/tests/unit/speech/test_rolling_whisper_wake_request_budget.py@@ -0,0 +1,71 @@+"""Rolling wake only transcribes a window after new audio arrives."""+from __future__ import annotations++import asyncio++import numpy as np++from jarvis.core.protocols import AudioChunk, Transcript+from jarvis.speech.rolling_whisper_wake import RollingWhisperWake+++class _CountingSTT:+ def __init__(self) -> None:+ self.calls = 0+ self.called = asyncio.Event()++ async def transcribe_pcm(+ self,+ pcm: bytes,+ sample_rate: int = 16_000,+ language: str | None = None,+ ) -> Transcript:+ self.calls += 1+ self.called.set()+ return Transcript(text="not a wake", language="en", confidence=1.0)+++class _NeverMatch:+ def search(self, text: str): # noqa: ANN001+ return None+++async def test_stalled_audio_source_does_not_repeat_identical_stt_request() -> None:+ stt = _CountingSTT()+ wake = RollingWhisperWake(+ stt,+ pattern=_NeverMatch(),+ poll_interval_s=0.01,+ cooldown_s=0.0,+ min_rms=0.0,+ min_peak=0.0,+ save_debug_wavs=False,+ )+ release = asyncio.Event()++ async def source():+ samples = np.full(16_000, 12_000, dtype=np.int16)+ yield AudioChunk(+ pcm=samples.tobytes(),+ sample_rate=16_000,+ timestamp_ns=0,+ channels=1,+ )+ await release.wait()++ async def consume() -> None:+ async for _ in wake.detect(source()):+ pass++ task = asyncio.create_task(consume())+ try:+ await asyncio.wait_for(stt.called.wait(), timeout=1.0)+ await asyncio.sleep(0.08)+ assert stt.calls == 1+ finally:+ release.set()+ task.cancel()+ try:+ await task+ except asyncio.CancelledError:+ pass