# Voice Orb

> Show whose turn it is in a voice conversation, with a round mark that listens, thinks, and speaks.

Source: https://www.honestui.com/docs/ai/voice-orb

```tsx
"use client"

import * as React from "react"

import { Button } from "@/components/honest-ui/ui/button"
import { VoiceOrb, type VoiceOrbState } from "@/components/ai/voice-orb"

const states: { value: VoiceOrbState; label: string }[] = [
  { value: "idle", label: "Idle" },
  { value: "listening", label: "Listening" },
  { value: "thinking", label: "Thinking" },
  { value: "speaking", label: "Speaking" },
]

// A made-up voice: syllables inside phrases, with pauses between them.
function sampleVoice(seconds: number, pace: number) {
  const syllable = Math.max(0, Math.sin(seconds * 9.1 * pace)) ** 0.7
  const phrase = Math.max(0, Math.sin(seconds * 1.15 * pace) + 0.3)
  return Math.min(1, syllable * phrase * 0.8)
}

/**
 * No microphone or model is involved. The levels are made up, so the orb has
 * something to listen to and something to say.
 */
export function VoiceOrbDemo() {
  const [state, setState] = React.useState<VoiceOrbState>("listening")
  const inputLevel = React.useCallback(() => sampleVoice(performance.now() / 1000, 1), [])
  const outputLevel = React.useCallback(() => sampleVoice(performance.now() / 1000 + 3, 1.25), [])

  return (
    <div className="flex w-full max-w-[22rem] flex-col items-center gap-[var(--hui-space-6)]">
      <VoiceOrb state={state} inputLevel={inputLevel} outputLevel={outputLevel} size={136} />
      <div role="group" aria-label="Orb state" className="flex flex-wrap justify-center gap-[var(--hui-space-2)]">
        {states.map((option) => (
          <Button
            key={option.value}
            size="sm"
            variant={state === option.value ? "secondary" : "ghost"}
            aria-pressed={state === option.value}
            onClick={() => setState(option.value)}
          >
            {option.label}
          </Button>
        ))}
      </div>
    </div>
  )
}

```

## Overview [#overview]

In a voice conversation there is no text to read while the turn changes hands. Voice Orb gives the person something to watch: it breathes at rest, swells with their voice while it listens, turns while the assistant thinks, and ripples with the reply while it speaks.

It shows state; it does not decide it. `state` comes from your voice pipeline, and `inputLevel` and `outputLevel` are loudness figures you measure. The orb opens no microphone and plays no audio.

## Anatomy [#anatomy]

<Anatomy title="VoiceOrb">
  <AnatomyItem name="Canvas" description="The body, its halo, and the thinking arc, drawn each frame" />

  <AnatomyItem name="Glyph" description="A still disc with a mark for each state, shown in place of the canvas with reduced motion" />

  <AnatomyItem name="Status" description="The state as text, for assistive technology" />
</Anatomy>

`VoiceOrb` is one component. It installs `motion`, which it uses to read the reduced motion setting.

## Behavior [#behavior]

### States [#states]

| State       | What it shows                        | Level it follows |
| ----------- | ------------------------------------ | ---------------- |
| `idle`      | A slow breath                        | None             |
| `listening` | A swell and a rippling edge          | `inputLevel`     |
| `thinking`  | An arc travelling around the outside | None             |
| `speaking`  | A livelier ripple                    | `outputLevel`    |

The state is reported as `data-state` on the root. A change of state or a jump in level eases in, so the orb never snaps.

### Levels [#levels]

A level is a number from 0 to 1. Pass a number when it comes from React state, or a function the orb calls once per frame, which avoids re-rendering on every audio frame:

```tsx
<VoiceOrb state="listening" inputLevel={() => meter.current} />
```

Values outside 0 to 1 are clamped.

### Color [#color]

The orb is drawn in the text color, so it is dark on light surfaces and light on dark ones. Pass `accent` with any CSS color to tint it; the color is read at draw time, so tokens such as `var(--hui-color-foreground-accent-primary)` follow the theme.

## Accessibility [#accessibility]

The canvas and glyph are hidden from assistive technology. A visually hidden status reads the state, such as "Listening", and is announced when it changes. If text nearby already says the state, set `announce` to `false` so it is not read twice.

The orb is not interactive. Put your microphone and stop controls next to it as real buttons.

With reduced motion, the orb does not animate: it shows a still glyph for the state, a dot, a microphone, three dots, or bars.

Every string comes from `labels`.

## Installation [#installation]


  

  
    <CliBlock commands="[&#x22;@honestai/voice-orb&#x22;]" />
  

  
    
      
        Install Motion.
      

      ```bash
      npm install motion
      ```

      
        Copy and paste this file into your project.
      

      ### components/ai/voice-orb.tsx

```tsx
"use client"

import * as React from "react"
import { useReducedMotion } from "motion/react"

import { cn } from "@/lib/utils"

export type VoiceOrbState = "idle" | "listening" | "thinking" | "speaking"

/** A level from 0 to 1, or a function the orb calls once per frame for one. */
export type VoiceOrbLevel = number | (() => number)

export type VoiceOrbLabels = Record<VoiceOrbState, string>

export const defaultVoiceOrbLabels: VoiceOrbLabels = {
  idle: "Voice assistant ready",
  listening: "Listening",
  thinking: "Thinking",
  speaking: "Speaking",
}

export type VoiceOrbProps = Omit<React.ComponentProps<"div">, "children"> & {
  /** What the assistant is doing. The orb only shows it. */
  state?: VoiceOrbState
  /** The person's loudness, from 0 to 1. Moves the orb while `listening`. */
  inputLevel?: VoiceOrbLevel
  /** The assistant's loudness, from 0 to 1. Moves the orb while `speaking`. */
  outputLevel?: VoiceOrbLevel
  /** Diameter in CSS pixels. */
  size?: number
  /** A CSS color for the orb. Defaults to the text color, so it is monochrome. */
  accent?: string
  /** Set false to keep the state out of the accessibility tree, when your own text already says it. */
  announce?: boolean
  labels?: Partial<VoiceOrbLabels>
}

const clamp01 = (value: number) => (Number.isFinite(value) ? Math.min(Math.max(value, 0), 1) : 0)
const readLevel = (level: VoiceOrbLevel | undefined) =>
  clamp01(typeof level === "function" ? level() : (level ?? 0))

const TAU = Math.PI * 2
const LOBES = 96
const HALO_RINGS = 6

/**
 * A round mark for a voice conversation that shows whose turn it is: it
 * breathes at rest, swells with the person's voice while listening, turns
 * while thinking, and ripples with the reply while speaking.
 */
function VoiceOrb({
  state = "idle",
  inputLevel,
  outputLevel,
  size = 96,
  accent,
  announce = true,
  labels: labelsProp,
  className,
  style,
  ...props
}: VoiceOrbProps) {
  const labels = { ...defaultVoiceOrbLabels, ...labelsProp }
  const shouldReduceMotion = useReducedMotion() ?? false
  const canvasRef = React.useRef<HTMLCanvasElement>(null)
  const live = React.useRef({ state, inputLevel, outputLevel })
  React.useLayoutEffect(() => {
    live.current = { state, inputLevel, outputLevel }
  })

  React.useEffect(() => {
    if (shouldReduceMotion) return
    const canvas = canvasRef.current
    const context = canvas?.getContext("2d")
    if (!canvas || !context) return

    const dpr = window.devicePixelRatio || 1
    canvas.width = Math.round(size * dpr)
    canvas.height = Math.round(size * dpr)

    let frame = 0
    let last = performance.now()
    let time = 0
    // Eased values, so a jump in level or a change of state never snaps.
    let energy = 0
    let spin = 0
    let thinking = 0

    const draw = (now: number) => {
      const dt = Math.min((now - last) / 1000, 0.1)
      last = now
      time += dt
      const { state: current, inputLevel: input, outputLevel: output } = live.current
      const target = current === "listening" ? readLevel(input) : current === "speaking" ? readLevel(output) : 0
      energy += (target - energy) * Math.min(1, dt * (target > energy ? 14 : 6))
      thinking += ((current === "thinking" ? 1 : 0) - thinking) * Math.min(1, dt * 4)
      spin += dt * (0.25 + thinking * 1.6)

      const ink = getComputedStyle(canvas).color
      const center = size / 2
      // Room is left around the body for the halo and the swell.
      const base = size * 0.34
      const breath = current === "idle" ? Math.sin(time * 1.6) * 0.015 : 0
      const swell = energy * 0.1

      context.setTransform(dpr, 0, 0, dpr, 0, 0)
      context.clearRect(0, 0, size, size)

      // The body: a circle whose edge ripples with the level.
      const ripple = current === "speaking" ? 0.09 : 0.06
      context.beginPath()
      for (let i = 0; i <= LOBES; i += 1) {
        const a = (i / LOBES) * TAU
        const wobble =
          Math.sin(a * 3 + time * 2.1 + spin) * 0.6 + Math.sin(a * 5 - time * 2.9) * 0.3 + Math.sin(a * 7 + time * 4.3) * 0.1
        const r = base * (1 + breath + swell + wobble * energy * ripple + wobble * 0.008)
        const x = center + Math.cos(a) * r
        const y = center + Math.sin(a) * r
        if (i === 0) context.moveTo(x, y)
        else context.lineTo(x, y)
      }
      context.closePath()
      context.globalAlpha = 0.92
      context.fillStyle = ink
      context.fill()

      // A soft highlight near the top that drifts a little as the orb turns.
      const hx = center - base * 0.3 + Math.cos(spin) * base * 0.12
      const hy = center - base * 0.38 + Math.sin(spin) * base * 0.12
      const shine = context.createRadialGradient(hx, hy, 0, hx, hy, base * 1.1)
      shine.addColorStop(0, "rgba(255,255,255,0.22)")
      shine.addColorStop(1, "rgba(255,255,255,0)")
      context.globalAlpha = 1
      context.globalCompositeOperation = "source-atop"
      context.fillStyle = shine
      context.fillRect(0, 0, size, size)

      // The halo widens with the voice and fades out, drawn behind the body.
      context.globalCompositeOperation = "destination-over"
      const haloRadius = base * (1.3 + energy * 0.25 + breath)
      // Stacked rings rather than a gradient, so any CSS color fades without parsing it.
      context.fillStyle = ink
      context.globalAlpha = (0.16 + energy * 0.14) / HALO_RINGS
      for (let ring = 1; ring <= HALO_RINGS; ring += 1) {
        context.beginPath()
        context.arc(center, center, base + (haloRadius - base) * (ring / HALO_RINGS), 0, TAU)
        context.fill()
      }
      context.globalCompositeOperation = "source-over"

      // While thinking, an arc travels around the outside.
      if (thinking > 0.01) {
        context.globalAlpha = thinking * 0.9
        context.strokeStyle = ink
        context.lineWidth = Math.max(1.5, size * 0.022)
        context.lineCap = "round"
        context.beginPath()
        const r = base * 1.32
        const startAngle = spin * 2.2
        context.arc(center, center, r, startAngle, startAngle + Math.PI * (0.35 + 0.25 * Math.sin(time * 2)))
        context.stroke()
      }

      context.globalAlpha = 1
      frame = requestAnimationFrame(draw)
    }

    frame = requestAnimationFrame(draw)
    return () => cancelAnimationFrame(frame)
  }, [size, shouldReduceMotion])

  return (
    <div
      data-slot="voice-orb"
      data-state={state}
      className={cn("relative inline-flex shrink-0 text-[var(--hui-color-foreground-base-primary)]", className)}
      style={{ width: size, height: size, ...(accent ? { color: accent } : null), ...style }}
      {...props}
    >
      {shouldReduceMotion ? (
        <StateGlyph state={state} size={size} />
      ) : (
        <canvas ref={canvasRef} aria-hidden="true" className="block size-full" />
      )}
      {announce ? (
        <span role="status" className="sr-only">
          {labels[state]}
        </span>
      ) : null}
    </div>
  )
}

/** The still picture shown with reduced motion: a disc with a mark for each state. */
function StateGlyph({ state, size }: { state: VoiceOrbState; size: number }) {
  return (
    <svg
      data-slot="voice-orb-glyph"
      aria-hidden="true"
      viewBox="0 0 100 100"
      width={size}
      height={size}
      className="block"
    >
      <circle cx="50" cy="50" r="40" fill="currentColor" opacity="0.1" />
      <circle cx="50" cy="50" r="34" fill="currentColor" />
      <g
        stroke="var(--hui-color-background-base-primary)"
        fill="var(--hui-color-background-base-primary)"
        strokeWidth="4"
        strokeLinecap="round"
      >
        {state === "idle" ? <circle cx="50" cy="50" r="5" stroke="none" /> : null}
        {state === "listening" ? (
          <>
            <rect x="44" y="34" width="12" height="20" rx="6" stroke="none" />
            <path d="M38 50a12 12 0 0 0 24 0M50 62v5" fill="none" />
          </>
        ) : null}
        {state === "thinking" ? (
          <>
            <circle cx="38" cy="50" r="3.5" stroke="none" />
            <circle cx="50" cy="50" r="3.5" stroke="none" />
            <circle cx="62" cy="50" r="3.5" stroke="none" />
          </>
        ) : null}
        {state === "speaking" ? <path d="M36 46v8M43 40v20M50 35v30M57 40v20M64 46v8" fill="none" /> : null}
      </g>
    </svg>
  )
}

export { VoiceOrb }

```

      
        Update the import paths to match your project setup.
      
    
  


## Usage [#usage]

```tsx
import { VoiceOrb } from "@/components/ai/voice-orb"

<VoiceOrb
  state={session.state}
  inputLevel={() => micLevel.current}
  outputLevel={() => replyLevel.current}
/>
```

## Examples [#examples]

### Accent color [#accent-color]

A smaller orb, tinted with the accent color, in a call header whose text already says the state.

```tsx
"use client"

import * as React from "react"

import { VoiceOrb } from "@/components/ai/voice-orb"

function sampleVoice(seconds: number) {
  const syllable = Math.max(0, Math.sin(seconds * 11)) ** 0.7
  const phrase = Math.max(0, Math.sin(seconds * 1.4) + 0.4)
  return Math.min(1, syllable * phrase * 0.8)
}

/** An orb in the accent color, in a call header. The reply's level is made up. */
export function VoiceOrbAccent() {
  const outputLevel = React.useCallback(() => sampleVoice(performance.now() / 1000), [])

  return (
    <div className="flex w-full max-w-[24rem] items-center gap-[var(--hui-space-4)] rounded-[var(--hui-radius-4)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-primary)] p-[var(--hui-space-4)] shadow-[var(--hui-shadow-feather)]">
      <VoiceOrb
        state="speaking"
        outputLevel={outputLevel}
        size={56}
        accent="var(--hui-color-foreground-accent-primary)"
        announce={false}
      />
      <div className="min-w-0 flex-1">
        <p className="m-0 truncate text-[var(--hui-color-foreground-base-primary)] [font-size:var(--hui-font-size-regular)] [font-weight:var(--hui-font-weight-medium)]">
          Support assistant
        </p>
        <p className="m-0 truncate text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)]">
          Speaking · <span className="tabular-nums">2:14</span>
        </p>
      </div>
    </div>
  )
}

```

### With the Audio Orb shader [#with-the-audio-orb-shader]

For a voice agent's main screen, the [Audio Orb](/docs/shaders/audio-orb) shader from Honest UI takes the same `state`, `inputLevel`, and `outputLevel`, and draws a colored glass orb with WebGL. Here it plays through a made-up exchange with a [Live Waveform](/docs/ai/live-waveform) under it and the turn written out, so the state is never shown by the orb alone.

```tsx
"use client"

import * as React from "react"
import { Pause as PauseIcon, Play as PlayIcon } from "honestui/icons"
import { AudioOrb } from "honestui/shaders"

import { Button } from "@/components/honest-ui/ui/button"
import { LiveWaveform } from "@/components/ai/live-waveform"
import type { VoiceOrbState } from "@/components/ai/voice-orb"

type Turn = { state: VoiceOrbState; seconds: number; caption: string }

// One made-up exchange, played in a loop. No microphone or model is involved.
const script: Turn[] = [
  { state: "idle", seconds: 1.6, caption: "Tap to talk, or just start speaking." },
  { state: "listening", seconds: 3.4, caption: "“Can you move my 3 o’clock with Priya to tomorrow?”" },
  { state: "thinking", seconds: 1.8, caption: "Checking both calendars…" },
  { state: "speaking", seconds: 4.2, caption: "“Done. You’re both free at 3:30 tomorrow, so I moved it there.”" },
]

// Syllables inside phrases, with pauses between them.
function sampleVoice(seconds: number, pace: number) {
  const syllable = Math.max(0, Math.sin(seconds * 9.1 * pace)) ** 0.7
  const phrase = Math.max(0, Math.sin(seconds * 1.15 * pace) + 0.3)
  return Math.min(1, syllable * phrase * 0.85)
}

/**
 * The shader orb from Honest UI as the main mark of a voice screen, with the
 * Honest AI waveform under it. Both read the same made-up levels.
 */
export function VoiceOrbShader() {
  const [turn, setTurn] = React.useState(0)
  const [playing, setPlaying] = React.useState(true)
  const current = script[turn]

  React.useEffect(() => {
    if (!playing) return
    const timer = window.setTimeout(() => setTurn((index) => (index + 1) % script.length), current.seconds * 1000)
    return () => window.clearTimeout(timer)
  }, [turn, playing, current.seconds])

  const inputLevel = React.useCallback(() => sampleVoice(performance.now() / 1000, 1), [])
  const outputLevel = React.useCallback(() => sampleVoice(performance.now() / 1000 + 3, 1.25), [])
  const waveformLevel = current.state === "listening" ? inputLevel : current.state === "speaking" ? outputLevel : 0

  return (
    <div className="flex w-full max-w-[24rem] flex-col gap-[var(--hui-space-5)]">
      <div className="flex flex-col items-center gap-[var(--hui-space-4)]">
        <AudioOrb
          state={current.state}
          inputLevel={inputLevel}
          outputLevel={outputLevel}
          size={208}
          paused={!playing}
          announce={false}
        />
        <LiveWaveform
          state={current.state === "thinking" ? "processing" : current.state === "idle" ? "idle" : "active"}
          level={waveformLevel}
          className="h-7 w-40"
          aria-hidden="true"
        />
        <p
          aria-live="polite"
          className="m-0 min-h-[2lh] text-center text-pretty text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-regular)] [line-height:var(--hui-line-height-regular)]"
        >
          {current.caption}
        </p>
      </div>
      <div>
        <Button variant="ghost" size="sm" onClick={() => setPlaying((value) => !value)}>
          {playing ? <PauseIcon aria-hidden="true" /> : <PlayIcon aria-hidden="true" />}
          {playing ? "Pause" : "Play"}
        </Button>
      </div>
    </div>
  )
}

```

## API reference [#api-reference]

### VoiceOrb [#voiceorb]

Accepts native div props beyond those listed.

| Prop          | Type                      | Default    | Description                                        |
| ------------- | ------------------------- | ---------- | -------------------------------------------------- |
| `state`       | `VoiceOrbState`           | `"idle"`   | What the assistant is doing.                       |
| `inputLevel`  | `VoiceOrbLevel`           | `0`        | The person's loudness, followed while listening.   |
| `outputLevel` | `VoiceOrbLevel`           | `0`        | The assistant's loudness, followed while speaking. |
| `size`        | number                    | `96`       | Diameter in CSS pixels.                            |
| `accent`      | string                    | Text color | A CSS color for the orb.                           |
| `announce`    | boolean                   | `true`     | Reads the state in a status region.                |
| `labels`      | `Partial<VoiceOrbLabels>` | English    | The text read for each state.                      |

### Types [#types]

| Export           | Shape                                                  |
| ---------------- | ------------------------------------------------------ |
| `VoiceOrbState`  | `"idle"`, `"listening"`, `"thinking"`, or `"speaking"` |
| `VoiceOrbLevel`  | A number from 0 to 1, or a function that returns one   |
| `VoiceOrbLabels` | One string per state                                   |
