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
fix(tts): one BCP-47 map (incl. es) + Cartesia stops defaulting to the English voice
Ruben Lütkedaa034296afd
diff --git a/jarvis/plugins/tts/cartesia_tts.py b/jarvis/plugins/tts/cartesia_tts.pyindex a3693b427c..28831f8dbc 100644--- a/jarvis/plugins/tts/cartesia_tts.py+++ b/jarvis/plugins/tts/cartesia_tts.py@@ -16,6 +16,7 @@ from typing import Anyfrom jarvis.core import config as cfgfrom jarvis.core.protocols import AudioChunk+from jarvis.core.turn_language import DEFAULT_LOCALEfrom jarvis.plugins.tts.gemini_flash_tts import (SAPI5_SAMPLE_RATE,_sapi5_synthesize,@@ -103,6 +104,12 @@ class CartesiaTTS:"es": voice_id_es or DEFAULT_VOICE_ID_ES,}self._language = language+ # Voice used when neither a per-call language_code nor the text sniff+ # resolves a language. A configured concrete language pins it; else the+ # doctrine default locale — NEVER a hardcoded English voice on German+ # text (the British-accent symptom; forensic 2026-06-23).+ _loc = (language or "").lower().split("-", 1)[0]+ self._default_locale = _loc if _loc in self._voice_by_lang else DEFAULT_LOCALEself._chunk_by_sentence = chunk_by_sentenceself._speed = speedself._allow_sapi5_fallback = allow_sapi5_fallback@@ -135,8 +142,10 @@ class CartesiaTTS:detected = _detect_lang_from_text(text)if detected and detected in self._voice_by_lang:return self._voice_by_lang[detected]- # Default English voice keeps the previous single-voice behaviour.- return self._voice_by_lang.get("en", self._voice_id)+ # No language could be resolved — follow the configured default_locale,+ # never a hardcoded English voice on German text (British-accent+ # symptom). default_locale is "en" only when configured/auto.+ return self._voice_by_lang.get(self._default_locale, self._voice_id)def _resolve_api_key(self) -> str:val = cfg.get_secret("cartesia_api_key", env_fallback="CARTESIA_API_KEY")diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.pyindex 269d8d544d..fe848637dd 100644--- a/jarvis/speech/pipeline.py+++ b/jarvis/speech/pipeline.py@@ -2492,7 +2492,7 @@ class SpeechPipeline:# 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)+ lang_code = self._bcp47(ann_lang)try:chunks = self._tts.synthesize(scrubbed.cleaned, language_code=lang_code)except TypeError:@@ -3358,14 +3358,11 @@ class SpeechPipeline:async def _play_ready_cue(self) -> None:"""Play the ascending boot-ready tone once. Silent no-op on a headless- VPS / when no output device exists — never raises."""- try:- await self._player.play_pcm(READY_PCM, sample_rate=CHIME_SAMPLE_RATE)- except Exception as exc: # noqa: BLE001- log.debug("Boot-Ready-Sound übersprungen (%s).", exc)+ VPS / when no output device exists, or when the global "Sound effects"+ switch is off — never raises."""+ await self._play_earcon(READY_PCM)async def _prerender_task_acks(self) -> None:- lang_map = {"de": "de-DE", "en": "en-US"}phrases = iter_all_start_ack()log.info("Pre-rendere %d Task-Ack-Phrasen …", len(phrases))@@ -3382,7 +3379,7 @@ class SpeechPipeline:try:chunks: list[AudioChunk] = []try:- it = self._tts.synthesize(phrase, language_code=lang_map.get(lang))+ it = self._tts.synthesize(phrase, language_code=self._bcp47(lang))except TypeError:it = self._tts.synthesize(phrase)async for c in it:@@ -5902,7 +5899,7 @@ class SpeechPipeline:lang_code: str | None = Noneif lang:- lang_code = {"de": "de-DE", "en": "en-US", "es": "es-ES"}.get(lang.lower())+ lang_code = self._bcp47(lang)# Bounded look-ahead: at most ``lookahead`` synthesized-but-not-yet-# consumed sentences in flight. maxsize on the channel-of-channels@@ -6871,6 +6868,19 @@ class SpeechPipeline:except Exception: # noqa: BLE001 — telemetry must never break the turnlog.debug("SpeechSpoken emit failed", exc_info=True)+ _BCP47: dict[str, str] = {"de": "de-DE", "en": "en-US", "es": "es-ES"}++ @classmethod+ def _bcp47(cls, lang: object) -> str | None:+ """Map a de/en/es turn-language code to a TTS BCP-47 locale, else None.++ Single source for the whole pipeline — replaces four hand-copied maps,+ one of which (the task-ack prerender) had silently dropped ``es``, so a+ Spanish turn there got no language pin and the multilingual TTS could+ code-switch.+ """+ return cls._BCP47.get(str(lang or "").lower())+def _output_language(self, stt_language: object, text: str) -> str:"""Resolve THIS turn's output language for EVERY spoken/written layer.@@ -6933,10 +6943,7 @@ class SpeechPipeline:# Track that the assistant has spoken at least once in this session.# Used by _emit_completeness_signal to pick earcon vs. spoken cue.self._session_has_assistant_spoken = True- lang_code: str | None = None- if language:- mapping = {"de": "de-DE", "en": "en-US", "es": "es-ES"}- lang_code = mapping.get(language.lower())+ lang_code = self._bcp47(language)try:chunks = self._tts.synthesize(text, language_code=lang_code)except TypeError:diff --git a/tests/unit/plugins/tts/test_cartesia_default_locale.py b/tests/unit/plugins/tts/test_cartesia_default_locale.pynew file mode 100644index 0000000000..b9cfd05161--- /dev/null+++ b/tests/unit/plugins/tts/test_cartesia_default_locale.py@@ -0,0 +1,55 @@+"""Cartesia must never silently fall back to its English voice on un-sniffable+text — that is the British-accent-on-German symptom (forensic 2026-06-23).++When neither a per-call ``language_code`` pin nor the cheap text-detection+heuristic resolves a language, the voice fallback follows the configured+``default_locale`` (derived from ``[tts.cartesia].language``), not a hardcoded+English voice. The real defense is the pipeline always passing a concrete+``language_code``; this is the safety net for the rare unpinned path.+"""+from __future__ import annotations++from unittest.mock import patch++import pytest++from jarvis.plugins.tts.cartesia_tts import CartesiaTTS+++def patched_secret():+ with patch(+ "jarvis.plugins.tts.cartesia_tts.cfg.get_secret", return_value="sk-test"+ ):+ yield+++def _tts(language: str) -> CartesiaTTS:+ return CartesiaTTS(+ voice_id="GENERIC",+ voice_id_de="DE-VOICE-UUID",+ voice_id_en="EN-VOICE-UUID",+ voice_id_es="ES-VOICE-UUID",+ language=language,+ )+++def test_unsniffable_text_falls_back_to_default_locale_de(patched_secret) -> None:+ # language="de" configured; no pin, un-sniffable text → DE voice, NOT English.+ tts = _tts(language="de")+ voice = tts._resolve_voice("…", voice_override=None, language_code=None)+ assert voice == "DE-VOICE-UUID"+++def test_unsniffable_text_auto_defaults_to_doctrine_locale(patched_secret) -> None:+ # language="auto" → fall back to the doctrine DEFAULT_LOCALE ("en").+ tts = _tts(language="auto")+ voice = tts._resolve_voice("…", voice_override=None, language_code=None)+ assert voice == "EN-VOICE-UUID"+++def test_concrete_pin_still_wins_over_default_locale(patched_secret) -> None:+ # A concrete de-DE pin must pick the DE voice regardless of default_locale.+ tts = _tts(language="en")+ voice = tts._resolve_voice("anything", voice_override=None, language_code="de-DE")+ assert voice == "DE-VOICE-UUID"diff --git a/tests/unit/speech/test_bcp47_map.py b/tests/unit/speech/test_bcp47_map.pynew file mode 100644index 0000000000..ee08f1b7c5--- /dev/null+++ b/tests/unit/speech/test_bcp47_map.py@@ -0,0 +1,26 @@+"""One BCP-47 map for the whole speech pipeline.++The de/en/es → BCP-47 mapping was hand-copied at four call sites, one of which+(the task-ack prerender) silently dropped ``es`` — so a Spanish turn there got+no language pin and the multilingual TTS could code-switch. ``_bcp47`` is the+single source; every site routes through it.+"""+from __future__ import annotations++from jarvis.speech.pipeline import SpeechPipeline+++def test_bcp47_covers_all_three_locales() -> None:+ assert SpeechPipeline._bcp47("de") == "de-DE"+ assert SpeechPipeline._bcp47("en") == "en-US"+ assert SpeechPipeline._bcp47("es") == "es-ES"+++def test_bcp47_is_case_insensitive() -> None:+ assert SpeechPipeline._bcp47("DE") == "de-DE"+++def test_bcp47_unknown_returns_none() -> None:+ assert SpeechPipeline._bcp47("xx") is None+ assert SpeechPipeline._bcp47(None) is None+ assert SpeechPipeline._bcp47("") is None