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.

fix(voice): resolve announcement language through the resolver, not event.language verbatim

Ruben Lütkeb8bbd124756c
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index bcb8efb6a6..269d8d544d 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -2435,7 +2435,15 @@ class SpeechPipeline:
# here as a safety net, but pass ack_mode=is_preamble so legitimate
# filler-opener phrases ("Lass mich kurz nachschauen.") are
# preserved on the second pass too.
- ann_lang = (event.language or "de").lower()
+ # Resolve the announcement's spoken language through the ONE
+ # authoritative resolver — the live brain.reply_language pin and the
+ # sticky conversation_language win over whatever an emitter stamped on
+ # the event, and an undetectable/None tag falls back to the resolved
+ # turn language, never a hardcoded German default (forensic 2026-06-23:
+ # a German voice chat spoke an English "ANNOUNCEMENT" because
+ # event.language was trusted verbatim). The event tag is only a hint,
+ # passed where the STT tag normally goes.
+ ann_lang = self._output_language(event.language, event.text or "")
scrubbed = scrub_for_voice(
event.text, language=ann_lang, ack_mode=is_preamble
)
@@ -2462,7 +2470,7 @@ class SpeechPipeline:
# surfaced in the transcript for debugging.
self._emit_spoken(
scrubbed.cleaned,
- event.language,
+ ann_lang,
_announcement_spoken_kind(getattr(event, "kind", None)),
getattr(event, "detail", None),
)
@@ -2479,11 +2487,12 @@ class SpeechPipeline:
if animate:
await self._transition("SPEAKING")
try:
- lang_code = None
- if event.language:
- lang_code = {"de": "de-DE", "en": "en-US", "es": "es-ES"}.get(
- event.language.lower()
- )
+ # Drive the TTS pin from the SAME resolved language as the scrub,
+ # not from event.language again — a None/auto tag here used to send
+ # language_code=None, which lets the multilingual TTS (Cartesia)
+ # fall back to its English voice on German text (the British-accent
+ # symptom; forensic 2026-06-23).
+ lang_code = {"de": "de-DE", "en": "en-US", "es": "es-ES"}.get(ann_lang)
try:
chunks = self._tts.synthesize(scrubbed.cleaned, language_code=lang_code)
except TypeError:
diff --git a/tests/unit/speech/test_announcement_bridge.py b/tests/unit/speech/test_announcement_bridge.py
index 118fa53b7e..e35fdfb255 100644
--- a/tests/unit/speech/test_announcement_bridge.py
+++ b/tests/unit/speech/test_announcement_bridge.py
@@ -323,18 +323,28 @@ async def test_announcement_regression_no_speak_api() -> None:
@pytest.mark.asyncio
-async def test_announcement_language_none_passes_none() -> None:
- """Wenn ``language=None`` im Event, wird auch kein language_code gesetzt."""
+async def test_announcement_language_none_resolves_via_conversation() -> None:
+ """A ``language=None`` event must NOT pass ``language_code=None`` to TTS.
+
+ Forensic 2026-06-23: a None/auto language_code lets the multilingual TTS
+ (Cartesia) fall back to its English voice on German text. The announcement
+ handler now resolves the language through ``_output_language``, so an
+ untagged announcement follows the established conversation language (here
+ German) instead of leaking ``None``.
+ """
+ from types import SimpleNamespace
+
bus = EventBus()
tts = FakeTTS()
player = FakePlayer()
- _make_pipeline(tts, bus, player)
+ pipe = _make_pipeline(tts, bus, player)
+ pipe._brain = SimpleNamespace(reply_language="auto", conversation_language="de")
await bus.publish(
AnnouncementRequested(text="test", language=None)
)
- assert tts.calls == [("test", None)]
+ assert tts.calls == [("test", "de-DE")]
@pytest.mark.asyncio
diff --git a/tests/unit/speech/test_announcement_language.py b/tests/unit/speech/test_announcement_language.py
new file mode 100644
index 0000000000..3118f26e0d
--- /dev/null
+++ b/tests/unit/speech/test_announcement_language.py
@@ -0,0 +1,83 @@
+"""``_on_announcement`` must resolve the announcement's spoken language through
+the ONE authoritative resolver (``_output_language``) instead of trusting
+``event.language`` verbatim.
+
+Forensic 2026-06-23 (screenshot): a German voice chat spoke an English
+"ANNOUNCEMENT" while the text answer was German. Root cause: the announcement
+handler read ``event.language`` literally (``(event.language or "de").lower()``)
+and never consulted the live ``brain.reply_language`` pin, the sticky
+``conversation_language`` or the announcement TEXT — so whatever (possibly
+stale/wrong) language an emitter stamped on the event drove the TTS voice.
+
+These tests pin the contract: the event tag is only a HINT (passed where the
+STT tag normally goes); the pin wins, then conversation stickiness for thin
+turns, then the detected language of the announcement text, then the tag.
+See CLAUDE.md "Runtime Output Language".
+"""
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+
+from jarvis.core.bus import EventBus
+from jarvis.core.events import AnnouncementRequested
+from tests.unit.speech.test_announcement_bridge import (
+ FakePlayer,
+ FakeTTS,
+ _make_pipeline,
+)
+
+
+def _last_language_code(tts: FakeTTS) -> str | None:
+ assert tts.calls, "expected the announcement to reach tts.synthesize"
+ return tts.calls[-1][1]
+
+
+async def test_announcement_uses_text_not_mistagged_event_language() -> None:
+ # The emitter stamped "en" but the text is clearly German. The resolver must
+ # speak German (text detection beats the stale event tag), not trust the tag.
+ bus = EventBus()
+ tts = FakeTTS()
+ pipe = _make_pipeline(tts, bus, FakePlayer())
+ pipe._brain = SimpleNamespace(reply_language="auto", conversation_language="de")
+
+ await bus.publish(
+ AnnouncementRequested(
+ text="Das Dokument ist fertig und liegt bereit.", language="en"
+ )
+ )
+
+ assert _last_language_code(tts) == "de-DE"
+
+
+async def test_announcement_honors_hard_pin_over_event_tag() -> None:
+ # A hard de pin must win over an English event tag AND English text.
+ bus = EventBus()
+ tts = FakeTTS()
+ pipe = _make_pipeline(tts, bus, FakePlayer())
+ pipe._brain = SimpleNamespace(reply_language="de", conversation_language="")
+
+ await bus.publish(
+ AnnouncementRequested(text="The file is ready now.", language="en")
+ )
+
+ assert _last_language_code(tts) == "de-DE"
+
+
+async def test_announcement_untagged_follows_text_not_german_default() -> None:
+ # No event language at all: today it silently defaults to German ("de-DE").
+ # It must instead mirror the announcement text (here: English).
+ bus = EventBus()
+ tts = FakeTTS()
+ pipe = _make_pipeline(tts, bus, FakePlayer())
+ pipe._brain = SimpleNamespace(reply_language="auto", conversation_language="")
+
+ await bus.publish(
+ AnnouncementRequested(text="The file is ready and waiting.", language=None)
+ )
+
+ assert _last_language_code(tts) == "en-US"