Voice Orb
An animated gradient orb for voice agents that reacts to state and audio level.
Code
components/thinking-ui/voice-orb.tsx
"use client";
import { motion, useMotionValue, useSpring, useTransform } from "motion/react";
import { useEffect, useRef } from "react";
import { useMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";
import { useShader } from "@/lib/webgl";
export type VoiceOrbState = "idle" | "listening" | "thinking" | "speaking";
export type VoiceOrbProps = {
state?: VoiceOrbState;
/** Live audio level from 0 to 1. Omit it to use a simulated level. */
level?: number;
/** Diameter in px, or any CSS length such as "100%". */
size?: number | string;
className?: string;
};
// How fast the liquid surface flows, per state
const flow: Record<VoiceOrbState, number> = {
idle: 0.25,
listening: 0.6,
thinking: 1.6,
speaking: 0.9,
};
/* A dark liquid-metal sphere: a warped noise field on the surface,
silver reflections along its ridges, a fresnel rim and one soft
key light. Colors come from the --orb-* tokens. */
const FRAGMENT = `
precision highp float;
varying vec2 vUv;
uniform float uFlow;
uniform float uLevel;
uniform vec2 uResolution;
uniform vec3 uDark;
uniform vec3 uMid;
uniform vec3 uLight;
float hash(vec3 p) {
p = fract(p * 0.3183099 + 0.1);
p *= 17.0;
return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
}
float noise(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(mix(hash(i), hash(i + vec3(1, 0, 0)), f.x), mix(hash(i + vec3(0, 1, 0)), hash(i + vec3(1, 1, 0)), f.x), f.y),
mix(mix(hash(i + vec3(0, 0, 1)), hash(i + vec3(1, 0, 1)), f.x), mix(hash(i + vec3(0, 1, 1)), hash(i + vec3(1, 1, 1)), f.x), f.y), f.z);
}
float fbm(vec3 p) {
float v = 0.0;
float a = 0.5;
for (int i = 0; i < 4; i++) {
v += a * noise(p);
p = p * 2.03 + vec3(1.7, 9.2, 3.4);
a *= 0.5;
}
return v;
}
void main() {
vec2 p = vUv * 2.0 - 1.0;
float r = length(p);
// Two device pixels of edge softening at any size
float alpha = smoothstep(1.0, 1.0 - 4.0 / uResolution.x, r);
if (alpha <= 0.0) { gl_FragColor = vec4(0.0); return; }
vec3 n = vec3(p, sqrt(max(0.0, 1.0 - r * r)));
// Flowing surface: low-frequency warp, louder audio bends it harder
vec3 q = n * 0.9 + vec3(0.0, 0.0, uFlow * 0.3);
vec3 warp = vec3(fbm(q + uFlow * 0.15), fbm(q + 4.3), fbm(q - uFlow * 0.12));
float field = fbm(q + warp * (0.9 + uLevel * 1.8));
// Two thin silver ribbons that slide over the surface
float bands = 0.5 + 0.5 * sin(field * 9.0 + uFlow * 0.6);
float ribbon = pow(bands, 18.0) + 0.45 * pow(0.5 + 0.5 * sin(field * 5.0 - uFlow * 0.4 + 2.0), 30.0);
vec3 L = normalize(vec3(-0.45, 0.6, 0.65));
float diffuse = max(dot(n, L), 0.0);
float key = pow(diffuse, 40.0);
float fresnel = pow(1.0 - n.z, 3.0);
// Mostly glossy black, lifted toward graphite where it faces the light
vec3 col = mix(uDark * 0.45, uMid, smoothstep(0.3, 1.0, diffuse) * (0.25 + 0.3 * field));
col = mix(col, uLight, clamp(ribbon * (0.55 + uLevel * 0.45) * (0.4 + 0.6 * diffuse), 0.0, 1.0));
col += uLight * (fresnel * 0.35 + key * 0.55);
gl_FragColor = vec4(col * alpha, alpha);
}
`;
export function VoiceOrb({ state = "idle", level, size = 120, className }: VoiceOrbProps) {
const m = useMotion();
const rawLevel = useMotionValue(0);
const flowTime = useRef(7);
const clock = useRef(0);
const speed = useRef(flow[state]);
const reduce = m.reduce;
// The personality's emphasis spring decides how organic the pulse feels
const { visualDuration, bounce } = m.personality.spring.emphasis;
const smoothLevel = useSpring(rawLevel, { visualDuration: visualDuration * 0.5, bounce });
const orbScale = useTransform(smoothLevel, [0, 1], [1, 1.08]);
const haloOpacity = useTransform(smoothLevel, [0, 1], [0.12, 0.4]);
const { ref, ready, invalidate } = useShader({
fragment: FRAGMENT,
transparent: true,
colors: { uDark: "--orb-1", uMid: "--orb-2", uLight: "--orb-3" },
uniforms: ({ delta }) => {
if (!reduce) {
const dt = delta / m.scale;
clock.current += dt;
// Ease toward the target flow speed so state changes never jump
speed.current += (flow[state] - speed.current) * Math.min(1, dt * 2.5);
flowTime.current += speed.current * dt;
const ms = clock.current * 1000;
const wobble = Math.abs(Math.sin(ms / 140) * Math.sin(ms / 53 + 1));
const breathing = 0.08 * (0.5 + 0.5 * Math.sin(ms / 900));
rawLevel.set(level ?? (state === "speaking" ? 0.2 + 0.8 * wobble : state === "listening" ? 0.1 + 0.35 * wobble : breathing));
}
return { uFlow: flowTime.current, uLevel: reduce ? 0.15 : smoothLevel.get() };
},
animate: () => !reduce,
});
// Repaint the still frame (reduced motion) or restart the loop when inputs change
useEffect(() => invalidate(), [reduce, state, level, invalidate]);
return (
<div
role="img"
aria-label={`Voice assistant ${state}`}
className={cn("relative shrink-0", className)}
style={{ width: size, height: size }}
>
{/* Soft halo that brightens with the voice */}
<motion.div
aria-hidden
className="absolute -inset-[22%] rounded-full blur-2xl"
style={{ opacity: haloOpacity, background: "radial-gradient(circle, var(--orb-3), transparent 65%)" }}
/>
<motion.div className="absolute inset-0 isolate rounded-full" style={{ scale: orbScale }}>
{/* Static fallback until (or unless) WebGL paints */}
<div
aria-hidden
className={cn("absolute inset-0 rounded-full transition-opacity duration-(--motion-duration-slow)", ready && "opacity-0")}
style={{ background: "radial-gradient(circle at 34% 28%, var(--orb-3), var(--orb-1) 55%, var(--orb-shade) 100%)" }}
/>
<div ref={ref} className="absolute inset-0 rounded-full" />
</motion.div>
</div>
);
}Motion notes
- Spin speed eases between states instead of restarting, so switching states never jumps.
- The audio level runs through a spring, so raw microphone values feel organic instead of jittery.
- Updates happen in an animation-frame loop that writes motion values, with no React re-renders per frame.
- Pass a real level from the Web Audio API, or leave it out to use the built-in simulation.
Installation
- 1
Install dependencies
Terminalnpm install motion clsx tailwind-merge - 2
Add the design tokens and motion system (once per project)
Copy
styles/tokens/*,lib/motion.tsxandlib/utils.ts, pluslib/webgl.tsfrom Get started. - 3
Paste the source into components/thinking-ui/voice-orb.tsx
Copy it from the Code tab, or use Copy prompt to let your coding agent do all of this.
Usage
Example
<VoiceOrb state="speaking" level={audioLevel} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| state | "idle" | "listening" | "thinking" | "speaking" | "idle" | Assistant state. |
| level | number | — | Audio level 0–1. Leave it out to simulate. |
| size | number | 120 | Diameter in px. |