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
feat(chat): grey out the words voice mode has not spoken yet
rubenluetke10-beep8eb06d3676f6
diff --git a/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsx b/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsxindex 3757de3cc2..38fe8ff197 100644--- a/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsx+++ b/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsx@@ -14,6 +14,7 @@ import { Greeting } from "@/components/home/Greeting";import { GigiMark } from "@/components/GigiMark";import { VoiceComposer } from "@/components/home/VoiceComposer";import { VoiceGlow } from "@/components/home/VoiceGlow";+import { useSpokenCursor } from "@/components/home/useSpokenCursor";import { TurnSteps, traceWorthShowing } from "@/components/home/TurnSteps";import { traceModel } from "@/lib/thinkingSteps";@@ -28,7 +29,10 @@ import { traceModel } from "@/lib/thinkingSteps";* says what is happening and carries Start / Stop. Behind it a soft light* rises from the bottom edge and breathes with the voices* (components/home/VoiceGlow); while the assistant thinks or speaks, its- * mark pulses under the last line. `onExit`, where the host page has a typed+ * mark pulses under the last line. While the answer is being spoken, the+ * words not yet said stay grey and light up as the voice reaches them+ * (components/home/useSpokenCursor — an estimate from the playback level,+ * since no voice path reports a per-word position). `onExit`, where the host page has a typed* half, puts the way back to the keyboard into the composer.** Empty, it is one centred column: the greeting and the voice composer.@@ -83,6 +87,14 @@ export function VoiceStage({ onExit }: { onExit?: () => void } = {}) {? liveReply: "";const hasLines = lines.length > 0 || Boolean(liveLine) || Boolean(liveAnswer);+ // The answer the voice is saying right now: the growing snapshot, or —+ // once its final line has landed while the audio still plays — that line.+ const speaking = active && voiceState === "speaking";+ const lastIsAnswer = !liveAnswer && lastLine?.who === "assistant";+ const spoken = useSpokenCursor(+ liveAnswer || (lastIsAnswer ? lastLine.text : ""),+ speaking,+ );const { rootRef, contentRef, atEnd, jumpToEnd, follow } = useStickToBottom();useLayoutEffect(follow, [follow, lines, liveLine, liveAnswer]);@@ -118,7 +130,7 @@ export function VoiceStage({ onExit }: { onExit?: () => void } = {}) {className="mx-auto flex w-full max-w-[720px] flex-col gap-6 px-6 pb-6 pt-8"aria-live="polite">- {lines.map((m) =>+ {lines.map((m, i) =>m.who === "steps" ? (<div key={m.id} className="max-w-[85%] pl-1" data-testid="transcript-steps"><TurnSteps@@ -136,11 +148,14 @@ export function VoiceStage({ onExit }: { onExit?: () => void } = {}) {who={m.who === "user" ? t("home.transcript_you") : assistantName}text={m.text}user={m.who === "user"}+ spoken={lastIsAnswer && i === lines.length - 1 ? spoken : null}/>),)}{liveLine && <TranscriptLine who={t("home.transcript_you")} text={liveLine} user live />}- {liveAnswer && <TranscriptLine who={assistantName} text={liveAnswer} user={false} live />}+ {liveAnswer && (+ <TranscriptLine who={assistantName} text={liveAnswer} user={false} live spoken={spoken} />+ )}{active && (voiceState === "thinking" || voiceState === "speaking") && (<div className="pl-0.5" data-testid="voice-turn-indicator" aria-hidden><GigiMark size={22} className="rounded-md animate-pulse motion-reduce:animate-none" />@@ -163,20 +178,25 @@ export function VoiceStage({ onExit }: { onExit?: () => void } = {}) {* right — italic, because they were heard — the assistant's as plain text* on the left. A LIVE line (words still being said, an* answer still being produced) is dimmed and italic with a cursor; the- * finished line it becomes is the same words, settled. The speaker's name- * stays for screen readers only — the side says who spoke.+ * finished line it becomes is the same words, settled. `spoken`, while the+ * voice is saying this line, splits it: the words already said in full ink,+ * the rest grey. The speaker's name stays for screen readers only — the side+ * says who spoke.*/function TranscriptLine({who,text,user,live = false,+ spoken = null,}: {who: string;text: string;user: boolean;live?: boolean;+ spoken?: number | null;}) {+ const reading = !user && spoken !== null;return (<divclassName={cn("flex", user ? "justify-end" : "justify-start")}@@ -188,11 +208,20 @@ function TranscriptLine({className={cn("max-w-[80%] whitespace-pre-wrap text-reading",user ? "jarvis-user-bubble rounded-[20px] px-4 py-2.5 italic" : "text-foreground",- live && (user ? "opacity-70" : "text-muted-foreground"),+ live && !reading && (user ? "opacity-70" : "text-muted-foreground"),)}>- {text}- {live && (+ {reading ? (+ <>+ <span data-testid="spoken-part">{text.slice(0, spoken)}</span>+ <span className="text-muted-foreground transition-colors" data-testid="unspoken-part">+ {text.slice(spoken)}+ </span>+ </>+ ) : (+ text+ )}+ {live && !reading && (<spanclassName="ml-0.5 inline-block h-[1em] w-0.5 translate-y-0.5 animate-pulse bg-current motion-reduce:animate-none"aria-hiddendiff --git a/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.test.ts b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.test.tsnew file mode 100644index 0000000000..4460fd7b6a--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.test.ts@@ -0,0 +1,57 @@+import { act, renderHook } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";++import { CHARS_PER_SECOND, useSpokenCursor, wordEnd } from "@/components/home/useSpokenCursor";+import { voiceOutputLevelRef } from "@/lib/voiceOutputLevel";++afterEach(() => {+ vi.useRealTimers();+ voiceOutputLevelRef.current = null;+});++describe("wordEnd", () => {+ it("lights a word up whole, never half-way", () => {+ expect(wordEnd("Morgen ist Freitag", 0)).toBe(0);+ expect(wordEnd("Morgen ist Freitag", 2)).toBe(6);+ expect(wordEnd("Morgen ist Freitag", 7.4)).toBe(10);+ expect(wordEnd("Morgen ist Freitag", 12)).toBe(18);+ expect(wordEnd("Morgen ist Freitag", 99)).toBe(18);+ });+});++describe("useSpokenCursor", () => {+ it("draws the text plainly while nothing is being spoken", () => {+ const { result } = renderHook(() => useSpokenCursor("Hallo Ruben", false));+ expect(result.current).toBeNull();+ });++ it("moves while audio plays and waits while it is silent", () => {+ vi.useFakeTimers({ toFake: ["requestAnimationFrame", "cancelAnimationFrame", "performance"] });+ const text = "Morgen ist Freitag, der zweite Oktober. Hast du was Besonderes vor?";+ voiceOutputLevelRef.current = 0.5;+ const { result } = renderHook(() => useSpokenCursor(text, true));+ expect(result.current).toBe(0);++ act(() => vi.advanceTimersByTime(1000));+ const afterOneSecond = result.current ?? 0;+ expect(afterOneSecond).toBeGreaterThan(CHARS_PER_SECOND / 2);+ expect(afterOneSecond).toBeLessThan(text.length);++ voiceOutputLevelRef.current = 0;+ act(() => vi.advanceTimersByTime(1000));+ const paused = result.current ?? 0;+ act(() => vi.advanceTimersByTime(1000));+ expect(result.current).toBe(paused);+ });++ it("starts a new answer from its beginning", () => {+ vi.useFakeTimers({ toFake: ["requestAnimationFrame", "cancelAnimationFrame", "performance"] });+ const { result, rerender } = renderHook(({ text }) => useSpokenCursor(text, true), {+ initialProps: { text: "Erste Antwort mit ein paar Worten" },+ });+ act(() => vi.advanceTimersByTime(1000));+ expect(result.current).toBeGreaterThan(0);+ rerender({ text: "Ganz andere Antwort" });+ expect(result.current).toBeLessThanOrEqual("Ganz".length);+ });+});diff --git a/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.ts b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.tsnew file mode 100644index 0000000000..6a95d09f6f--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.ts@@ -0,0 +1,82 @@+import { useEffect, useRef, useState } from "react";++import { voiceOutputLevelRef } from "@/lib/voiceOutputLevel";++/**+ * How far into the current answer the voice has got — the Claude app's+ * "words not yet spoken are grey" effect for voice mode.+ *+ * No voice path reports a playback position per word, so this is an+ * estimate made where the sound is: while the assistant is speaking and the+ * playback level says audio is actually coming out, the cursor moves at a+ * steady speaking rate; in a pause between sentences it waits. A surface+ * that cannot observe its playback level (`voiceOutputLevelRef` is null)+ * counts the whole speaking state as audible. The cursor snaps to word ends+ * so a word never lights up half-way, and the moment the assistant stops+ * speaking the whole answer is shown as spoken — a guess is never left+ * hanging greyed out.+ *+ * Returns the number of leading characters of `text` to draw as spoken, or+ * null while nothing is being spoken (draw the text plainly).+ */+export function useSpokenCursor(text: string, speaking: boolean): number | null {+ // The count is kept with the text it was measured on, so a new answer+ // never borrows the last one's position for a frame.+ const [shown, setShown] = useState({ text: "", chars: 0 });+ const charsRef = useRef(0);+ const textRef = useRef("");+ const lastAudibleRef = useRef(0);++ // A new answer starts from the beginning; the same answer growing (more+ // snapshot words arriving) keeps its place.+ if (text !== textRef.current) {+ if (!text.startsWith(textRef.current) || !textRef.current) charsRef.current = 0;+ textRef.current = text;+ }++ useEffect(() => {+ if (!speaking || !text || typeof requestAnimationFrame === "undefined") return;+ let frame = 0;+ let last = performance.now();+ const tick = (now: number) => {+ const dt = Math.min(0.1, (now - last) / 1000);+ last = now;+ const level = voiceOutputLevelRef.current;+ if (level === null || level > AUDIBLE_LEVEL) lastAudibleRef.current = now;+ // A word's own dips are not a pause: keep moving for a beat after+ // the last audible frame.+ if (now - lastAudibleRef.current < AUDIBLE_HOLD_MS) {+ charsRef.current = Math.min(textRef.current.length, charsRef.current + dt * CHARS_PER_SECOND);+ }+ const current = textRef.current;+ const next = wordEnd(current, charsRef.current);+ setShown((prev) =>+ prev.text === current && prev.chars === next ? prev : { text: current, chars: next },+ );+ frame = requestAnimationFrame(tick);+ };+ frame = requestAnimationFrame(tick);+ return () => cancelAnimationFrame(frame);+ }, [speaking, text]);++ if (!speaking || !text) return null;+ return shown.text === text ? shown.chars : wordEnd(text, charsRef.current);+}++/** A calm speaking voice: roughly 160 words a minute. */+export const CHARS_PER_SECOND = 15;+/** Playback level above which audio counts as audible. */+const AUDIBLE_LEVEL = 0.015;+const AUDIBLE_HOLD_MS = 300;++/**+ * The end of the word the cursor is in, so a word lights up whole. A cursor+ * at 0 stays at 0 — nothing has been said yet.+ */+export function wordEnd(text: string, chars: number): number {+ const at = Math.floor(chars);+ if (at <= 0) return 0;+ if (at >= text.length) return text.length;+ const space = text.slice(at).search(/\s/);+ return space === -1 ? text.length : at + space;+}