Skip to content
Browse documentation

Voice mode for your assistant: ink in water that the voice moves, with the talk button, the microphone and the reply wired to your own backend.

Used forVoice modeRealtime agentsPhone and support botsDictation

Install with the shadcn CLI

$ npx shadcn@latest add https://hairlineui.com/r/voice-orb.json

Registered the namespace? Then it’s shadcn add @hairline/voice-orb. Set it up

Templates

Need the whole page?

61 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 6 are free.

All 61 templates

Where it’s used

  • Voice mode

    Talk to your assistant: record, send to your speech-to-text, model and voice, play the answer.

  • Realtime agents

    OpenAI Realtime, LiveKit or ElevenLabs over WebRTC: hand it the call, it shows who is talking.

  • Phone and support bots

    A caller-facing agent listening, working and answering, interruptible mid-sentence.

  • Dictation

    Hold to talk, let go to send, with the microphone shown hearing you.

What it handles for you

A voice button looks simple until it ships: permission prompts, knowing when someone has stopped talking, a reply that has to be interruptible, a request to cancel, and an orb that should follow the real sound. This handles all of it and leaves the speech stack to you.

Instead of wiring upMediaRecorder boilerplatevoice activity detectionAnalyserNode visualizerlooping orb videoLottie voice animationpush-to-talk buttonframer-motion
  1. One function to plug in

    onTurn gets the recorded audio and an AbortSignal; return a fetch Response, a Blob, a URL, an <audio> element or a stream, and it plays.

  2. Or a realtime call

    connect gets the open microphone and returns the voice coming back; listening, thinking and speaking are read from the audio, or set from your provider's events.

  3. Knows when you stopped

    Speech is detected from the microphone level; a short quiet after it sends the turn, with a longest-turn limit and a give-up if nobody speaks.

  4. Interrupt and cancel

    Pressing during the reply stops it and listens; pressing while it thinks aborts the request through the signal; End lets go of everything.

  5. Every failure explained

    A blocked microphone, no microphone, an insecure page, a failed request or reply: the button becomes the fix and the reason folds open under it.

  6. A real fluid, cheap

    Stable fluids on the GPU with sharp ink; sound read inside the frame loop, never React state; sleeps off screen; a still under reduced motion.

Overview

Most voice-mode orbs are a looping video, and wiring one to a real assistant is left to you. This is the whole piece. The orb is a real fluid solved on the GPU: while you talk, your voice's frequency bands push ink in from the rim; while it answers, each syllable blooms ink out from the centre; while it thinks, two streams wind into a spiral. VoiceTalk puts one button under it that morphs into what pressing it does next (Talk, Send, Thinking, Interrupt), and it handles the microphone, recording, the end of speech, playing the reply, interrupting it and every error. You give it one async function, or a realtime connection, and it fits whatever speech stack you already run.

States

idle
The button says Talk (or Hold to talk); leftover ink drifts and clears in the slowly turning water.
listening
The microphone is recording and the button says Send. Eight jets on the rim, one per frequency band, push ink inward as the voice gets louder in that band. 900ms of quiet after speech sends the turn.
thinking
onTurn is running and the button says Thinking (pressing aborts it). The water turns and two thin streams wind into a spiral.
speaking
The reply plays and the button says Interrupt. Each band blooms ink out from the centre; the vessel swells slightly with loudness.
error
The button turns into the fix (Allow the microphone, Try again) and the reason folds open under it.
between states
Each state is a spring weight (about 0.8s), so one motion hands the ink to the next; labels morph, End slides in beside the button.
reduced motion
No loop: each state is shown as one still, settled picture; the controls change in place.

Usage

usage.tsx
import { VoiceTalk } from "@/components/voice-talk";<VoiceTalk onTurn={(audio, { signal }) => fetch("/api/voice", { method: "POST", body: audio, signal })} />

Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.

Works with

With your own speech stack, or a realtime call

Record-then-reply: one route takes the audio and answers with audio. Realtime: hand the microphone to a WebRTC connection and return the remote track. The same orb and button work for both.

example.tsx
// app/api/voice/route.ts: your speech-to-text, your model, your voice.export async function POST(req: Request) {  const text = await transcribe(await req.blob());  const answer = await reply(text);  return new Response(await speak(answer), { headers: { "content-type": "audio/mpeg" } });}// A turn-based voice mode."use client";import { VoiceTalk } from "@/components/voice-talk";export function VoiceMode() {  return (    <VoiceTalk      onTurn={async (audio, { signal }) => {        const res = await fetch("/api/voice", { method: "POST", body: audio, signal });        if (!res.ok) throw new Error("The assistant didn't answer.");        return res; // played as it arrives, metered for the orb      }}    />  );}// Realtime over WebRTC (OpenAI Realtime shown; LiveKit and others look the same).export function RealtimeVoice() {  return (    <VoiceTalk      connect={async (mic, { signal, setState }) => {        const pc = new RTCPeerConnection();        mic.getTracks().forEach((track) => pc.addTrack(track, mic));        const remote = new Promise<MediaStream>((resolve) => (pc.ontrack = (e) => resolve(e.streams[0])));        const events = pc.createDataChannel("oai-events");        events.onmessage = (e) => {          const { type } = JSON.parse(e.data);          if (type === "response.created") setState("thinking");          if (type === "response.done") setState(null); // back to reading the audio        };        await pc.setLocalDescription(await pc.createOffer());        const answer = await fetch("/api/realtime-session", { method: "POST", body: pc.localDescription!.sdp, signal });        await pc.setRemoteDescription({ type: "answer", sdp: await answer.text() });        return { output: await remote, close: () => pc.close() };      }}    />  );}

Props

onTurn
(audio: Blob, { signal, mimeType, duration }) => Promise<VoiceReply>
Record-then-reply. Return a Response, Blob, ArrayBuffer, URL, <audio> element, MediaStream or nothing. Throw to show an error.
connect
(mic: MediaStream, { signal, setState, end }) => Promise<{ output, close? }>
Realtime instead: return the voice coming back (a MediaStream or an <audio> element). setState overrides what the audio says; end hangs up.
mode= "tap"
"tap" | "hold"
Tap to talk (sends when you stop, or on Send), or hold to talk and let go to send. Space and Enter work too.
continuous= false
boolean
After each reply, listen again, hands-free.
silence= 900
number
Quiet after speech, in ms, that ends a turn.
maxTurn= 30000
number
Longest turn in ms; it is sent when reached.
waitForSpeech= 8000
number
How long to wait for any speech before giving up, in ms.
getMicrophone
() => Promise<MediaStream>
Your own microphone stream (a device picker, an SDK). Default: getUserMedia with echo cancellation, released after each turn.
onPhaseChange / onError
(phase) => void / (error: VoiceError) => void
Follow the session: idle, starting, listening, thinking, speaking, error. Errors carry a kind.
session
VoiceSession
A session from useVoiceSession, to start or stop it from elsewhere (a keyboard shortcut, a menu).
size / colors / label= 200 / chart-1, chart-3, chart-2 / "Voice assistant"
number / [string, string, string] / string
The orb: diameter in px, three ink colours low notes to high (theme variables work; if the theme only has greys it uses blue, teal and coral of its own), its name for screen readers.
labels
Partial<VoiceTalkLabels>
Every word on the button and in the errors, for your copy or language.
VoiceOrb
{ state, getLevel, getSpectrum, level, size, colors }
The orb alone, for a UI of your own: drive it with useVoiceSession or useVoiceAudio(stream | element).

Accessibility and motion

  • The talk button is a real button whose name is what it does next; End appears beside it during a session; a polite status region announces listening, thinking, speaking and errors, never the sound. The orb is role="img", named with its state.
  • Browsers only open the microphone and play audio after a press, so start() runs inside the click; the reply player is unlocked there too, which Safari needs.
  • Microphones it opens are closed after each turn so the recording light goes off; a stream you pass through getMicrophone stays yours.
  • Reply URLs play as they stream in; Web Audio can only meter them if they are same-origin or sent with CORS.
  • The fluid runs on WebGL 2 with half-float textures (a 128 grid for the water, up to 384 for the ink), only on screen in a visible tab. Without WebGL 2, a CSS picture in the same colours stands in.
  • The page must be allowed to use the microphone: https, and a Permissions-Policy that permits it on that page.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

The CLI also installs Text morph.

Source

"use client";import * as React from "react";import { createSpring, useInteractionActivity, useInteractionReducedMotion, type Spring } from "./ui-interaction-motion";import { BANDS, createAudioMeter, elementSource, type AudioMeter } from "./voice-audio";import { createFluidOrb, resolveColors, waterCss, type Emitter, type FluidOrb, type Rgb, type Water } from "./voice-orb-gl";/* ───────────────────────────────────────────────────────── * VOICE ORB: ink in water that the voice moves * * A real fluid runs inside a round vessel, and each state is a way * of moving it, so the orb shows which way the sound is going: *   listening  sound comes in: the voice's frequency bands push *              ink in from the rim, low notes in the first colour, *              high notes in the last *   speaking   sound goes out: each syllable blooms ink outward *              from the centre, band by band *   thinking   no sound: a slow vortex stirs the ink and folds the *              colours into each other *   idle       the ink drifts, barely moving; a finger or a cursor *              stirs it * * The states are spring weights, so they blend: speech fading into * thought hands the ink from one motion to the next. Loudness and * bands are read once a frame from functions, never through React * state. Off screen or in a hidden tab it stops. * * Reduced motion: one still, settled picture per state. * ───────────────────────────────────────────────────────── */export type VoiceOrbState = "idle" | "listening" | "thinking" | "speaking";export interface VoiceOrbProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {  state?: VoiceOrbState;  /** Read every frame, 0 to 1: the microphone while listening, the voice while speaking. useVoiceAudio makes one. */  getLevel?: () => number;  /** Read every frame: loudness per frequency band, 0 to 1, low to high (eight is plenty). useVoiceAudio makes one. */  getSpectrum?: () => ArrayLike<number>;  /** The loudness as a prop instead; getLevel wins when both are given. */  level?: number;  /** Diameter in px. */  size?: number;  /** Three CSS colours for the ink, low notes to high. Theme variables welcome. */  colors?: [string, string, string];  /** What it's called for screen readers; the state is added to it. */  label?: string;}const COLORS: [string, string, string] = ["var(--chart-1, var(--primary))", "var(--chart-3, var(--primary))", "var(--chart-2, var(--primary))"];/** Inks for themes without colour of their own: blue, teal and coral. */const INKS: Rgb[] = [  [0.23, 0.42, 0.95],  [0.08, 0.66, 0.6],  [0.96, 0.46, 0.38],];const SAY: Record<VoiceOrbState, string> = { idle: "ready", listening: "listening", thinking: "thinking", speaking: "speaking" };const SILENT = new Float32Array(BANDS);const TAU = Math.PI * 2;// How each state moves the water: accelerations in grid cells per second², and ink poured per second.const PULL_IN = 1450;const PUSH_OUT = 1750;const DRIFT = 45;const INK_IN = 7;const INK_OUT = 7;const MOOD = { stiffness: 60, damping: 15 };const LEVEL = { stiffness: 320, damping: 30 };const clamp01 = (n: number) => (Number.isFinite(n) ? Math.max(0, Math.min(1, n)) : 0);const mixRgb = (a: Rgb, b: Rgb, t: number): Rgb => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];/** Low notes in the first colour, through the second, high notes in the third. */const bandColor = (palette: Rgb[], b: number) => {  const t = (b / (BANDS - 1)) * 2;  return t <= 1 ? mixRgb(palette[0], palette[1], t) : mixRgb(palette[1], palette[2], t - 1);};/** Where the three pools of dilute ink sit in the water (the vessel's box, y down): low notes top left, high notes below. */const POOLS: [number, number][] = [  [0.32, 0.36],  [0.68, 0.4],  [0.5, 0.72],];/** The water's look: the pools turned by phase (they drift a full turn in about a minute), deeper in the dark. */function waterLook(dark: boolean, phase: number): Omit<Water, "inks"> {  const c = Math.cos(phase), s = Math.sin(phase);  return {    pools: POOLS.map(([x, y]): [number, number] => [0.5 + (x - 0.5) * c - (y - 0.5) * s, 0.5 + (x - 0.5) * s + (y - 0.5) * c]),    poolAlpha: dark ? 0.36 : 0.3,    poolRadius: 0.46,    base: dark ? [0.09, 0.2] : [0.07, 0.16],    line: dark ? 0.4 : 0.32,  };}/** The inks and whether the page is dark, read from the theme. A theme whose chart colours are greys (shadcn's default) * would pour grey ink, so then the orb uses inks of its own. */function readTheme(host: HTMLElement, colorKey: string) {  const [r1, r2, r3, bg] = resolveColors(host, [...colorKey.split("|"), "var(--background, #fff)"]);  const chroma = (c: Rgb) => Math.max(...c) - Math.min(...c);  const inks = [r1, r2, r3].some((c) => chroma(c) > 0.12) ? [r1, r2, r3] : INKS;  return { inks, dark: 0.2126 * bg[0] + 0.7152 * bg[1] + 0.0722 * bg[2] < 0.45 };}const rgbCss = (c: Rgb) => `rgb(${Math.round(c[0] * 255)} ${Math.round(c[1] * 255)} ${Math.round(c[2] * 255)})`;type Weights = { listen: number; speak: number; think: number };const WEIGHTS: Record<VoiceOrbState, Weights> = {  idle: { listen: 0, speak: 0, think: 0 },  listening: { listen: 1, speak: 0, think: 0 },  thinking: { listen: 0, speak: 0, think: 1 },  speaking: { listen: 0, speak: 1, think: 0 },};interface Clock {  time: number;  turn: number;  stir: number;}/** Everything a state does to the water this frame. Pure: the same inputs make the same emitters. */function emittersFor(w: Weights, bands: ArrayLike<number>, palette: Rgb[], clock: Clock, dt: number): Emitter[] {  const out: Emitter[] = [];  const idle = Math.max(0, 1 - w.listen - w.speak - w.think);  for (let b = 0; b < BANDS; b++) {    const e = clamp01(bands[b] ?? 0);    const color = bandColor(palette, b);    if (w.listen > 0.02 && e > 0.03) {      const a = clock.turn + (b * TAU) / BANDS;      const c = Math.cos(a), s = Math.sin(a);      const k = e * w.listen;      out.push({ x: 0.5 + 0.43 * c, y: 0.5 + 0.43 * s, radius: 0.038, fx: -c * PULL_IN * k * dt, fy: -s * PULL_IN * k * dt, color, amount: k * INK_IN * dt });    }    if (w.speak > 0.02 && e > 0.03) {      // Each band blooms out on two opposite sides, so the voice opens the ink evenly instead of shooting one plume.      const a = -clock.turn * 1.3 + (b * Math.PI) / BANDS + (b % 2) * Math.PI + 0.4;      const c = Math.cos(a), s = Math.sin(a);      const k = e * w.speak;      out.push({ x: 0.5 + 0.04 * c, y: 0.5 + 0.04 * s, radius: 0.036, fx: c * PUSH_OUT * k * dt, fy: s * PUSH_OUT * k * dt, color, amount: k * INK_OUT * dt });    }  }  // Thinking and idle feed the body from two points circling near the middle; the turning water winds it into arms.  const feed = 0.9 * w.think;  if (feed > 0.02) {    for (let k = 0; k < 2; k++) {      const a = clock.stir + k * Math.PI;      out.push({ x: 0.5 + 0.12 * Math.cos(a), y: 0.5 + 0.12 * Math.sin(a), radius: 0.026, color: palette[k], amount: feed * 2.2 * dt });    }  }  if (idle > 0.02) {    const t = clock.time;    const x = 0.5 + 0.2 * Math.cos(t * 0.23), y = 0.5 + 0.2 * Math.sin(t * 0.17 + 1);    const a = Math.atan2(y - 0.5, x - 0.5) + Math.PI / 2;    out.push({ x, y, radius: 0.09, fx: Math.cos(a) * DRIFT * idle * dt, fy: Math.sin(a) * DRIFT * idle * dt });  }  return out;}/** How the water itself behaves in a blend of states: eddies, how fast motion and ink fade, and the turn. */function waterFor(w: Weights) {  const idle = Math.max(0, 1 - w.listen - w.speak - w.think);  const voice = w.listen + w.speak;  return {    curl: 2 * idle + 1.2 * w.think + 6 * voice,    velocityFade: 0.9 * idle + 0.7 * w.think + 0.8 * voice,    inkFade: 0.1 * idle + 0.22 * w.think + 0.34 * voice,    rimFade: 0.35 * idle + 0.25 * w.think + 0.05 * w.listen + 0.12 * w.speak,    swirl: 0.08 * idle + 0.6 * w.think + 0.05 * w.listen - 0.04 * w.speak,  };}/** Bands from loudness alone, for sources that only give a level: speech-like, never all bands in step. */function bandsFromLevel(level: number, time: number, out: Float32Array) {  for (let b = 0; b < BANDS; b++) out[b] = clamp01(level * (0.55 + 0.45 * Math.sin(time * 5.3 + b * 1.9 + Math.sin(time * 1.3 + b * 0.7) * 2)));  return out;}/** The first drops: three small ones, wound into wisps before the first frame, so it never starts empty. */function seedFor(palette: Rgb[]): Emitter[] {  return [    { x: 0.44, y: 0.56, radius: 0.045, color: palette[0], amount: 1.4 },    { x: 0.58, y: 0.47, radius: 0.04, color: palette[1], amount: 1.2 },    { x: 0.46, y: 0.41, radius: 0.03, color: palette[2], amount: 0.8 },  ];}export function VoiceOrb({ state = "idle", getLevel, getSpectrum, level, size = 160, colors = COLORS, label = "Voice assistant", className = "", style, ...props }: VoiceOrbProps) {  const reduced = useInteractionReducedMotion();  const { ref: activityRef, active } = useInteractionActivity<HTMLDivElement>();  const canvas = React.useRef<HTMLCanvasElement>(null);  const fallback = React.useRef<HTMLSpanElement>(null);  const [failed, setFailed] = React.useState(false);  const colorKey = colors.join("|");  const input = React.useRef({ state, getLevel, getSpectrum, level });  React.useLayoutEffect(() => {    input.current = { state, getLevel, getSpectrum, level };  });  const engine = React.useRef<{    fluid: FluidOrb;    palette: Rgb[];    dark: boolean;    /** Seconds the water has been shown; the pools drift with it. */    waterTime: number;    springs: { listen: Spring; speak: Spring; think: Spring; level: Spring };    clock: Clock;    bands: Float32Array;    stirs: Emitter[];    /** True while the first ink is being folded, a few steps a frame; the loop waits for it. */    pouring: boolean;    frame: (dt: number) => void;    settle: (target: Weights) => void;  } | null>(null);  // The fluid lives as long as the canvas; its size is fixed when it starts.  React.useEffect(() => {    const el = canvas.current;    if (!el) return;    const dpr = Math.min(2, window.devicePixelRatio || 1);    el.width = Math.round(size * dpr);    el.height = Math.round(size * dpr);    let fluid: FluidOrb | null = null;    try {      fluid = createFluidOrb(el);    } catch {      fluid = null;    }    if (!fluid) {      const frame = requestAnimationFrame(() => setFailed(true));      return () => cancelAnimationFrame(frame);    }    const f = fluid;    const start = WEIGHTS[input.current.state];    const quiet = () => {};    const springs = {      listen: createSpring(start.listen, MOOD, quiet, 0.002),      speak: createSpring(start.speak, MOOD, quiet, 0.002),      think: createSpring(start.think, MOOD, quiet, 0.002),      level: createSpring(0, LEVEL, quiet, 0.002),    };    const clock: Clock = { time: 0, turn: 0, stir: 0 };    const bands = new Float32Array(BANDS);    const e: NonNullable<typeof engine.current> = {      fluid: f,      palette: [[0.19, 0.36, 0.87], [0.11, 0.69, 0.48], [0.91, 0.45, 0.23]],      dark: false,      waterTime: 0,      springs,      clock,      bands,      stirs: [],      pouring: false,      frame(dt) {        if (e.pouring) return;        const { state: s, getLevel: read, getSpectrum: spectrum, level: given } = input.current;        const moving = s === "listening" || s === "speaking";        const raw = moving ? clamp01(read ? read() : (given ?? 0)) : 0;        springs.level.set(raw);        const lv = Math.max(0, springs.level.get());        if (moving && spectrum) {          const got = spectrum();          for (let b = 0; b < BANDS; b++) bands[b] = clamp01(got[Math.floor((b * got.length) / BANDS)] ?? 0);        } else bandsFromLevel(lv, clock.time, bands);        const w = { listen: Math.max(0, springs.listen.get()), speak: Math.max(0, springs.speak.get()), think: Math.max(0, springs.think.get()) };        clock.time += dt;        clock.turn += dt * (0.22 + 0.5 * w.think);        clock.stir += dt * 1.5;        const emitters = emittersFor(w, bands, e.palette, clock, dt);        if (e.stirs.length) emitters.push(...e.stirs.splice(0));        f.step({ dt, emitters, ...waterFor(w) });        e.waterTime += dt;        f.draw({ radius: 0.455 + 0.025 * lv * (w.listen + w.speak) - 0.012 * w.think, water: { inks: e.palette, ...waterLook(e.dark, e.waterTime * 0.1) }, dark: e.dark });      },      settle(target) {        if (e.pouring) return;        // A still picture of a state: run it for a moment at speech-like loudness, then hold.        const w = target;        bandsFromLevel(0.55, clock.time, bands);        for (let i = 0; i < 50; i++) {          clock.time += 1 / 30;          clock.turn += (1 / 30) * 0.3;          clock.stir += (1 / 30) * 1.5;          f.step({ dt: 1 / 30, emitters: emittersFor(w, bands, e.palette, clock, 1 / 30), ...waterFor(w) });        }        f.draw({ radius: 0.455, water: { inks: e.palette, ...waterLook(e.dark, e.waterTime * 0.1) }, dark: e.dark });      },    };    engine.current = e;    const lost = (event: Event) => {      event.preventDefault();      setFailed(true);    };    el.addEventListener("webglcontextlost", lost);    return () => {      el.removeEventListener("webglcontextlost", lost);      Object.values(springs).forEach((s) => s.stop());      f.dispose();      engine.current = null;    };  }, [size]);  // The stand-in is the same water the fluid starts in, in CSS, so handing over to the fluid changes nothing but the ink.  // It is painted with the resolved theme before the first paint (the markup's own picture only shows before hydration).  const paintStandIn = React.useCallback((theme: { inks: Rgb[]; dark: boolean }) => {    const el = fallback.current;    if (!el) return;    const css = waterCss(waterLook(theme.dark, 0), theme.inks.map(rgbCss));    el.style.background = css.background;    el.style.boxShadow = css.boxShadow;  }, []);  React.useLayoutEffect(() => {    const el = fallback.current;    if (el) paintStandIn(readTheme(el.parentElement ?? document.body, colorKey));  }, [colorKey, paintStandIn]);  // Colours from the theme, again whenever the theme changes. The first time, the ink is poured and settled before it shows.  const poured = React.useRef(false);  React.useEffect(() => {    const el = canvas.current;    if (!el || failed) return;    poured.current = false;    let pour = 0;    const apply = () => {      const e = engine.current;      if (!e) return;      const theme = readTheme(el.parentElement ?? document.body, colorKey);      e.palette = theme.inks;      e.dark = theme.dark;      paintStandIn(theme);      const reveal = () => {        // A true crossfade: both show the same water, so fading one in as the other fades out keeps the water still and        // only the ink appears. (The stand-in's slow fade is only for a WebGL failure.)        const standIn = fallback.current;        if (!standIn) return;        el.style.transition = standIn.style.transition = "opacity 240ms linear";        el.style.opacity = "1";        standIn.style.opacity = "0";      };      if (poured.current) {        e.frame(0.0001);        return reveal();      }      poured.current = true;      // Pour, then fold it with a stir before it shows, so it starts as ink that has been moving. It waits for the shaders      // to finish compiling in the background, then folds a few steps a frame behind the stand-in, never as one long task.      const fold = { listen: 0, speak: 0, think: 1 };      const stir = (steps: number) => {        for (let i = 0; i < steps; i++) {          e.clock.time += 1 / 30;          e.clock.stir += (1 / 30) * 1.5;          e.fluid.step({ dt: 1 / 30, emitters: emittersFor(fold, e.bands, e.palette, e.clock, 1 / 30), ...waterFor(fold) });        }      };      const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;      e.pouring = true;      let left = -1;      const chunk = () => {        if (engine.current !== e) return;        try {          if (!e.fluid.ready()) {            pour = requestAnimationFrame(chunk);            return;          }        } catch {          setFailed(true);          return;        }        if (left < 0) {          e.fluid.seed(seedFor(e.palette));          left = 54;        }        const n = still ? left : Math.min(6, left);        stir(n);        left -= n;        if (left > 0) {          pour = requestAnimationFrame(chunk);          return;        }        e.pouring = false;        if (still) e.settle(WEIGHTS[input.current.state]);        else e.frame(1 / 60);        reveal();      };      pour = requestAnimationFrame(chunk);    };    apply();    // Only a theme switch matters (a class or data-theme on <html>); other attribute writes are ignored.    const root = document.documentElement;    let theme = `${root.className}|${root.dataset.theme ?? ""}`;    const watch = new MutationObserver(() => {      const next = `${root.className}|${root.dataset.theme ?? ""}`;      if (next === theme) return;      theme = next;      apply();    });    watch.observe(root, { attributes: true, attributeFilter: ["class", "data-theme"] });    return () => {      watch.disconnect();      cancelAnimationFrame(pour);      if (engine.current) engine.current.pouring = false;    };  }, [colorKey, failed, size, paintStandIn]);  // A state change re-aims the weights from wherever they are; under reduced motion it settles a still of the new state.  React.useEffect(() => {    const e = engine.current;    if (!e) return;    const w = WEIGHTS[state];    if (reduced) {      e.springs.listen.jump(w.listen);      e.springs.speak.jump(w.speak);      e.springs.think.jump(w.think);      e.settle(w);      return;    }    e.springs.listen.set(w.listen);    e.springs.speak.set(w.speak);    e.springs.think.set(w.think);  }, [state, reduced]);  // The loop: only while on screen and the tab is visible, never under reduced motion.  React.useEffect(() => {    if (!active || reduced || failed) return;    let frame = 0;    let last = 0;    const tick = (now: number) => {      const dt = last ? Math.min(1 / 30, (now - last) / 1000) : 1 / 60;      last = now;      engine.current?.frame(dt);      frame = requestAnimationFrame(tick);    };    frame = requestAnimationFrame(tick);    return () => cancelAnimationFrame(frame);  }, [active, reduced, failed]);  // A finger or a cursor stirs the water: no ink, just a push along the way it moved.  const lastPoint = React.useRef<{ x: number; y: number } | null>(null);  const stir = (event: React.PointerEvent<HTMLDivElement>) => {    const e = engine.current;    if (!e || reduced) return;    const box = event.currentTarget.getBoundingClientRect();    const x = (event.clientX - box.left) / box.width;    const y = 1 - (event.clientY - box.top) / box.height;    const prev = lastPoint.current;    lastPoint.current = { x, y };    if (!prev || Math.hypot(x - 0.5, y - 0.5) > 0.46) return;    const dx = x - prev.x, dy = y - prev.y;    if (Math.abs(dx) + Math.abs(dy) < 0.002) return;    e.stirs.push({ x, y, radius: 0.06, fx: Math.max(-120, Math.min(120, dx * 4000)), fy: Math.max(-120, Math.min(120, dy * 4000)) });  };  return (    <div      ref={activityRef}      role="img"      aria-label={`${label}, ${SAY[state]}`}      {...props}      onPointerMove={(event) => {        props.onPointerMove?.(event);        stir(event);      }}      onPointerLeave={(event) => {        props.onPointerLeave?.(event);        lastPoint.current = null;      }}      className={`relative inline-grid shrink-0 place-items-center ${className}`}      style={{ width: size, height: size, ...style }}    >      {/* First paint, and the whole orb where WebGL 2 isn't available: the fluid's water, without the moving ink. */}      <span        ref={fallback}        aria-hidden="true"        className="absolute rounded-full transition-[opacity,scale] duration-700 ease-[cubic-bezier(0.16,1,0.3,1)]"        style={{          width: "91%",          height: "91%",          opacity: 1,          // The vessel's size in the state it opens in, so the hand-over to the fluid has one edge.          scale: state === "thinking" ? 0.443 / 0.455 : 1,          ["--orb-d" as string]: `${size * 0.91}px`,          ...waterCss(waterLook(false, 0), colors),        }}      />      <canvas ref={canvas} aria-hidden="true" className="absolute inset-0 size-full" style={{ display: failed ? "none" : undefined, opacity: 0 }} />      <span role="status" className="sr-only">        {SAY[state]}      </span>    </div>  );}/* ───────────────────────────────────────────────────────── * useVoiceAudio: what the orb reads from a real source * *   MediaStream        a microphone from getUserMedia, or a *                      remote track from WebRTC *   HTMLMediaElement   an <audio> playing the assistant's voice * * Returns { getLevel, getSpectrum }: functions that read the sound * right now, so the orb can call them every frame without * re-rendering anything. Spread them onto the orb. * ───────────────────────────────────────────────────────── */export function useVoiceAudio(source: MediaStream | HTMLMediaElement | null | undefined) {  const meter = React.useRef<AudioMeter | null>(null);  React.useEffect(() => {    if (!source) return;    let context: AudioContext;    let node: AudioNode;    let own = false;    if (source instanceof HTMLMediaElement) {      ({ context, node } = elementSource(source));    } else {      context = new AudioContext();      node = context.createMediaStreamSource(source);      own = true;    }    meter.current = createAudioMeter(context, node);    const resume = () => void context.resume().catch(() => {});    resume();    window.addEventListener("pointerdown", resume, { once: true });    return () => {      window.removeEventListener("pointerdown", resume);      meter.current?.disconnect();      meter.current = null;      if (own) void context.close().catch(() => {});    };  }, [source]);  return React.useMemo(    () => ({      getLevel: () => meter.current?.getLevel() ?? 0,      getSpectrum: (): ArrayLike<number> => meter.current?.getSpectrum() ?? SILENT,    }),    [],  );}export default VoiceOrb;

Registry item: /r/voice-orb.json