Voice Orb
An audio-reactive orb for voice mode that listens, thinks and speaks — with a control bar, live transcript and a useMicLevel hook.
Preview
Ready
00:00
Installation
- 1
Run the following command
npx shadcn@latest add https://localhostui.com/r/voice-orb.json
Also copy voice-bar.tsx from the same folder.
States
| State | What you see |
|---|---|
idle | Slow breathing (scale 1 → 1.03 over 4s) |
listening | Follows mic volume, smoothed with a 0.15 lerp so it never jitters |
thinking | Shrinks to 0.85, deformation stops, a thin arc orbits |
speaking | Follows output volume with stronger deformation, so you can feel who is talking |
muted | 60% opacity, a mic-off badge pops in |
error | One shake and a destructive tint for 600ms, then idle |
Variants
- blob — a canvas circle deformed by three layered sine waves, drawn at
devicePixelRatiowith a monochrome gradient and soft inner glow. - rings — three concentric rings that scale with volume at different lags.
- bars — five rounded bars in a pill, for compact UIs.
Connecting real audio
Your microphone
const mic = useMicLevel();
<VoiceOrb state="listening" analyser={mic.analyser} />
<button onClick={mic.start}>Start</button>OpenAI Realtime or any WebRTC track
Create an AnalyserNode from the remote audio track and pass it in while the assistant speaks:
pc.ontrack = (e) => {
const ctx = new AudioContext();
const analyser = ctx.createAnalyser();
analyser.fftSize = 512;
ctx.createMediaStreamSource(e.streams[0]).connect(analyser);
setOutputAnalyser(analyser);
};
<VoiceOrb state={speaking ? "speaking" : "listening"} analyser={speaking ? outputAnalyser : mic.analyser} />Any other level source
If you already compute a level (e.g. from an audio worklet), keep it in a ref and use getVolume so React never re-renders per frame:
const level = useRef(0);
<VoiceOrb state="speaking" getVolume={() => level.current} />Performance
- One
requestAnimationFrameloop per orb; all per-frame values live in refs, never React state. - The loop skips work while the orb is off-screen (
IntersectionObserver) or the tab is hidden. - The canvas is sized once per
sizechange and capped at 2× DPR.
Props
VoiceOrb
| Prop | Type | Default | Description |
|---|---|---|---|
state | "idle""listening""thinking""speaking""muted""error" | "idle" | Conversation state. Every change morphs smoothly. |
volume | number | — | External 0..1 level (e.g. the AI's output volume). |
getVolume | () => number | — | Per-frame level getter — read from a ref so nothing re-renders 60×/s. Wins over volume. |
analyser | AnalyserNode | null | — | Web Audio analyser read directly inside the animation loop. Wins over both. |
size | number | 160 | Diameter in px. |
variant | "blob""rings""bars" | "blob" | Canvas blob, concentric rings, or a 5-bar waveform. |
VoiceBar
| Prop | Type | Default | Description |
|---|---|---|---|
state | VoiceState | — | "muted" draws a slash across the mic. |
onMicToggle | () => void | — | Toggle mute. Space does the same while the bar is focused. |
onEnd | () => void | — | End the session. |
elapsed | number | — | Elapsed seconds, shown as mm:ss. |
transcript | string | — | Live transcript; the last two lines are shown. |
permission | "unknown""prompt""granted""denied""unsupported" | "granted" | prompt shows an “Allow microphone” button, denied shows instructions. |
onRequestPermission | () => void | — | Called by the Allow button — usually mic.start(). |
useMicLevel()
| Prop | Type | Default | Description |
|---|---|---|---|
start | () => Promise<void> | — | Ask for the mic and begin measuring. |
stop | () => void | — | Stop tracks and close the AudioContext. |
level | number | — | Smoothed 0..1 level, updated ~15×/s. |
levelRef | RefObject<number> | — | Always-current level for rAF loops. |
analyser | AnalyserNode | null | — | Pass straight to <VoiceOrb analyser>. |
permission | MicPermission | — | Live permission state. |
active | boolean | — | True while the mic stream is open. |
Accessibility
- The orb is decorative (
aria-hidden); a visually hidden status reads “Listening”, “Speaking”… through a live region. Spacetoggles mute when the bar is focused. All controls have labels; mute exposesaria-pressed.- With reduced motion the orb becomes a static circle that only changes opacity with volume.