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(tts): wire Inworld into the factory + canonical same-family guard

Ruben Lütke3eb9145454c1
diff --git a/jarvis/core/config_writer.py b/jarvis/core/config_writer.py
index 2dbfa58084..117625bf36 100644
--- a/jarvis/core/config_writer.py
+++ b/jarvis/core/config_writer.py
@@ -875,6 +875,19 @@ def set_brain_provider_defaults(
# Without an entry, set_tts_provider() would pass an empty defaults dict and
# leave a stale model/voice from the previous provider in jarvis.toml.
_TTS_DEFAULTS: dict[str, dict[str, str]] = {
+ "inworld": {
+ # Inworld reads its per-language voices from the [tts.inworld] subtable
+ # (voice_de/voice_en/voice_es), NOT [tts].voice_de — same pattern as
+ # Cartesia. The scalar voice_de/voice_en are placeholders never consumed
+ # by the Inworld factory path. [tts].model is ignored too (the model
+ # comes from [tts.inworld].model or the plugin default inworld-tts-2), so
+ # model="" is skipped by _patch_tts_block's falsy gate. language_code=
+ # "auto" lets Inworld auto-detect the spoken language per turn.
+ "model": "",
+ "voice_de": "Charon", # placeholder; Inworld reads [tts.inworld].voice_de
+ "voice_en": "Charon", # placeholder; Inworld reads [tts.inworld].voice_en
+ "language_code": "auto",
+ },
"gemini-flash-tts": {
# model from jarvis/plugins/tts/gemini_flash_tts.py (factory line:
# tts_cfg.model or "gemini-3.1-flash-tts-preview")
diff --git a/jarvis/plugins/tts/__init__.py b/jarvis/plugins/tts/__init__.py
index b044385be3..fd1565b14b 100644
--- a/jarvis/plugins/tts/__init__.py
+++ b/jarvis/plugins/tts/__init__.py
@@ -39,6 +39,9 @@ _GEMINI_TTS_ALIASES = frozenset({"gemini-flash-tts", "gemini-flash", "gemini"})
_OPENROUTER_TTS_ALIASES = frozenset({
"openrouter", "openrouter-tts", "openrouter_tts", "open-router-tts",
})
+_INWORLD_ALIASES = frozenset({
+ "inworld", "inworld-tts", "inworld_tts", "inworld-tts-2",
+})
# Credential candidates per TTS family — the (keyring_key, env_var) pairs that
# hold a usable key, matching what each plugin's own key lookup reads. A fresh
@@ -47,6 +50,7 @@ _OPENROUTER_TTS_ALIASES = frozenset({
# instead of building a keyless provider that goes silently mute (open-source
# single-provider resilience, AP-22). Families absent here are left untouched.
_TTS_SECRET_CANDIDATES: dict[str, tuple[tuple[str, str], ...]] = {
+ "inworld": (("inworld_api_key", "INWORLD_API_KEY"),),
"gemini-flash-tts": (
("gemini_api_key", "GEMINI_API_KEY"),
("google_api_key", "GOOGLE_API_KEY"),
@@ -66,17 +70,21 @@ _TTS_SECRET_CANDIDATES: dict[str, tuple[tuple[str, str], ...]] = {
"openrouter": (("openrouter_api_key", "OPENROUTER_API_KEY"),),
}
-# Cross-family probe order when the configured provider has no key: the family
-# the maintainer ships first, then the common BYO-key alternatives. Only a family
-# that actually has a key is ever chosen.
+# Cross-family probe order when the configured provider has no key: native
+# premium families first (Inworld leads — the arena-#1 realtime default), then
+# the common BYO-key alternatives, with OpenRouter LAST as the last-resort
+# gateway (design 2026-07-07). Only a family that actually has a key is chosen.
_TTS_CROSS_FAMILY_ORDER: tuple[str, ...] = (
- "gemini-flash-tts", "elevenlabs", "cartesia", "grok-voice", "openrouter",
+ "inworld", "gemini-flash-tts", "elevenlabs", "cartesia", "grok-voice",
+ "openrouter",
)
def _canonical_tts_name(name: str) -> str:
"""Map any accepted TTS provider spelling to its canonical family name."""
n = (name or "").strip().lower()
+ if n in _INWORLD_ALIASES:
+ return "inworld"
if n in _ELEVEN_ALIASES:
return "elevenlabs"
if n in _CARTESIA_ALIASES:
@@ -232,7 +240,13 @@ def build_tts_from_config(tts_cfg: Any) -> Any:
primary = _build_provider(primary_cfg, primary_name)
fallback_name = (getattr(tts_cfg, "fallback", "") or "").strip().lower()
- if not fallback_name or fallback_name == primary_name:
+ # Compare CANONICAL families, not raw strings: a provider="gemini" +
+ # fallback="gemini-flash-tts" pair (or any alias pair) resolves to the SAME
+ # family and must NOT build a FallbackTTS(gemini, gemini) single-family brick
+ # (AP-22). primary_name is already the resolved (possibly crossed) provider.
+ if not fallback_name or _canonical_tts_name(fallback_name) == _canonical_tts_name(
+ primary_name
+ ):
return primary
try:
@@ -254,6 +268,42 @@ def _build_provider(tts_cfg: Any, provider: str) -> Any:
"""Build a single TTS provider instance for ``provider`` (no fallback wrap)."""
allow_sapi5 = bool(getattr(tts_cfg, "allow_sapi5_fallback", False))
+ if provider in _INWORLD_ALIASES:
+ try:
+ from jarvis.plugins.tts.inworld_tts import (
+ DEFAULT_MODEL as INWORLD_DEFAULT_MODEL,
+ )
+ from jarvis.plugins.tts.inworld_tts import (
+ DEFAULT_VOICE_DE,
+ DEFAULT_VOICE_EN,
+ DEFAULT_VOICE_ES,
+ InworldTTS,
+ )
+ except ImportError as exc:
+ raise RuntimeError(
+ f"TTS provider 'inworld' configured, but the plugin is not "
+ f"importable: {exc}. Check that "
+ f"jarvis/plugins/tts/inworld_tts.py exists and httpx is installed.",
+ ) from exc
+ # Per-language voices live in the [tts.inworld] sub-table (extra="allow"),
+ # NOT [tts].voice_de — that field may hold a foreign Gemini voice name
+ # ("Charon") which is not a valid Inworld voice. Falls back to the
+ # plugin's native defaults (Josef/Dennis/Diego). The shared [tts].model
+ # is ignored here (it may hold another family's id); the model comes from
+ # the sub-table or the plugin default.
+ extras = getattr(tts_cfg, "model_extra", None) or {}
+ iw = extras.get("inworld") if isinstance(extras, dict) else None
+ iw = iw if isinstance(iw, dict) else {}
+ return InworldTTS(
+ default_voice_de=iw.get("voice_de") or DEFAULT_VOICE_DE,
+ default_voice_en=iw.get("voice_en") or DEFAULT_VOICE_EN,
+ default_voice_es=iw.get("voice_es") or DEFAULT_VOICE_ES,
+ model=iw.get("model") or INWORLD_DEFAULT_MODEL,
+ language=tts_cfg.language_code or "auto",
+ speed=float(iw.get("speed", getattr(tts_cfg, "speed", 1.0))),
+ allow_sapi5_fallback=allow_sapi5,
+ )
+
if provider in ("elevenlabs", "eleven-labs", "eleven_labs", "11labs"):
try:
from jarvis.plugins.tts.elevenlabs_tts import (
diff --git a/pyproject.toml b/pyproject.toml
index 37dfe3639c..3d500a9211 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -288,6 +288,7 @@ groq-api = "jarvis.plugins.stt.groq_api:GroqWhisperAPI"
openrouter-stt = "jarvis.plugins.stt.openrouter_stt:OpenRouterSTT"
[project.entry-points."jarvis.tts"]
+inworld = "jarvis.plugins.tts.inworld_tts:InworldTTS"
elevenlabs = "jarvis.plugins.tts.elevenlabs_tts:ElevenLabsTTS"
gemini-flash-tts = "jarvis.plugins.tts.gemini_flash_tts:GeminiFlashTTS"
grok-voice = "jarvis.plugins.tts.grok_voice_tts:GrokVoiceTTS"
diff --git a/tests/unit/plugins/tts/test_inworld_factory.py b/tests/unit/plugins/tts/test_inworld_factory.py
new file mode 100644
index 0000000000..74d9d945b4
--- /dev/null
+++ b/tests/unit/plugins/tts/test_inworld_factory.py
@@ -0,0 +1,62 @@
+"""Factory wiring for Inworld + the canonical same-family fallback guard (AP-22)."""
+from __future__ import annotations
+
+from typing import Any
+
+import jarvis.core.config as cfg
+import jarvis.plugins.tts as tts_pkg
+from jarvis.core.config import TTSConfig
+from jarvis.plugins.tts.inworld_tts import InworldTTS
+
+
+def _keys(*env_names: str):
+ have = set(env_names)
+
+ def fake(candidates: tuple[tuple[str, str], ...]) -> str | None:
+ for _keyring, env in candidates:
+ if env in have:
+ return "KEY"
+ return None
+
+ return fake
+
+
+def _cfg(provider: str, **over: Any) -> TTSConfig:
+ # Real TTSConfig (extra="allow") so building any provider finds every field
+ # it reads; `fallback` rides in as an extra key the factory reads via getattr.
+ return TTSConfig(provider=provider, **over)
+
+
+def test_inworld_aliases_canonicalize():
+ for alias in ("inworld", "inworld-tts", "inworld-tts-2", "inworld_tts"):
+ assert tts_pkg._canonical_tts_name(alias) == "inworld"
+
+
+def test_factory_builds_inworld(monkeypatch):
+ monkeypatch.setattr(cfg, "get_secret_any", _keys("INWORLD_API_KEY"))
+ built = tts_pkg.build_tts_from_config(_cfg("inworld"))
+ assert isinstance(built, InworldTTS)
+ assert built.name == "inworld"
+
+
+def test_inworld_leads_cross_family_order(monkeypatch):
+ # A configured provider with no key, but only an Inworld key present, crosses
+ # to Inworld (native premium first, per the new order).
+ monkeypatch.setattr(cfg, "get_secret_any", _keys("INWORLD_API_KEY"))
+ name, _view = tts_pkg._resolve_keyed_tts_provider("cartesia", _cfg("cartesia"))
+ assert name == "inworld"
+
+
+def test_canonical_same_family_guard_no_brick(monkeypatch):
+ # provider="gemini" + fallback="gemini-flash-tts" resolve to the SAME family;
+ # the factory must return a bare provider, NOT a FallbackTTS single-family brick.
+ monkeypatch.setattr(cfg, "get_secret_any", _keys("GEMINI_API_KEY"))
+ built = tts_pkg.build_tts_from_config(_cfg("gemini", fallback="gemini-flash-tts"))
+ assert type(built).__name__ != "FallbackTTS"
+
+
+def test_distinct_family_fallback_still_wraps(monkeypatch):
+ # A genuinely different fallback family DOES wrap in FallbackTTS.
+ monkeypatch.setattr(cfg, "get_secret_any", _keys("INWORLD_API_KEY", "CARTESIA_API_KEY"))
+ built = tts_pkg.build_tts_from_config(_cfg("inworld", fallback="cartesia"))
+ assert type(built).__name__ == "FallbackTTS"