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): ElevenLabs ignores a foreign model/voice left in shared [tts]
Ruben Lütke2a2e3191b8d9
diff --git a/jarvis/plugins/tts/__init__.py b/jarvis/plugins/tts/__init__.pyindex 2d131a5ea8..b044385be3 100644--- a/jarvis/plugins/tts/__init__.py+++ b/jarvis/plugins/tts/__init__.py@@ -259,17 +259,24 @@ def _build_provider(tts_cfg: Any, provider: str) -> Any:from jarvis.plugins.tts.elevenlabs_tts import (JARVIS_VOICE_DANIEL,ElevenLabsTTS,+ coerce_elevenlabs_model,)except ImportError as exc:raise RuntimeError(f"TTS provider 'elevenlabs' configured, but the plugin is not "f"importable: {exc}",) from exc- # ElevenLabs uses voice IDs (cryptic hashes), no provider- # whitelist — we take the config value as-is.+ # Cross-family config hygiene: [tts] shares ONE model + voice field+ # across every TTS family. After switching FROM Cartesia/Gemini/Grok TO+ # ElevenLabs, a stale foreign model ('sonic-2') or voice name ('Kore')+ # can remain and 400s every ElevenLabs call — the provider then reads as+ # "Not working — synthesized 0 bytes" while the fallback voice speaks, so+ # it looks broken yet audible. Drop foreign values → ElevenLabs defaults.+ # A genuine ElevenLabs voice id (cryptic hash) is preserved as-is.+ eleven_cfg = _without_foreign_voice(tts_cfg, "elevenlabs")return ElevenLabsTTS(- model=tts_cfg.model or "eleven_flash_v2_5",- default_voice=tts_cfg.voice_de or JARVIS_VOICE_DANIEL,+ model=coerce_elevenlabs_model(tts_cfg.model),+ default_voice=eleven_cfg.voice_de or JARVIS_VOICE_DANIEL,language_code=tts_cfg.language_code or "de-DE",stability=tts_cfg.stability,similarity_boost=tts_cfg.similarity_boost,diff --git a/jarvis/plugins/tts/elevenlabs_tts.py b/jarvis/plugins/tts/elevenlabs_tts.pyindex 2a4f6680b3..a8dd0656dd 100644--- a/jarvis/plugins/tts/elevenlabs_tts.py+++ b/jarvis/plugins/tts/elevenlabs_tts.py@@ -37,6 +37,43 @@ ELEVENLABS_TTS_SAMPLE_RATE = 24_000_OUTPUT_FORMAT = "pcm_24000"_STREAMING_LATENCY_OPTIMIZATION = 1+DEFAULT_MODEL = "eleven_flash_v2_5"++# Every ElevenLabs speech model id starts with ``eleven`` (the API namespace).+# Curated snapshot for an exact-match fast path; the prefix rule below still+# admits a NEW eleven_* model we don't list yet.+_KNOWN_ELEVEN_MODELS: frozenset[str] = frozenset({+ "eleven_flash_v2_5", "eleven_flash_v2",+ "eleven_turbo_v2_5", "eleven_turbo_v2",+ "eleven_multilingual_v2", "eleven_multilingual_v1",+ "eleven_monolingual_v1", "eleven_v3",+ "eleven_english_sts_v2", "eleven_multilingual_sts_v2",+})+++def coerce_elevenlabs_model(model_id: str | None) -> str:+ """Return a usable ElevenLabs model id for ``model_id``.++ Guards against a FOREIGN model id left in the shared ``[tts].model`` config+ after switching TTS providers. ``[tts]`` has a single global ``model`` field+ shared across every TTS family, so flipping TO ElevenLabs can leave another+ provider's value in place (Cartesia's ``sonic-2``, Gemini's ``gemini-*``,+ an OpenRouter ``vendor/model``) — ElevenLabs then 400s ("An invalid ID has+ been received for voice: 'sonic-2'"). Mirrors ``coerce_speech_model`` for+ OpenRouter. Resolution:++ * empty → the default model,+ * a known eleven model → itself,+ * any ``eleven*`` id → itself (trust a NEW model we don't list yet),+ * anything else → the default model (a foreign provider's id).+ """+ mid = (model_id or "").strip()+ if not mid:+ return DEFAULT_MODEL+ if mid in _KNOWN_ELEVEN_MODELS or mid.lower().startswith("eleven"):+ return mid+ return DEFAULT_MODEL+# On quota exhaustion / an auth problem, skip ElevenLabs briefly# so not every sentence retriggers the 429 path._QUOTA_COOLDOWN_S = 900.0diff --git a/tests/unit/plugins/tts/test_elevenlabs_foreign_params.py b/tests/unit/plugins/tts/test_elevenlabs_foreign_params.pynew file mode 100644index 0000000000..75df474e13--- /dev/null+++ b/tests/unit/plugins/tts/test_elevenlabs_foreign_params.py@@ -0,0 +1,92 @@+"""ElevenLabs must not 400 on a FOREIGN model / voice left in shared ``[tts]``.++``[tts]`` has a single global ``model`` + ``voice_de``/``voice_en`` shared across+every TTS family. Switching FROM Cartesia/Gemini/Grok TO ElevenLabs can leave a+foreign value behind (Cartesia's ``sonic-2`` model, Gemini's ``Kore`` voice).+ElevenLabs used to forward those verbatim and the API answered ``400 — "An+invalid ID has been received for voice: 'sonic-2'"`` on every call → the provider+read as "Not working — synthesized 0 bytes" while a fallback voice still spoke+(looks broken yet audible). The factory now sanitises foreign values to the+ElevenLabs defaults. Mirrors the OpenRouter ``coerce_speech_model`` guard.+"""+from __future__ import annotations++from types import SimpleNamespace+from typing import Any++import jarvis.plugins.tts as tts_pkg+from jarvis.plugins.tts.elevenlabs_tts import (+ DEFAULT_MODEL,+ JARVIS_VOICE_DANIEL,+ coerce_elevenlabs_model,+)+++# --- coerce_elevenlabs_model: foreign model ids fall back to the default ------+++def test_cartesia_model_is_coerced_to_default() -> None:+ assert coerce_elevenlabs_model("sonic-2") == DEFAULT_MODEL+++def test_gemini_model_is_coerced_to_default() -> None:+ assert coerce_elevenlabs_model("gemini-3.1-flash-tts-preview") == DEFAULT_MODEL+++def test_openrouter_shaped_model_is_coerced_to_default() -> None:+ assert coerce_elevenlabs_model("google/gemini-3.1-flash-tts-preview") == DEFAULT_MODEL+++def test_empty_and_none_model_use_default() -> None:+ assert coerce_elevenlabs_model("") == DEFAULT_MODEL+ assert coerce_elevenlabs_model(None) == DEFAULT_MODEL+ assert coerce_elevenlabs_model(" ") == DEFAULT_MODEL+++def test_known_eleven_model_is_kept() -> None:+ assert coerce_elevenlabs_model("eleven_multilingual_v2") == "eleven_multilingual_v2"+++def test_new_unlisted_eleven_model_is_trusted() -> None:+ # A NEW eleven_* model we don't list yet is trusted (prefix rule), not blocked.+ assert coerce_elevenlabs_model("eleven_flash_v9_future") == "eleven_flash_v9_future"+++# --- factory build: a fully contaminated config yields a valid instance -------+++def _cfg(**over: Any) -> SimpleNamespace:+ base = dict(+ provider="elevenlabs",+ model="",+ voice_de="",+ voice_en="",+ language_code="de-DE",+ stability=0.5,+ similarity_boost=0.75,+ style=0.0,+ speed=1.0,+ allow_sapi5_fallback=False,+ )+ base.update(over)+ return SimpleNamespace(**base)+++def test_build_drops_cartesia_model_and_gemini_voice() -> None:+ """The exact live failure: model='sonic-2' (Cartesia), voice_de='Kore' (Gemini)."""+ inst = tts_pkg._build_provider(_cfg(model="sonic-2", voice_de="Kore", voice_en="Kore"), "elevenlabs")+ assert inst._model == DEFAULT_MODEL+ assert inst._model.startswith("eleven")+ # The foreign Gemini voice name must NOT survive as a bogus ElevenLabs id.+ assert inst._default_voice == JARVIS_VOICE_DANIEL+ assert inst._default_voice != "Kore"+++def test_build_keeps_a_real_elevenlabs_voice_and_model() -> None:+ """A genuine ElevenLabs voice id (cryptic hash) + model is preserved as-is."""+ inst = tts_pkg._build_provider(+ _cfg(model="eleven_turbo_v2_5", voice_de="onwK4e9ZLuTAKqWW03F9"),+ "elevenlabs",+ )+ assert inst._model == "eleven_turbo_v2_5"+ assert inst._default_voice == "onwK4e9ZLuTAKqWW03F9"