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(dictation): dictate during a live call instead of hanging it up

rubenluetke10-beep0097faae0fd9
diff --git a/jarvis/core/events.py b/jarvis/core/events.py
index 83e970112c..b16e2082c0 100644
--- a/jarvis/core/events.py
+++ b/jarvis/core/events.py
@@ -1120,6 +1120,24 @@ class VoiceMuteChanged(Event):
source: str = ""
+@dataclass(frozen=True, slots=True)
+class VoiceInputHeld(Event):
+ """A live call's microphone is held back while something else listens.
+
+ Published by the speech pipeline when a dictation starts beside a live
+ voice call (``held=True``) and again once that dictation has delivered its
+ text (``held=False``). The call keeps running; only the user's audio stops
+ reaching the realtime model, so the dictated words go into the text field
+ and never become a turn. Separate from ``VoiceMuteChanged`` on purpose:
+ that is the user's own mute, and a dictation must neither show it on
+ every mute icon nor clear it when it ends.
+
+ ``reason`` is free-form for the log (``"dictation"`` today).
+ """
+ held: bool = False
+ reason: str = ""
+
+
@dataclass(frozen=True, slots=True)
class VoiceSpeakerMuteChanged(Event):
"""Authoritative broadcast that the assistant's voice went silent or audible.
diff --git a/jarvis/live/session.py b/jarvis/live/session.py
index 24471f72bd..a896aa0da6 100644
--- a/jarvis/live/session.py
+++ b/jarvis/live/session.py
@@ -51,6 +51,13 @@ def _pipeline_input_muted() -> bool:
return bool(getattr(get_speech_pipeline(), "is_muted", False))
+def _pipeline_input_held() -> bool:
+ """Whether a dictation beside the call holds the user's audio back."""
+ from jarvis.core.runtime_refs import get_speech_pipeline
+
+ return bool(getattr(get_speech_pipeline(), "is_voice_input_held", False))
+
+
def _summary_index(event: dict) -> int:
"""The summary part a reasoning-summary event belongs to (0 when absent)."""
try:
@@ -128,7 +135,11 @@ class LiveVoiceSession:
# The mute on the pet strip, the Jarvis Bar or the orb. A browser call
# owns its microphone in the WebView, out of reach of the pipeline's own
# capture gate, so the session drops the frames and tells the page.
+ # ``_input_muted`` is what the frame gate and the page obey: the
+ # user's mute OR a dictation holding the input (see ``VoiceInputHeld``).
self._input_muted = False
+ self._user_muted = False
+ self._input_held = False
self._watching_input_mute = False
self._media_timeout: asyncio.TimerHandle | None = None
self._active_model = ""
@@ -624,29 +635,52 @@ class LiveVoiceSession:
def _watch_input_mute(self) -> None:
"""Adopt the current microphone mute and follow it until the call ends."""
- self._input_muted = _pipeline_input_muted()
+ self._user_muted = _pipeline_input_muted()
+ self._input_held = _pipeline_input_held()
+ self._input_muted = self._user_muted or self._input_held
if self._bus is None or self._watching_input_mute:
return
- from jarvis.core.events import VoiceMuteChanged
+ from jarvis.core.events import VoiceInputHeld, VoiceMuteChanged
self._bus.subscribe(VoiceMuteChanged, self._on_input_mute_changed)
+ self._bus.subscribe(VoiceInputHeld, self._on_input_held_changed)
self._watching_input_mute = True
def _stop_watching_input_mute(self) -> None:
if not self._watching_input_mute or self._bus is None:
return
- from jarvis.core.events import VoiceMuteChanged
+ from jarvis.core.events import VoiceInputHeld, VoiceMuteChanged
self._bus.unsubscribe(VoiceMuteChanged, self._on_input_mute_changed)
+ self._bus.unsubscribe(VoiceInputHeld, self._on_input_held_changed)
self._watching_input_mute = False
async def _on_input_mute_changed(self, event: Any) -> None:
+ """Follow the user's own microphone mute."""
+ self._user_muted = bool(event.muted)
+ await self._apply_input_mute()
+
+ async def _on_input_held_changed(self, event: Any) -> None:
+ """Follow a dictation that borrows the user's voice beside the call.
+
+ The call stays open; only the audio stops reaching the model until the
+ dictated text has been delivered, so it never becomes a spoken turn.
+ """
+ self._input_held = bool(event.held)
+ log.info(
+ "Live call input %s (%s).",
+ "held" if self._input_held else "released",
+ getattr(event, "reason", "") or "unknown",
+ )
+ await self._apply_input_mute()
+
+ async def _apply_input_mute(self) -> None:
"""Drop the user's audio from now on and let the page silence its track.
Dropping frames here covers the PCM socket. A WebRTC call sends its
audio straight to the provider, so only the page can silence that one.
"""
- self._input_muted = bool(event.muted)
+ self._input_muted = self._user_muted or self._input_held
if self._closing:
return
try:
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index d7045af4e0..e419b4f5bf 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -79,6 +79,7 @@ from jarvis.core.events import (
TranscriptionUpdate,
UtteranceCaptured,
VoiceBootStatus,
+ VoiceInputHeld,
VoiceMuteChanged,
VoiceMuteToggleRequested,
VoiceSessionEnded,
@@ -2382,6 +2383,10 @@ class SpeechPipeline:
# and the moment ``_dictation_task`` exists (or the handover is refused),
# and never both at once. See ``_begin_dictation_handover``.
self._dictation_handover_task: asyncio.Task[None] | None = None
+ # A dictation started beside a live call, and whether that call's input
+ # is held for it. See ``_live_call_owns_microphone``.
+ self._dictation_beside_call = False
+ self._voice_input_held = False
# 0.0 is a real value here — "no ceiling" — so it must NOT be coerced
# to a default the way an absent or malformed setting is. The old
# ``or 300.0`` did exactly that and made the off switch unreachable
@@ -10850,10 +10855,69 @@ class SpeechPipeline:
"The voice pipeline is not running, so dictation cannot start.",
)
return False
+ if self._live_call_owns_microphone():
+ # A live call keeps running: its input is held, not hung up.
+ return self._commit_dictation(
+ loop, target=target, source=source, beside_call=True
+ )
if self._voice_session_holds_microphone():
return self._begin_dictation_handover(loop, target=target, source=source)
return self._commit_dictation(loop, target=target, source=source)
+ def _live_call_owns_microphone(self) -> bool:
+ """True while a live realtime call captures the microphone in the WebView.
+
+ Such a call owns its own capture (getUserMedia, with the browser's echo
+ cancellation), so a dictation does not have to take the device away
+ from it. Instead the dictation records through its own capture and the
+ call's input is HELD until the text is delivered (``VoiceInputHeld``):
+ the conversation stays open and the dictated words never become a turn.
+ Push-to-talk is excluded — its raw recording is the pipeline's own
+ stream, and that lane keeps the ordinary handover.
+ """
+ if getattr(self, "_ptt_mode", False):
+ return False
+ try:
+ from jarvis.live.runtime import owns_microphone
+ except Exception: # noqa: BLE001 — no live stack means no live call
+ log.debug("live call registry unavailable", exc_info=True)
+ return False
+ return owns_microphone()
+
+ @property
+ def is_voice_input_held(self) -> bool:
+ """Whether a dictation currently holds a live call's input back.
+
+ Read by a call that starts DURING such a dictation, so it adopts the
+ hold instead of hearing the dictated words.
+ """
+ return bool(getattr(self, "_voice_input_held", False))
+
+ def _set_voice_input_held(self, held: bool) -> None:
+ """Hold or release a live call's input and tell the call. Never raises."""
+ if bool(getattr(self, "_voice_input_held", False)) == held:
+ return
+ self._voice_input_held = held
+ log.info(
+ "Live call input %s for the dictation.",
+ "held" if held else "released",
+ )
+ self._publish_event_soon(VoiceInputHeld(held=held, reason="dictation"))
+
+ def _on_beside_call_dictation_done(self, _task: asyncio.Task[None]) -> None:
+ """Give the call its voice back once the dictation has fully ended.
+
+ A done-callback rather than a ``finally``: it runs for every end of the
+ task, including one cancelled before its first step, so the call can
+ never be left deaf. The task ends only after the text was delivered,
+ which is the moment the user may talk to the call again.
+ """
+ try:
+ self._dictation_beside_call = False
+ self._set_voice_input_held(False)
+ except Exception: # noqa: BLE001 — a release must never become a crash
+ log.warning("Releasing the live call input failed", exc_info=True)
+
def _voice_session_holds_microphone(self) -> bool:
"""True while the VOICE lane owns the one input device.
@@ -11013,26 +11077,42 @@ class SpeechPipeline:
log.debug("Dictation handover callback failed", exc_info=True)
def _commit_dictation(
- self, loop: asyncio.AbstractEventLoop, *, target: str, source: str = "api"
+ self,
+ loop: asyncio.AbstractEventLoop,
+ *,
+ target: str,
+ source: str = "api",
+ beside_call: bool = False,
) -> bool:
"""Arm the wake block, announce the turn and spawn the recording task.
The commit point shared by the direct start and the handover, so both
arrive in the dictation lane through exactly one door. Always returns
``True``; every reason not to be here is checked by ``start_dictation``.
+
+ ``beside_call`` means a live call keeps running next to this dictation:
+ its input is held until the task ends, and the call's hangup event is
+ left alone — it belongs to the call, not to this recording.
"""
self._dictation_started_by = str(source or "api")
self._dictation_discard_requested = False
+ self._dictation_beside_call = beside_call
# A fresh dictation session must NOT inherit a stale hangup. ``_hangup_event``
# is set by every "auflegen" and is otherwise only cleared when the next
# VOICE session is accepted (``_run_session``). The dictation lane shares
# that event in its ``asyncio.wait`` gate, so a leftover hangup from an
# earlier voice call would finalize this session on its first tick — the
# mic appears to "stop the instant you click it". Clear it here, mirroring
- # the voice-path ``self._hangup_event.clear()`` at session accept.
+ # the voice-path ``self._hangup_event.clear()`` at session accept. Beside
+ # a live call the event is the CALL's: clearing it could swallow a
+ # hangup the user just asked for, and the lane does not wait on it.
hangup = getattr(self, "_hangup_event", None)
- if hangup is not None:
+ if hangup is not None and not beside_call:
hangup.clear()
+ if beside_call:
+ # Held BEFORE the recording task exists, so the call stops hearing
+ # the user as early as possible.
+ self._set_voice_input_held(True)
# Stored RAW ("auto" / "insert" / "chat"). ``auto`` is resolved when the
# recording ENDS, not here: the window that matters is the one in front
# when the text is delivered. Clicking "Start dictating" in the app and
@@ -11076,10 +11156,13 @@ class SpeechPipeline:
self._dictation_task = loop.create_task(
self._dictation_session(), name="dictation"
)
+ if beside_call:
+ self._dictation_task.add_done_callback(self._on_beside_call_dictation_done)
log.info(
- "🎙️ dictation started (transcribe-only, target=%s, via=%s).",
+ "🎙️ dictation started (transcribe-only, target=%s, via=%s%s).",
self._dictation_target,
self._dictation_started_by,
+ ", beside a live call" if beside_call else "",
)
return True
@@ -13150,7 +13233,14 @@ class SpeechPipeline:
else None
)
stop_task = asyncio.create_task(self._dictation_stop_event.wait())
- hangup_task = asyncio.create_task(self._hangup_event.wait())
+ # Beside a live call the hangup event is the CALL's: hanging up
+ # the conversation must not throw away what is being dictated.
+ hangup_event = (
+ asyncio.Event()
+ if getattr(self, "_dictation_beside_call", False)
+ else self._hangup_event
+ )
+ hangup_task = asyncio.create_task(hangup_event.wait())
# Only a recording the HOLD key started is owed a release edge;
# the watchdog ends it when the key is physically up and that
# edge never came (BUG-191). It sets the stop event, so it is
@@ -13173,7 +13263,7 @@ class SpeechPipeline:
timeout=self._dictation_max_s or None,
return_when=asyncio.FIRST_COMPLETED,
)
- hung_up = hangup_task in done or self._hangup_event.is_set()
+ hung_up = hangup_task in done or hangup_event.is_set()
if getattr(self, "_dictation_discard_requested", False):
# The bar's close-X: end it like a hangup — nothing
# transcribed, nothing delivered.
diff --git a/tests/contract/test_live_input_mute.py b/tests/contract/test_live_input_mute.py
index 7e8f4c0bf4..1bbe293999 100644
--- a/tests/contract/test_live_input_mute.py
+++ b/tests/contract/test_live_input_mute.py
@@ -11,7 +11,7 @@ import pytest
from jarvis.core import runtime_refs
from jarvis.core.bus import EventBus
-from jarvis.core.events import VoiceMuteChanged
+from jarvis.core.events import VoiceInputHeld, VoiceMuteChanged
from jarvis.live.native import NativeLiveVoiceSession
from jarvis.live.session import LiveVoiceSession
@@ -98,3 +98,37 @@ async def test_an_ended_call_stops_following_the_mute(call):
await call.bus.publish(VoiceMuteChanged(muted=True, source="pet_strip"))
assert call.page == []
assert call.session._input_muted is False
+
+
+async def test_a_dictation_holds_the_call_input_until_it_is_delivered(call):
+ call.session._watch_input_mute()
+ await call.bus.publish(VoiceInputHeld(held=True, reason="dictation"))
+ assert call.page[-1] == {"type": "input_mute", "muted": True}
+ await call.session.handle_audio_frame(PCM)
+ assert call.connection.sent == []
+
+ await call.bus.publish(VoiceInputHeld(held=False, reason="dictation"))
+ assert call.page[-1] == {"type": "input_mute", "muted": False}
+ await call.session.handle_audio_frame(PCM)
+ assert len(call.connection.sent) == 1
+
+
+async def test_releasing_the_hold_never_unmutes_the_user(call):
+ call.session._watch_input_mute()
+ await call.bus.publish(VoiceMuteChanged(muted=True, source="pet_strip"))
+ await call.bus.publish(VoiceInputHeld(held=True, reason="dictation"))
+ await call.bus.publish(VoiceInputHeld(held=False, reason="dictation"))
+ assert call.page[-1] == {"type": "input_mute", "muted": True}
+ await call.session.handle_audio_frame(PCM)
+ assert call.connection.sent == []
+
+
+async def test_a_call_that_starts_during_a_dictation_adopts_the_hold(call):
+ call.pipeline.is_voice_input_held = True
+ call.session._watch_input_mute()
+ assert call.session._input_muted is True
+ await call.session.handle_audio_frame(PCM)
+ assert call.connection.sent == []
diff --git a/tests/unit/speech/test_dictation_beside_live_call.py b/tests/unit/speech/test_dictation_beside_live_call.py
new file mode 100644
index 0000000000..09a0fdbf56
--- /dev/null
+++ b/tests/unit/speech/test_dictation_beside_live_call.py
@@ -0,0 +1,248 @@
+"""The dictation key works DURING a live call instead of hanging it up.
+
+Live 2026-10-01: holding the dictation key in a realtime call ended the call —
+the press took the microphone the old way (hang up, wait, record). A live call
+captures the microphone in the WebView, so the two never fight over the device:
+the dictation records through its own capture while the call's input is HELD
+(``VoiceInputHeld``). The model hears nothing until the dictated text has been
+delivered, then the conversation continues as if nothing happened.
+"""
+
+from __future__ import annotations
+
+import asyncio
+
+import pytest
+
+import jarvis.live.runtime as live_runtime
+import jarvis.speech.pipeline as pipeline_mod
+from jarvis.core.bus import EventBus
+from jarvis.core.events import DictationRefused, DictationStarted, VoiceInputHeld
+from jarvis.speech.pipeline import PipelineState, SpeechPipeline, TurnTakingState
+
+
+class _StubSTT:
+ async def transcribe_pcm(self, pcm: bytes): # pragma: no cover - never called
+ raise AssertionError("no transcription in this unit test")
+
+
+class _SilentMic:
+ """A capture device that never yields a frame."""
+
+ opens = 0
+
+ def __init__(self, *args: object, **kwargs: object) -> None:
+ pass
+
+ async def __aenter__(self) -> _SilentMic:
+ type(self).opens += 1
+ return self
+
+ async def __aexit__(self, *exc: object) -> bool:
+ return False
+
+ async def stream(self): # type: ignore[no-untyped-def]
+ await asyncio.Event().wait()
+ yield # pragma: no cover - unreachable, keeps this an async generator
+
+
+class _Player:
+ def __init__(self) -> None:
+ self.stops = 0
+
+ def stop(self) -> None:
+ self.stops += 1
+
+
+class _Collector:
+ def __init__(self, bus: EventBus) -> None:
+ self.held: list[bool] = []
+ self.started: list[DictationStarted] = []
+ self.refused: list[DictationRefused] = []
+ bus.subscribe(VoiceInputHeld, self._held)
+ bus.subscribe(DictationStarted, self._started)
+ bus.subscribe(DictationRefused, self._refused)
+
+ async def _held(self, event: VoiceInputHeld) -> None:
+ self.held.append(event.held)
+
+ async def _started(self, event: DictationStarted) -> None:
+ self.started.append(event)
+
+ async def _refused(self, event: DictationRefused) -> None:
+ self.refused.append(event)
+
+
+def _pipeline(bus: EventBus) -> SpeechPipeline:
+ """A pipeline reduced to the dictation lane, sitting in a live call."""
+ pipe = SpeechPipeline.__new__(SpeechPipeline)
+ pipe._bus = bus
+ pipe._utterance_stt = _StubSTT()
+ pipe._dictation_task = None
+ pipe._dictation_handover_task = None
+ pipe._dictation_stop_event = asyncio.Event()
+ pipe._dictation_cfg = None
+ pipe._dictation_max_s = 5.0
+ pipe._dictation_wake_block_until = 0.0
+ pipe._dictation_completion_published = True
+ pipe._ptt_mode = False
+ pipe._ptt_partial_interval_s = 0.0 # no live probe in these tests
+ # The desktop pipeline sits in an active session while the call runs.
+ pipe._state = PipelineState.ACTIVE
+ pipe._turn_state = TurnTakingState.IDLE
+ pipe._muted = False
+ pipe._input_device = "default"
+ pipe._input_priority = ()
+ pipe._hangup_event = asyncio.Event()
+ pipe._player = _Player()
+
+ async def _no_delivery(**_kwargs) -> str:
+ return ""
+
+ pipe._finish_dictation = _no_delivery # type: ignore[assignment]
+ return pipe
+
+
+async def _drain_bus() -> None:
+ for _ in range(6):
+ await asyncio.sleep(0)
+
+
[email protected](autouse=True)
+def _live_call(monkeypatch: pytest.MonkeyPatch):
+ """One registered browser call that owns the microphone."""
+ monkeypatch.setattr(_SilentMic, "opens", 0)
+ monkeypatch.setattr(pipeline_mod, "MicrophoneCapture", _SilentMic)
+ monkeypatch.setattr(live_runtime, "_active", {"call-1": object()})
+ monkeypatch.setattr(live_runtime, "_opening", set())
+
+
+async def test_the_key_dictates_without_hanging_up_the_call() -> None:
+ bus = EventBus()
+ seen = _Collector(bus)
+ pipe = _pipeline(bus)
+
+ assert pipe.start_dictation(target="insert") is True
+ await _drain_bus()
+
+ assert pipe._dictation_handover_task is None, "no handover beside a live call"
+ assert pipe._hangup_event.is_set() is False, "the call is not hung up"
+ assert pipe._player.stops == 0
+ assert pipe._state is PipelineState.ACTIVE
+ assert pipe.dictation_active() is True
+ assert _SilentMic.opens == 1, "the dictation records through its own capture"
+ assert [e.target for e in seen.started] == ["insert"]
+ assert seen.refused == []
+ # The call stops hearing the user for as long as the dictation runs.
+ assert pipe.is_voice_input_held is True
+ assert seen.held == [True]
+
+ task = pipe._dictation_task
+ assert task is not None
+ pipe.stop_dictation()
+ await asyncio.wait_for(task, timeout=2.0)
+ await _drain_bus()
+
+ # Delivered — the call gets the user's voice back.
+ assert pipe.is_voice_input_held is False
+ assert seen.held == [True, False]
+ assert pipe._hangup_event.is_set() is False
+
+
+async def test_a_cancelled_dictation_still_gives_the_call_its_voice_back() -> None:
+ bus = EventBus()
+ seen = _Collector(bus)
+ pipe = _pipeline(bus)
+
+ assert pipe.start_dictation() is True
+ task = pipe._dictation_task
+ assert task is not None
+ # Cancelled before its first step: no ``finally`` inside it ever runs.
+ task.cancel()
+ with pytest.raises(asyncio.CancelledError):
+ await task
+ await _drain_bus()
+
+ assert pipe.is_voice_input_held is False
+ assert seen.held == [True, False]
+
+
+async def test_hanging_up_the_call_does_not_throw_the_dictation_away() -> None:
+ bus = EventBus()
+ _Collector(bus)
+ pipe = _pipeline(bus)
+
+ assert pipe.start_dictation() is True
+ await _drain_bus()
+ pipe._hangup_event.set()
+ await _drain_bus()
+
+ assert pipe.dictation_active() is True, "the call's hangup is not the dictation's"
+
+ task = pipe._dictation_task
+ assert task is not None
+ pipe.stop_dictation()
+ await asyncio.wait_for(task, timeout=2.0)
+ # The call's hangup request survives the dictation untouched.
+ assert pipe._hangup_event.is_set() is True
+
+
+async def test_a_pending_call_hangup_is_not_swallowed_by_the_press() -> None:
+ bus = EventBus()
+ _Collector(bus)
+ pipe = _pipeline(bus)
+ pipe._hangup_event.set()
+
+ assert pipe.start_dictation() is True
+ assert pipe._hangup_event.is_set() is True
+
+ task = pipe._dictation_task
+ assert task is not None
+ pipe.stop_dictation()
+ await asyncio.wait_for(task, timeout=2.0)
+
+
+async def test_push_to_talk_keeps_the_ordinary_handover(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """PTT records on the pipeline's own stream, so it is not a WebView call."""
+ bus = EventBus()
+ seen = _Collector(bus)
+ pipe = _pipeline(bus)
+ pipe._ptt_mode = True
+ hangups: list[bool] = []
+ monkeypatch.setattr(pipe, "request_hangup", lambda: hangups.append(True))
+
+ assert pipe.start_dictation() is True
+ assert hangups == [True]
+ handover = pipe._dictation_handover_task
+ assert handover is not None
+ handover.cancel()
+ await asyncio.gather(handover, return_exceptions=True)
+ await _drain_bus()
+ assert seen.held == []
+ assert pipe.is_voice_input_held is False
+
+
+async def test_no_call_means_no_hold(monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(live_runtime, "_active", {})
+ bus = EventBus()
+ seen = _Collector(bus)
+ pipe = _pipeline(bus)
+ pipe._state = PipelineState.IDLE
+
+ assert pipe.start_dictation() is True
+ await _drain_bus()
+ assert seen.held == []
+ assert pipe.is_voice_input_held is False
+
+ task = pipe._dictation_task
+ assert task is not None
+ pipe.stop_dictation()
+ await asyncio.wait_for(task, timeout=2.0)