ComponentsVoice Orb

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. 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

StateWhat you see
idleSlow breathing (scale 1 → 1.03 over 4s)
listeningFollows mic volume, smoothed with a 0.15 lerp so it never jitters
thinkingShrinks to 0.85, deformation stops, a thin arc orbits
speakingFollows output volume with stronger deformation, so you can feel who is talking
muted60% opacity, a mic-off badge pops in
errorOne shake and a destructive tint for 600ms, then idle

Variants

  • blob — a canvas circle deformed by three layered sine waves, drawn at devicePixelRatio with 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 requestAnimationFrame loop 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 size change and capped at 2× DPR.

Props

VoiceOrb

PropTypeDefaultDescription
state
"idle""listening""thinking""speaking""muted""error"
"idle"Conversation state. Every change morphs smoothly.
volumenumber—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.
analyserAnalyserNode | null—Web Audio analyser read directly inside the animation loop. Wins over both.
sizenumber160Diameter in px.
variant
"blob""rings""bars"
"blob"Canvas blob, concentric rings, or a 5-bar waveform.

VoiceBar

PropTypeDefaultDescription
stateVoiceState—"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.
elapsednumber—Elapsed seconds, shown as mm:ss.
transcriptstring—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()

PropTypeDefaultDescription
start() => Promise<void>—Ask for the mic and begin measuring.
stop() => void—Stop tracks and close the AudioContext.
levelnumber—Smoothed 0..1 level, updated ~15×/s.
levelRefRefObject<number>—Always-current level for rAF loops.
analyserAnalyserNode | null—Pass straight to <VoiceOrb analyser>.
permissionMicPermission—Live permission state.
activeboolean—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.
  • Space toggles mute when the bar is focused. All controls have labels; mute exposes aria-pressed.
  • With reduced motion the orb becomes a static circle that only changes opacity with volume.