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(voice): measure the assistant on the native path, and give the row a hue

rubenluetke10-beep4d574222b945
diff --git a/jarvis/ui/web/frontend/src/components/home/StageWaveform.tsx b/jarvis/ui/web/frontend/src/components/home/StageWaveform.tsx
index dc62dad3dd..00c19bd318 100644
--- a/jarvis/ui/web/frontend/src/components/home/StageWaveform.tsx
+++ b/jarvis/ui/web/frontend/src/components/home/StageWaveform.tsx
@@ -64,14 +64,24 @@ import { cn } from "@/lib/utils";
* reaches the soft ends. That is the depth cue — the row looks lit from its
* own centre line instead of flatly filled.
*
+ * ## The colour (maintainer, 2026-08-28)
+ *
+ * A measured row runs along a lavender-to-blue ramp; everything unmeasured
+ * stays neutral. That is not decoration but the same statement the shapes
+ * make: hue appears exactly when the drawing has a real signal behind it,
+ * and "ready", "thinking" and a speech we cannot hear stay in
+ * `--muted-foreground`. The two hues are the design system's timeline
+ * pastels — the palette reserved for in-product agent visualisation, which
+ * is precisely what this row is — and they live as `--voice-wave-a/b` in
+ * index.css with their own light-mode values, because a pastel tuned for
+ * charcoal disappears on warm paper.
+ *
* Canvas rather than DOM capsules: forty to sixty shapes repainted every
* frame are cheap on a 2D context and would be layout work as elements.
- * Colours are read from the theme tokens on the element itself, so the
+ * Every colour is read from the theme tokens on the element itself, so the
* drawing follows light/dark and the wallpaper floor without a single
- * literal — the brand carries no hue any more, so the row travels along the
- * VALUE scale (dim dot → full accent) where a coloured visualiser would
- * travel along a hue. Reduced motion keeps the information (a level meter)
- * and drops the decoration (no breathing, no sweep, no scroll).
+ * literal. Reduced motion keeps the information (a level meter) and drops
+ * the decoration (no breathing, no sweep, no scroll).
*/
export function StageWaveform({
levelRef,
@@ -118,7 +128,7 @@ export function StageWaveform({
// rare, a frame is not.
let tokens = readTokens(canvas);
let tokensAt = 0;
- let fills = buildFills(ctx, height, tokens);
+ let fills = buildFills(ctx, width, height, tokens);
let history: number[] = [];
let head = 0;
@@ -141,7 +151,7 @@ export function StageWaveform({
// The tallest capsule stops short of the box: the row needs air above
// and below or a loud syllable reads as a clipped block.
span = Math.max(2, height * TALLEST - BAR_MIN);
- fills = buildFills(ctx, height, tokens);
+ fills = buildFills(ctx, width, height, tokens);
const next = Math.max(6, Math.floor((width + BAR_GAP) / ROW_PITCH));
if (next !== count) {
count = next;
@@ -155,9 +165,15 @@ export function StageWaveform({
* input the geometry is derived from, so every phase describes WHAT it
* has to say and the drawing stays one place.
*/
- const paint = (shaped: number[], alphas: number[], fill: string | CanvasGradient) => {
+ const paint = (shaped: number[], alphas: number[], tint: string | CanvasGradient) => {
ctx.clearRect(0, 0, width, height);
- ctx.fillStyle = fill;
+ // Pass 1 draws the capsules as a MASK: white, carrying only the
+ // vertical light profile and each column's own opacity. Pass 2 (below)
+ // pours the colour in through it. Two gradients for the whole frame
+ // instead of one per capsule, and the hue ramp and the lit core stay
+ // independent of each other.
+ ctx.globalCompositeOperation = "source-over";
+ ctx.fillStyle = fills.mask;
// Columns sit on a fixed pitch and every capsule is drawn around its
// column's CENTRE, so a blooming capsule grows outwards in both
// directions instead of pushing the row sideways.
@@ -177,7 +193,15 @@ export function StageWaveform({
ctx.globalAlpha = (alphas[i] ?? 1) * edge(t);
capsule(ctx, cx0 + i * ROW_PITCH - w / 2, mid - h / 2, w, h);
}
+ // Pass 2: colour, kept only where the mask is. `source-in` multiplies
+ // the incoming alpha by what is already there, so every capsule keeps
+ // the shape and the light it was just given and takes the ramp's hue
+ // at its own position in the row.
ctx.globalAlpha = 1;
+ ctx.globalCompositeOperation = "source-in";
+ ctx.fillStyle = tint;
+ ctx.fillRect(0, 0, width, height);
+ ctx.globalCompositeOperation = "source-over";
};
/** How present a column is: a quiet floor that the activity lifts. */
@@ -225,7 +249,7 @@ export function StageWaveform({
shaped[i] = v;
alphas[i] = presence(v);
}
- paint(shaped, alphas, fills.primary);
+ paint(shaped, alphas, fills.wave);
};
const frame = (now: number) => {
@@ -234,9 +258,9 @@ export function StageWaveform({
last = now;
if (now - tokensAt > 1000) {
const next = readTokens(canvas);
- if (next.primary !== tokens.primary || next.muted !== tokens.muted) {
+ if (next.waveA !== tokens.waveA || next.muted !== tokens.muted) {
tokens = next;
- fills = buildFills(ctx, height, tokens);
+ fills = buildFills(ctx, width, height, tokens);
}
tokensAt = now;
}
@@ -277,7 +301,7 @@ export function StageWaveform({
shaped[i] = v;
alphas[i] = presence(0.5 * pulse * rim(t));
}
- paint(shaped, alphas, fills.primary);
+ paint(shaped, alphas, fills.muted);
return;
}
@@ -309,7 +333,7 @@ export function StageWaveform({
shaped[i] = v;
alphas[i] = presence(Math.min(1, 0.25 + gain) * rim(t));
}
- paint(shaped, alphas, fills.primary);
+ paint(shaped, alphas, fills.muted);
return;
}
@@ -431,11 +455,19 @@ function capsule(ctx: CanvasRenderingContext2D, x: number, y: number, w: number,
ctx.fill();
}
-type Tokens = { primary: string; muted: string; error: string };
+type Tokens = {
+ waveA: string;
+ waveB: string;
+ muted: string;
+ error: string;
+};
type Fills = {
- primary: string | CanvasGradient;
- muted: string | CanvasGradient;
- error: string | CanvasGradient;
+ /** Vertical light profile, colourless — the shape mask (see `paint`). */
+ mask: string | CanvasGradient;
+ /** The row's hue ramp, left to right. */
+ wave: string | CanvasGradient;
+ muted: string;
+ error: string;
};
/**
@@ -448,20 +480,40 @@ type Fills = {
* reference gets from a violet-to-blue ramp, spelled in value because the
* brand no longer carries a hue.
*/
-function buildFills(ctx: CanvasRenderingContext2D, height: number, tokens: Tokens): Fills {
- const make = (triple: string): string | CanvasGradient => {
- if (height <= 1) return `hsl(${triple})`;
+function buildFills(
+ ctx: CanvasRenderingContext2D,
+ width: number,
+ height: number,
+ tokens: Tokens,
+): Fills {
+ let mask: string | CanvasGradient = "#fff";
+ if (height > 1) {
const g = ctx.createLinearGradient(0, 0, 0, height);
- g.addColorStop(0, `hsl(${triple} / ${CAP_ALPHA})`);
- g.addColorStop(0.34, `hsl(${triple} / ${SHOULDER_ALPHA})`);
- g.addColorStop(0.5, `hsl(${triple} / 1)`);
- g.addColorStop(0.66, `hsl(${triple} / ${SHOULDER_ALPHA})`);
- g.addColorStop(1, `hsl(${triple} / ${CAP_ALPHA})`);
- return g;
- };
- return { primary: make(tokens.primary), muted: make(tokens.muted), error: make(tokens.error) };
+ g.addColorStop(0, `hsl(0 0% 100% / ${CAP_ALPHA})`);
+ g.addColorStop(0.34, `hsl(0 0% 100% / ${SHOULDER_ALPHA})`);
+ g.addColorStop(0.5, "hsl(0 0% 100%)");
+ g.addColorStop(0.66, `hsl(0 0% 100% / ${SHOULDER_ALPHA})`);
+ g.addColorStop(1, `hsl(0 0% 100% / ${CAP_ALPHA})`);
+ mask = g;
+ }
+ let wave: string | CanvasGradient = `hsl(${tokens.waveB})`;
+ if (width > 1) {
+ // Across the MIDDLE of the row, not its full width. A canvas gradient
+ // clamps to its end colours outside the span, so the quiet rims stay
+ // solid and the part a conversation actually occupies gets the whole
+ // ramp. Anchored edge to edge, the centre only ever sampled the middle
+ // of the gradient and the row read as one flat colour.
+ const g = ctx.createLinearGradient(width * RAMP_INSET, 0, width * (1 - RAMP_INSET), 0);
+ g.addColorStop(0, `hsl(${tokens.waveA})`);
+ g.addColorStop(1, `hsl(${tokens.waveB})`);
+ wave = g;
+ }
+ return { mask, wave, muted: `hsl(${tokens.muted})`, error: `hsl(${tokens.error})` };
}
+/** Where the hue ramp starts and ends, as a fraction of the row. */
+const RAMP_INSET = 0.22;
+
/** Strength of the lit core at the caps and at the shoulders. */
const CAP_ALPHA = 0.45;
const SHOULDER_ALPHA = 0.82;
@@ -479,7 +531,8 @@ function readTokens(el: HTMLElement): Tokens {
return raw || fallback;
};
return {
- primary: token("--primary", "0 0% 100%"),
+ waveA: token("--voice-wave-a", "267 44% 76%"),
+ waveB: token("--voice-wave-b", "214 51% 75%"),
muted: token("--muted-foreground", "47 5% 59%"),
error: token("--destructive", "0 84% 60%"),
};
diff --git a/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsx b/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsx
index ec1c40e46d..9bd3e23391 100644
--- a/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsx
+++ b/jarvis/ui/web/frontend/src/components/voice/BrowserRealtimeControl.tsx
@@ -18,7 +18,11 @@ import {
setBrowserVoiceInputOwnership,
setVoiceInputLevel,
} from "@/lib/voiceInputLevel";
-import { clearVoiceOutputLevel, setVoiceOutputLevel } from "@/lib/voiceOutputLevel";
+import {
+ clearVoiceOutputLevel,
+ setBrowserVoiceOutputOwnership,
+ setVoiceOutputLevel,
+} from "@/lib/voiceOutputLevel";
type ConnectionState = "idle" | "connecting" | "connected" | "error";
@@ -135,7 +139,8 @@ export function BrowserRealtimeControl() {
setSpokenText("");
levelRef.current = 0;
clearVoiceInputLevel("browser");
- clearVoiceOutputLevel();
+ clearVoiceOutputLevel("browser");
+ setBrowserVoiceOutputOwnership(false);
setBrowserVoiceInputOwnership(false);
setVoice("idle");
await client?.disconnect();
@@ -152,7 +157,7 @@ export function BrowserRealtimeControl() {
setEffectiveProvider("");
levelRef.current = 0;
clearVoiceInputLevel("browser");
- clearVoiceOutputLevel();
+ clearVoiceOutputLevel("browser");
await previousClient?.disconnect();
if (connectionGenerationRef.current !== generation) return;
@@ -178,8 +183,8 @@ export function BrowserRealtimeControl() {
},
onOutputLevel: (value) => {
if (!isCurrent()) return;
- if (value === null) clearVoiceOutputLevel();
- else setVoiceOutputLevel(value);
+ if (value === null) clearVoiceOutputLevel("browser");
+ else setVoiceOutputLevel(value, "browser");
},
onStatus: (status, payload) => {
if (!isCurrent()) return;
@@ -306,9 +311,12 @@ export function BrowserRealtimeControl() {
]);
useEffect(() => {
- setBrowserVoiceInputOwnership(
- visible && (state === "connecting" || state === "connected"),
- );
+ // This surface owns BOTH directions while it is live: it holds the
+ // microphone and it plays the reply, so the backend's own levels for
+ // either one would be a second, unsynchronised opinion.
+ const owns = visible && (state === "connecting" || state === "connected");
+ setBrowserVoiceInputOwnership(owns);
+ setBrowserVoiceOutputOwnership(owns);
}, [state, visible]);
useEffect(() => {
@@ -321,6 +329,7 @@ export function BrowserRealtimeControl() {
const client = clientRef.current;
clientRef.current = null;
setBrowserVoiceInputOwnership(false);
+ setBrowserVoiceOutputOwnership(false);
if (client) void client.disconnect();
},
[],
diff --git a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
index 4957d4777e..424c5c47f0 100644
--- a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
@@ -9,6 +9,7 @@ import {
isForThisWindow,
} from "@/lib/dictationTarget";
import { clearVoiceInputLevel, setVoiceInputLevel } from "@/lib/voiceInputLevel";
+import { clearVoiceOutputLevel, setVoiceOutputLevel } from "@/lib/voiceOutputLevel";
import {
SECTION_LABELS,
VOICE_STATES,
@@ -79,6 +80,7 @@ export function useWebSocket(): void {
setWarming(code === 1013 || Boolean(info?.authRetryPending));
setConnected(false);
clearVoiceInputLevel("native");
+ clearVoiceOutputLevel("native");
},
onMessage: (raw) => {
const welcome = WSWelcome.safeParse(raw);
@@ -115,6 +117,10 @@ export function useWebSocket(): void {
const audioLevel = WSAudioLevel.safeParse(raw);
if (audioLevel.success) {
setVoiceInputLevel(audioLevel.data.input, "native");
+ // Absent (older backend) leaves the tap where it was rather than
+ // asserting silence — see lib/voiceOutputLevel on 0 vs null.
+ const out = audioLevel.data.output;
+ if (out !== undefined) setVoiceOutputLevel(out, "native");
return;
}
@@ -214,6 +220,7 @@ export function useWebSocket(): void {
// A state boundary invalidates the previous phase's sample. Native
// capture will immediately supply a fresh value while listening.
clearVoiceInputLevel("native");
+ clearVoiceOutputLevel("native");
// The live-transcript box has no other reset path: without this,
// the last utterance of a session survives into READY/IDLE and the
// next session, masquerading as a frozen live transcript (live
@@ -676,6 +683,7 @@ export function useWebSocket(): void {
return () => {
clearVoiceInputLevel("native");
+ clearVoiceOutputLevel("native");
client.close();
singleton = null;
mounted.current = false;
diff --git a/jarvis/ui/web/frontend/src/index.css b/jarvis/ui/web/frontend/src/index.css
index 013c81745d..91e77a3a9f 100644
--- a/jarvis/ui/web/frontend/src/index.css
+++ b/jarvis/ui/web/frontend/src/index.css
@@ -577,6 +577,28 @@ label,
--viz-result: 53 12% 13%; /* full ink — the run's landing */
--viz-deliverable: 47 6% 43%; /* files left behind */
+ /* --- Voice waveform ---------------------------------------------------
+ The ONE place in the app that carries more than one hue, and it is not
+ a brand colour: these are the design system's timeline pastels
+ (lavender `timeline-edit`, pastel blue `timeline-read`), whose whole
+ job is in-product agent visualisation. The Jarvis bar's waveform is
+ exactly that — a live picture of the agent listening and speaking —
+ so it draws its capsules along a lavender-to-blue ramp instead of a
+ flat accent. Retiring the brand hue made the interface monochrome; it
+ did not retire this palette, and the row of capsules is the surface it
+ was reserved for.
+
+ The two are pulled a little further apart than the raw pastels, and
+ the ramp is laid across the MIDDLE of the row rather than its full
+ width (see buildFills): a conversation lives in the centre of the
+ tape, so a gradient anchored at the outer edges would only ever show
+ its middle and read as one flat colour.
+
+ Light mode keeps the same two hues and drops the lightness: the
+ pastels are tuned for a charcoal ground and vanish on warm paper. */
+ --voice-wave-a: 272 40% 56%; /* lavender, oldest end of the tape */
+ --voice-wave-b: 205 55% 45%; /* blue, newest end of the tape */
+
/* Legacy aliases. Kept because they are referenced from a handful of
places that predate the token set; all now follow the theme. The names
outlived the colour — nothing yellow is left in either — but they stay
@@ -665,6 +687,11 @@ label,
--viz-result: 0 0% 100%;
--viz-deliverable: 47 6% 58%;
+ /* Voice waveform — the timeline pastels at their documented values;
+ see :root for why this surface is allowed a hue at all. */
+ --voice-wave-a: 272 45% 74%; /* lavender, near #C0A8DD */
+ --voice-wave-b: 205 62% 70%; /* blue, near #9FBBE0 */
+
--jarvis-yellow: 247 247 244;
--jarvis-yellow-dim: 154 151 140;
--jarvis-grid: 60 4% 8%;
diff --git a/jarvis/ui/web/frontend/src/lib/voiceOutputLevel.ts b/jarvis/ui/web/frontend/src/lib/voiceOutputLevel.ts
index eadd9f243c..1c11df8840 100644
--- a/jarvis/ui/web/frontend/src/lib/voiceOutputLevel.ts
+++ b/jarvis/ui/web/frontend/src/lib/voiceOutputLevel.ts
@@ -6,23 +6,48 @@
*
* - a number (0 included) — a tap is running and this is what is currently
* leaving for the speaker. `0` is the honest "Jarvis is between words";
- * - `null` — there is NO tap on this device, so nothing may claim to draw
- * the assistant's voice.
+ * - `null` — there is NO tap, so nothing may claim to draw the assistant's
+ * voice. Renderers fall back to a sweep: motion, promising nothing.
*
- * That distinction exists because only the browser realtime surface plays
- * the reply itself (components/voice/BrowserRealtimeControl → the
- * `pcm-playback` worklet, which measures the samples it writes). When the
- * backend speaks through the OS audio device instead, the page never sees a
- * sample, and a waveform drawn there would be an invention. Renderers fall
- * back to a sweep on `null`: motion, promising nothing.
+ * ## Two sources, one owner
+ *
+ * Whoever plays the reply is who can measure it, and that is not always the
+ * same side:
+ *
+ * - `native` — the backend owns the speakers. `jarvis.audio.level_tap`
+ * measures each block and, importantly, schedules its level for the
+ * moment that block becomes AUDIBLE, so the number is in step with what
+ * the person hears rather than with what PortAudio accepted. It reaches
+ * the page on the `audio.level` frame.
+ * - `browser` — the browser realtime surface plays the reply itself, and
+ * the `pcm-playback` worklet measures the samples it writes.
+ *
+ * Both can be live at once (the backend keeps its player while a browser
+ * session runs), so browser ownership wins the same way it does for the
+ * microphone: while it is claimed, native writes are dropped instead of
+ * fighting the browser's samples frame by frame.
*/
+export type VoiceOutputLevelSource = "native" | "browser";
+
export const voiceOutputLevelRef: { current: number | null } = { current: null };
-export function setVoiceOutputLevel(value: number): void {
+let browserOwnsOutput = false;
+
+export function setVoiceOutputLevel(
+ value: number,
+ source: VoiceOutputLevelSource = "native",
+): void {
+ if (source === "native" && browserOwnsOutput) return;
voiceOutputLevelRef.current = Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0;
}
/** Give up the tap — the surface that owned playback has stopped. */
-export function clearVoiceOutputLevel(): void {
+export function clearVoiceOutputLevel(source: VoiceOutputLevelSource = "native"): void {
+ if (source === "native" && browserOwnsOutput) return;
+ voiceOutputLevelRef.current = null;
+}
+
+export function setBrowserVoiceOutputOwnership(active: boolean): void {
+ browserOwnsOutput = active;
voiceOutputLevelRef.current = null;
}
diff --git a/jarvis/ui/web/frontend/src/schema/ws.ts b/jarvis/ui/web/frontend/src/schema/ws.ts
index a5644d0960..d4a3d6f446 100644
--- a/jarvis/ui/web/frontend/src/schema/ws.ts
+++ b/jarvis/ui/web/frontend/src/schema/ws.ts
@@ -27,10 +27,14 @@ export const WSWelcome = z.object({
});
export type WSWelcomeT = z.infer<typeof WSWelcome>;
-/** Ephemeral normalized native-microphone level for canvas animation. */
+/** Ephemeral normalized native voice levels for canvas animation — the
+ * microphone and the assistant's own output. `output` is optional so a page
+ * talking to an older backend still parses the frame; absent means "this
+ * server cannot tell us", which is NOT the same as a measured zero. */
export const WSAudioLevel = z.object({
type: z.literal("audio.level"),
input: z.number().min(0).max(1),
+ output: z.number().min(0).max(1).optional(),
});
export type WSAudioLevelT = z.infer<typeof WSAudioLevel>;
diff --git a/jarvis/ui/web/schema.py b/jarvis/ui/web/schema.py
index 8551450979..8501ae6449 100644
--- a/jarvis/ui/web/schema.py
+++ b/jarvis/ui/web/schema.py
@@ -48,10 +48,23 @@ class WSWelcome(BaseModel):
class WSAudioLevel(BaseModel):
- """Ephemeral normalized microphone level for lightweight UI animation."""
+ """Ephemeral normalized voice levels for lightweight UI animation.
+
+ Both directions of the conversation, because a bar that draws one of them
+ and mimes the other is telling half a truth: ``input`` is the microphone
+ (``jarvis.audio.mic_level``), ``output`` is what the speakers are emitting
+ (``jarvis.audio.level_tap``, which already schedules each level for the
+ moment its audio block becomes AUDIBLE rather than the moment PortAudio
+ accepted it — so the number a client draws is in step with what the person
+ hears).
+
+ ``output`` carries a default so a client parsing an older server, or a
+ server with no player at all, still validates.
+ """
type: Literal["audio.level"] = "audio.level"
input: float = Field(ge=0.0, le=1.0)
+ output: float = Field(default=0.0, ge=0.0, le=1.0)
# ----------------------------------------------------------------------
diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.py
index b5dd1f4825..c378b51742 100644
--- a/jarvis/ui/web/server.py
+++ b/jarvis/ui/web/server.py
@@ -104,6 +104,12 @@ class WebServer:
self._mic_level_sessions: set[str] = set()
self._mic_level_unsub: Callable[[], None] | None = None
self._mic_level_latest = 0.0
+ # The assistant's own voice, from jarvis.audio.level_tap. It rides the
+ # SAME frame and the same coalescing as the microphone: two directions
+ # of one conversation, one ~30 Hz channel, so adding it costs no extra
+ # WebSocket traffic.
+ self._tts_level_latest = 0.0
+ self._tts_level_unsub: Callable[[], None] | None = None
self._mic_level_revision = 0
self._mic_level_task: asyncio.Task[None] | None = None
self._server: uvicorn.Server | None = None
@@ -1644,12 +1650,18 @@ class WebServer:
)
def _ensure_mic_level_bridge(self) -> None:
- """Tap the existing microphone stream while a web UI is connected."""
+ """Tap both voice levels while a web UI is connected.
+
+ The microphone and the assistant's own output. ``level_tap`` only
+ computes its RMS while something is subscribed, so a web client
+ connecting is what turns that measurement on — and disconnecting turns
+ it back off.
+ """
if self._mic_level_unsub is not None or not self._mic_level_sessions:
return
# Lazy import keeps audio modules off the web server's startup path.
- from jarvis.audio import mic_level
+ from jarvis.audio import level_tap, mic_level
loop = asyncio.get_running_loop()
@@ -1661,15 +1673,27 @@ class WebServer:
# and this handoff. The subscriber is removed during teardown.
logger.opt(exception=exc).debug("Microphone level loop is closed")
+ def _receive_tts(level: float) -> None:
+ try:
+ loop.call_soon_threadsafe(self._queue_tts_level, float(level))
+ except RuntimeError as exc:
+ logger.opt(exception=exc).debug("Output level loop is closed")
+
self._mic_level_unsub = mic_level.subscribe(_receive)
+ self._tts_level_unsub = level_tap.subscribe(_receive_tts)
def _stop_mic_level_bridge(self) -> None:
unsubscribe = self._mic_level_unsub
self._mic_level_unsub = None
+ unsubscribe_tts = self._tts_level_unsub
+ self._tts_level_unsub = None
self._mic_level_latest = 0.0
+ self._tts_level_latest = 0.0
self._mic_level_revision += 1
if unsubscribe is not None:
unsubscribe()
+ if unsubscribe_tts is not None:
+ unsubscribe_tts()
task = self._mic_level_task
if task is not None and task is not asyncio.current_task() and not task.done():
@@ -1693,13 +1717,25 @@ class WebServer:
if self._mic_level_task is None or self._mic_level_task.done():
self._mic_level_task = asyncio.create_task(self._drain_mic_levels())
+ def _queue_tts_level(self, level: float) -> None:
+ """Same coalescing as the microphone, for the assistant's own voice."""
+ if not self._mic_level_sessions:
+ return
+ self._tts_level_latest = min(1.0, max(0.0, level)) if math.isfinite(level) else 0.0
+ self._mic_level_revision += 1
+ if self._mic_level_task is None or self._mic_level_task.done():
+ self._mic_level_task = asyncio.create_task(self._drain_mic_levels())
+
async def _drain_mic_levels(self) -> None:
"""Send only the freshest level; functional WS traffic has priority."""
sent_revision = -1
try:
while self._mic_level_sessions and sent_revision != self._mic_level_revision:
sent_revision = self._mic_level_revision
- frame = WSAudioLevel(input=self._mic_level_latest).model_dump()
+ frame = WSAudioLevel(
+ input=self._mic_level_latest,
+ output=self._tts_level_latest,
+ ).model_dump()
await asyncio.gather(
*(
self._send_mic_level(session_id, frame)