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(realtime): browser input-level indicator and voice hang-up handling
Ruben Lütke3ceaa75debd9
diff --git a/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsx b/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsxindex 21d29389b5..8e3cdc1c08 100644--- a/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsx+++ b/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsx@@ -26,6 +26,7 @@ export function BrowserRealtimeControl() {const [state, setState] = useState<ConnectionState>("idle");const [effectiveProvider, setEffectiveProvider] = useState("");const [error, setError] = useState("");+ const [inputLevel, setInputLevel] = useState(0);const clientRef = useRef<RealtimeAudioClient | null>(null);const browserSurface = capabilities.data?.native_file_actions === false;const visible = browserSurface && mode === "realtime";@@ -37,6 +38,7 @@ export function BrowserRealtimeControl() {setState("idle");setEffectiveProvider("");setError("");+ setInputLevel(0);setVoice("idle");}, [setVoice]);@@ -53,6 +55,7 @@ export function BrowserRealtimeControl() {if (role === "user" && isFinal) setVoice("thinking");},onAudio: () => setVoice("speaking"),+ onInputLevel: setInputLevel,onStatus: (status, payload) => {if (status === "audio_ready") {const provider = typeof payload.provider === "string" ? payload.provider : "";@@ -61,6 +64,10 @@ export function BrowserRealtimeControl() {setVoice("listening");} else if (status === "mode_fallback") {setEffectiveProvider(t("sidebar.realtime_pipeline_fallback"));+ } else if (status === "hangup") {+ // The session ended the call by voice ("auflegen" / end_call) —+ // release the microphone and return to idle.+ void stop();} else if (status === "turn_complete" || status === "tts_end") {setVoice("listening");} else if (status === "tts_cancel") {@@ -82,7 +89,7 @@ export function BrowserRealtimeControl() {setError(t("sidebar.realtime_error"));setVoice("error");}- }, [realtimeAvailable, setTranscription, setVoice, state, t]);+ }, [realtimeAvailable, setTranscription, setVoice, state, stop, t]);useEffect(() => {if (visible) return;@@ -138,6 +145,19 @@ export function BrowserRealtimeControl() {/><span>{connecting ? t("sidebar.realtime_connecting") : label}</span></button>+ {connected && (+ <div className="mt-1.5 flex h-1.5 items-stretch gap-0.5" aria-hidden="true">+ {[0.08, 0.24, 0.42, 0.6, 0.78].map((threshold) => (+ <span+ key={threshold}+ className={cn(+ "flex-1 rounded-sm transition-colors duration-75",+ inputLevel >= threshold ? "bg-primary" : "bg-border/60",+ )}+ />+ ))}+ </div>+ )}<div className="mt-1.5 min-h-4 text-[10px] text-muted-foreground" aria-live="polite">{error ||(connecteddiff --git a/jarvis/ui/web/frontend/src/lib/levelMeter.test.ts b/jarvis/ui/web/frontend/src/lib/levelMeter.test.tsnew file mode 100644index 0000000000..f81c14a6e6--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/levelMeter.test.ts@@ -0,0 +1,48 @@+import { describe, expect, it } from "vitest";++import { LevelMeter } from "./levelMeter";++describe("LevelMeter", () => {+ it("stays near zero on silence", () => {+ const meter = new LevelMeter();+ let level = 0;+ for (let i = 0; i < 60; i++) level = meter.push(0.0001);+ expect(level).toBeLessThan(0.05);+ });++ it("rises well above the floor on speech-level input", () => {+ const meter = new LevelMeter();+ // settle the noise floor on hiss first, like a real quiet room+ for (let i = 0; i < 30; i++) meter.push(0.0005);+ let level = 0;+ for (let i = 0; i < 10; i++) level = meter.push(0.05);+ expect(level).toBeGreaterThan(0.3);+ });++ it("attacks faster than it releases", () => {+ const meter = new LevelMeter();+ for (let i = 0; i < 30; i++) meter.push(0.0005);+ const quiet = meter.push(0.0005);+ const afterOneLoud = meter.push(0.08);+ const attackDelta = afterOneLoud - quiet;+ const afterOneQuiet = meter.push(0.0005);+ const releaseDelta = afterOneLoud - afterOneQuiet;+ expect(attackDelta).toBeGreaterThan(0);+ expect(releaseDelta).toBeGreaterThan(0);+ expect(attackDelta).toBeGreaterThan(releaseDelta);+ });++ it("clamps bad input to zero instead of propagating NaN", () => {+ const meter = new LevelMeter();+ expect(meter.push(Number.NaN)).toBeGreaterThanOrEqual(0);+ expect(meter.push(-1)).toBeGreaterThanOrEqual(0);+ expect(Number.isFinite(meter.push(0.01))).toBe(true);+ });++ it("reset returns to the resting state", () => {+ const meter = new LevelMeter();+ for (let i = 0; i < 10; i++) meter.push(0.1);+ meter.reset();+ expect(meter.push(0.0001)).toBeLessThan(0.05);+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/levelMeter.ts b/jarvis/ui/web/frontend/src/lib/levelMeter.tsnew file mode 100644index 0000000000..0d17947a64--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/levelMeter.ts@@ -0,0 +1,51 @@+// Client-side input-level normalizer for the browser realtime surface.+//+// Simplified port of the backend LevelNormalizer (jarvis/audio/mic_level.py):+// adaptive noise floor (EMA on quiet frames), peak auto-gain (fast attack,+// slow decay), and attack-fast / release-slow output smoothing so the level+// indicator pulses naturally instead of flickering. Raw RMS comes from the+// capture worklet on float32 samples in [-1, 1], the same scale the backend+// uses, so both surfaces behave alike.++const MIN_NOISE_FLOOR = 0.0002;+const MIN_PEAK = 0.004;++export class LevelMeter {+ private noiseFloor = 0.005;+ private peak = MIN_PEAK;+ private smoothed = 0;++ /** Normalize one raw RMS sample to a reactive 0..1 level. */+ push(rms: number): number {+ const value = Number.isFinite(rms) && rms > 0 ? rms : 0;++ if (value < this.noiseFloor * 1.5) {+ this.noiseFloor = 0.95 * this.noiseFloor + 0.05 * value;+ }+ this.noiseFloor = Math.max(this.noiseFloor, MIN_NOISE_FLOOR);++ const speechThreshold = this.noiseFloor * 3.0;+ const gated = Math.max(0, value - speechThreshold);++ if (gated > this.peak) this.peak = gated;+ else this.peak *= 0.997;+ this.peak = Math.max(this.peak, MIN_PEAK);++ const raw = Math.min(1, gated / this.peak);++ if (raw > this.smoothed) {+ // attack fast+ this.smoothed = 0.4 * this.smoothed + 0.6 * raw;+ } else {+ // release slow+ this.smoothed = 0.75 * this.smoothed + 0.25 * raw;+ }+ return this.smoothed;+ }++ reset(): void {+ this.noiseFloor = 0.005;+ this.peak = MIN_PEAK;+ this.smoothed = 0;+ }+}diff --git a/jarvis/ui/web/frontend/src/lib/pcm-worklet.ts b/jarvis/ui/web/frontend/src/lib/pcm-worklet.tsindex 08f6c8f8aa..18d07e4376 100644--- a/jarvis/ui/web/frontend/src/lib/pcm-worklet.ts+++ b/jarvis/ui/web/frontend/src/lib/pcm-worklet.ts@@ -24,9 +24,24 @@ function floatToInt16(float32: Float32Array): ArrayBuffer {}class PcmCapture extends AudioWorkletProcessor {+ private levelSum = 0;+ private levelCount = 0;+process(inputs: Float32Array[][]): boolean {const ch = inputs[0]?.[0];if (ch && ch.length) {+ // Throttled (~30 Hz) input-level messages for the speaking indicator —+ // computed here where the float32 samples already live, so no extra+ // server round-trip. Separate message type; the audio path below is+ // untouched.+ for (let i = 0; i < ch.length; i++) this.levelSum += ch[i] * ch[i];+ this.levelCount += ch.length;+ if (this.levelCount >= sampleRate / 30) {+ const rms = Math.sqrt(this.levelSum / this.levelCount);+ this.port.postMessage({ type: "level", rms });+ this.levelSum = 0;+ this.levelCount = 0;+ }const buf = floatToInt16(ch);this.port.postMessage(buf, [buf]);}diff --git a/jarvis/ui/web/frontend/src/lib/realtimeAudio.ts b/jarvis/ui/web/frontend/src/lib/realtimeAudio.tsindex db3ebc5a63..55faf08af5 100644--- a/jarvis/ui/web/frontend/src/lib/realtimeAudio.ts+++ b/jarvis/ui/web/frontend/src/lib/realtimeAudio.ts@@ -1,6 +1,8 @@// Dedicated /ws/audio client for browser-owned voice. Separate from the// JSON-only WSClient: this socket carries raw mono PCM16 in both directions.+import { LevelMeter } from "./levelMeter";+export function buildAudioSocketUrl(): string {const proto = window.location.protocol === "https:" ? "wss" : "ws";const host = window.location.host;@@ -15,6 +17,8 @@ export type RealtimeCallbacks = {onTranscript?: (text: string, isFinal: boolean, role: string) => void;onStatus?: (status: string, payload: RealtimeStatusPayload) => void;onAudio?: () => void;+ /** Normalized 0..1 microphone input level, ~30 Hz while capturing. */+ onInputLevel?: (level: number) => void;};/** Stateful linear PCM16 resampler used for provider audio playback.@@ -93,6 +97,7 @@ export class RealtimeAudioClient {private connecting: Promise<void> | null = null;private ready = false;private intentionalClose = false;+ private inputMeter = new LevelMeter();constructor(private cb: RealtimeCallbacks = {}) {}@@ -136,8 +141,15 @@ export class RealtimeAudioClient {this.ws = new WebSocket(buildAudioSocketUrl());this.ws.binaryType = "arraybuffer";this.captureNode.port.onmessage = (event) => {- if (this.ready && this.ws?.readyState === WebSocket.OPEN) {- this.ws.send(event.data as ArrayBuffer);+ const data = event.data as ArrayBuffer | { type?: string; rms?: number };+ if (data instanceof ArrayBuffer) {+ if (this.ready && this.ws?.readyState === WebSocket.OPEN) {+ this.ws.send(data);+ }+ return;+ }+ if (data && data.type === "level" && typeof data.rms === "number") {+ this.cb.onInputLevel?.(this.inputMeter.push(data.rms));}};@@ -263,5 +275,7 @@ export class RealtimeAudioClient {this.playbackResampler = null;this.stream = null;this.ctx = null;+ this.inputMeter.reset();+ this.cb.onInputLevel?.(0);}}