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.

feat(stt): apply user dictionary at the STT choke point + decoder bias

Ruben Lütke9008c41ac91a
diff --git a/jarvis/plugins/stt/__init__.py b/jarvis/plugins/stt/__init__.py
index b15906d031..1af4128440 100644
--- a/jarvis/plugins/stt/__init__.py
+++ b/jarvis/plugins/stt/__init__.py
@@ -87,6 +87,22 @@ def build_stt_from_config(stt_cfg: Any) -> Any:
language = getattr(stt_cfg, "language", "auto")
language = language if language and language != "auto" else None
bias_prompt = (getattr(stt_cfg, "bias_prompt", "") or "").strip()
+ # Merge the user's STT-dictionary words into the decoder bias for
+ # prompt-capable providers (capability-gated: providers that reject the
+ # kwarg keep working via the TypeError retry below, and every provider
+ # still gets the dictionary's post-STT corrections — AP-21/22). The local
+ # utterance fwhisper deliberately receives NO initial_prompt (silence-
+ # hallucination risk, see _build_local_fallback).
+ try:
+ from jarvis.speech.stt_dictionary import dictionary_bias_words
+
+ vocab = dictionary_bias_words()
+ except Exception as exc: # noqa: BLE001 — the dictionary must never break STT build
+ logger.debug("STT dictionary bias words unavailable: {}", exc)
+ vocab = []
+ if vocab:
+ joined = ", ".join(vocab)
+ bias_prompt = f"{bias_prompt}, {joined}" if bias_prompt else joined
cls = _load_provider_class(provider_name) if provider_name else None
if cls is not None and provider_name != "faster-whisper":
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 4c407f4230..e41eca008e 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -1047,6 +1047,19 @@ class SpeechPipeline:
# utterance STT may still exist (cloud provider). Keep that path alive
# so the Listening bubble does not stay stuck on "...".
self._probe_stt: Any = self._stt or self._utterance_stt
+ # User STT dictionary (a dictation app-style custom vocabulary): wrap the
+ # utterance + preview handles so EVERY provider's transcript gets the
+ # user's corrections — brain turns, chat dictation, and the live
+ # preview alike (pure string ops, hot-path safe). The wake path
+ # (``self._stt``, wake whisper, echo confirm) stays UNWRAPPED: wake
+ # matching must never see rewritten transcripts (AP-27 territory).
+ try:
+ from jarvis.speech.stt_dictionary import wrap_stt_with_dictionary
+
+ self._utterance_stt = wrap_stt_with_dictionary(self._utterance_stt)
+ self._probe_stt = wrap_stt_with_dictionary(self._probe_stt)
+ except Exception as exc: # noqa: BLE001 — corrections must never break voice boot
+ log.warning("STT dictionary wrapper unavailable: %s", exc)
self._tts = tts or GeminiFlashTTS()
self._openwakeword_enabled = enable_openwakeword
# Custom-wake-word plan (jarvis.speech.wake_phrase.WakeWordPlan) or None.
@@ -1661,7 +1674,14 @@ class SpeechPipeline:
stt_cfg, language=lang, wake_phrase=getattr(plan, "phrase", None)
)
if self._probe_stt is None:
- self._probe_stt = self._stt
+ try:
+ from jarvis.speech.stt_dictionary import (
+ wrap_stt_with_dictionary,
+ )
+
+ self._probe_stt = wrap_stt_with_dictionary(self._stt)
+ except Exception: # noqa: BLE001 — preview must survive without it
+ self._probe_stt = self._stt
log.info("Wake-Live-Switch: built local Whisper for custom phrase.")
except Exception as exc: # noqa: BLE001 — degrade, never crash the switch
log.warning("Wake-Live-Switch: local Whisper build failed: %s", exc)
@@ -5394,8 +5414,10 @@ class SpeechPipeline:
uuid4(),
enabled=getattr(lat_cfg, "enabled", True),
)
- utt_stt_name = type(self._utterance_stt).__name__
- log.info("→ Transkribiere (%.1f KB) via %s …", len(pcm) / 1024, utt_stt_name)
+ utt_stt_name = getattr(
+ self._utterance_stt, "provider_label", type(self._utterance_stt).__name__
+ )
+ log.info("→ Transcribing (%.1f KB) via %s …", len(pcm) / 1024, utt_stt_name)
await self._set_turn_state(TurnTakingState.WAITING_FOR_FINAL_TRANSCRIPT)
transcript = await self._transcribe_final(pcm)
if transcript is None:
diff --git a/tests/unit/speech/test_pipeline_lightweight_wake.py b/tests/unit/speech/test_pipeline_lightweight_wake.py
index e9ccfe13a7..f946668b89 100644
--- a/tests/unit/speech/test_pipeline_lightweight_wake.py
+++ b/tests/unit/speech/test_pipeline_lightweight_wake.py
@@ -49,7 +49,10 @@ def test_lightweight_mode_instantiates_no_faster_whisper() -> None:
)
assert pipe._stt is None
assert pipe._whisper_wake is None
- assert type(pipe._utterance_stt).__name__ == "GroqWhisperAPI"
+ # The utterance STT is wrapped by the user-dictionary corrector; the
+ # resolved provider underneath must still be the configured Groq cloud STT.
+ assert type(pipe._utterance_stt).__name__ == "DictionaryCorrectingSTT"
+ assert pipe._utterance_stt.provider_label == "GroqWhisperAPI"
def test_heavy_mode_keeps_faster_whisper_by_default() -> None: