# Voice indicator

Show caller-supplied voice state and audio level.

## Preview

voice-indicator-preview-1.jsx

```jsx
import * as React from "react";
import { AudioPlayer, useAudioPlayer } from "@/components/ui/audio-player";
import { VoiceIndicator } from "@/components/ui/voice-indicator";

export default function Example() {
  return (
    <section
      aria-label="Sample narration"
      style={{
        width: "min(100%, 440px)",
        marginInline: "auto",
        padding: 16,
      }}
    >
      <AudioPlayer.Root
        src="/audio/the-metal-forest.mp3"
        label="Sample narration"
      >
        <div
          style={{
            display: "grid",
            justifyItems: "center",
            paddingBlockEnd: 16,
          }}
        >
          <PlayerDrivenIndicator />
        </div>
        <AudioPlayer.ControlBar>
          <AudioPlayer.PlayPause />
          <AudioPlayer.Seek />
          <AudioPlayer.Time />
        </AudioPlayer.ControlBar>
      </AudioPlayer.Root>
    </section>
  );
}

function PlayerDrivenIndicator() {
  const player = useAudioPlayer();
  const [audio, setAudio] = React.useState(null);
  const [output, setOutput] = React.useState(0);
  const { src, getMediaElement, status } = player;
  React.useEffect(() => {
    const controller = new AbortController();
    let context;
    setAudio(null);
    async function decode() {
      try {
        const response = await fetch(src, {
          signal: controller.signal,
        });
        if (!response.ok) return;
        const bytes = await response.arrayBuffer();
        if (controller.signal.aborted) return;
        context = new AudioContext();
        const decoded = await context.decodeAudioData(bytes);
        if (!controller.signal.aborted) setAudio(decoded);
      } catch {
      } finally {
        void context?.close().catch(() => {});
      }
    }
    void decode();
    return () => {
      controller.abort();
    };
  }, [src]);
  React.useEffect(() => {
    setOutput(0);
    if (!audio || status !== "playing") return;
    const channels = Array.from(
      {
        length: audio.numberOfChannels,
      },
      (_, index) => audio.getChannelData(index),
    );
    let frame;
    const measure = () => {
      const media = getMediaElement();
      setOutput(
        media && !media.paused && !media.muted
          ? playbackLevel(channels, audio.sampleRate, media.currentTime) *
              media.volume
          : 0,
      );
      frame = requestAnimationFrame(measure);
    };
    measure();
    return () => cancelAnimationFrame(frame);
  }, [audio, status, getMediaElement]);
  const state =
    player.status === "playing"
      ? "speaking"
      : player.status === "loading"
        ? "connecting"
        : player.status === "error"
          ? "error"
          : "idle";
  return (
    <VoiceIndicator
      state={state}
      outputLevel={output}
      size="xl"
      label="Narration playback"
      description={
        player.status === "error"
          ? "The recording could not be loaded."
          : undefined
      }
    />
  );
}

function playbackLevel(channels, sampleRate, seconds) {
  const start = Math.max(0, Math.floor(seconds * sampleRate));
  const length = Math.max(1, Math.floor(sampleRate * 0.02));
  let energy = 0,
    count = 0;
  for (const channel of channels) {
    for (
      let index = start;
      index < Math.min(channel.length, start + length);
      index++
    ) {
      energy += channel[index] ** 2;
      count++;
    }
  }
  return count ? Math.min(1, Math.sqrt(energy / count) * 3) : 0;
}

```

Play the excerpt from Tik-Tok of Oz to see the form follow the audio. The example measures 20ms loudness windows from decoded audio at the player's current position. Louder speech gently expands the orb; silence lets it settle. See the [sample audio credits](/audio/README.txt) for reuse terms. To use this example, replace /audio/the-metal-forest.mp3 with your own audio file.

## Design guidance

Use Voice indicator as a quiet, visible center beside a transcript, playback, or session controls. Light mode uses a broad reflection and a soft blue pool. Dark mode gives the drop a deeper blue body with a quieter edge. Listening stretches toward the input and speaking follows outputLevel with a soft phrase envelope. Error tints the rounded drop a cool red and keeps the Error label visible.

The artwork is decorative. Keep capture, playback, and session controls with the caller. Supply levels only when measurements are available. A pointer press deforms the drop and release inside sends a small ripple. Reduced motion keeps each pose still and takes priority over live audio and pointer effects. A matching SVG appears during graphics startup, offscreen rendering, and when WebGL is unavailable.

**Also known as**

Voice orb.

“Voice orb” describes the visual form. The caller supplies voice state and audio level; the indicator does not capture or recognize speech.

## Installation

```sh
npx shadcn@latest add https://ghost-ui.com/r/voice-indicator.json
```

The source registry installs the component, its styles, and the React Three Fiber and Three.js dependencies. For an npm install, import VoiceIndicator from @collectivecreation/ghost-ui/components/voice-indicator and load @collectivecreation/ghost-ui/styles.css followed by @collectivecreation/ghost-ui/components.css. Install the optional @react-three/fiber and three peers to enable live rendering. The preview also uses AudioPlayer.

## Basic usage

  return (
    <VoiceIndicator
      state="listening"
      inputLevel={inputLevel}
      label="Voice session"
    />
  );
}
Levels are finite normalized values from 0 to 1 and are clamped to that range. A missing or non-finite value is treated as zero. The component does not source measurements or choose a state.

## Structures

VoiceIndicator is the public component. Its state artwork and label are internal slots, not separately imported parts.

The root is a native div with forwarded attributes and HTMLDivElement ref. The art is hidden from assistive technology; state and optional label remain readable, and description is connected with aria-describedby. Caller children render after the state text. Keep actions outside the decorative art so there is no nested or implied audio action.

## Examples

### Voice chat

Keep the transcript beside a smaller orb so people can read while they listen. Start voice replays sample speech events; Stop reply keeps the words already shown. This example does not use a microphone or speech service.

voice-indicator-voice-chat-2.jsx

```jsx
import * as React from "react";
import { Mic, MicOff, PhoneOff, Play, RotateCcw, Square } from "lucide-react";
import { Button, IconButton } from "@/components/ui/button";
import { VoiceIndicator } from "@/components/ui/voice-indicator";
import { MessageSender } from "@/components/ui/message-sender";
import { Transcript } from "@/components/ui/transcript";
import {
  MessageScroller,
  MessageScrollerProvider,
  MessageScrollerViewport,
  MessageScrollerContent,
  MessageScrollerItem,
  MessageScrollerButton,
} from "@/components/ui/message-scroller";

export default function Example() {
  const [time, setTime] = React.useState(0);
  const [running, setRunning] = React.useState(false);
  const [muted, setMuted] = React.useState(false);
  const [ended, setEnded] = React.useState(false);
  const [interruptedAt, setInterruptedAt] = React.useState(null);
  const inputAtMute = React.useRef(0);
  React.useEffect(() => {
    if (!running) return;
    let previous = performance.now();
    const timer = window.setInterval(() => {
      const now = performance.now(),
        delta = Math.min(0.25, (now - previous) / 1000);
      previous = now;
      setTime((value) => Math.min(22, value + delta));
    }, 80);
    return () => window.clearInterval(timer);
  }, [running]);
  React.useEffect(() => {
    if (time >= 22) setRunning(false);
  }, [time]);
  const interrupted = interruptedAt !== null || time >= 15.5;
  const speaking =
    running && time >= 7 && time < 15.5 && interruptedAt === null;
  const phase = !running
    ? "idle"
    : speaking
      ? "speaking"
      : (time >= 5.2 && time < 7) || time >= 19.5
        ? "thinking"
        : muted
          ? "muted"
          : "listening";
  const inputTime = muted ? inputAtMute.current : time;
  const input =
    inputTime < 1.2
      ? ""
      : inputTime < 2.4
        ? "Can you help me"
        : inputTime < 3.6
          ? "Can you help me simplify"
          : inputTime < 5.2
            ? "Can you help me simplify the"
            : "Can you help me simplify the onboarding flow?";
  const draft =
    inputTime >= 1.2 && inputTime < 2.4
      ? " simplify"
      : inputTime >= 2.4 && inputTime < 3.6
        ? " the onboarding"
        : inputTime >= 3.6 && inputTime < 5.2
          ? " onboarding flow?"
          : undefined;
  const spokenTime = Math.min(time, interruptedAt ?? 15.5);
  const count =
    spokenTime < 7
      ? 0
      : Math.min(reply.length, Math.floor((spokenTime - 7) / 0.52) + 1);
  const words = reply.slice(0, count).map((text, index) => ({
    id: `reply-word-${index}`,
    text: `${index ? " " : ""}${text}`,
    start: 7 + index * 0.52,
    end: 7 + (index + 1) * 0.52,
  }));
  const segments = [
    ...(input
      ? [
          {
            id: "user-1",
            speaker: "You",
            start: 1.2,
            text: input,
            draftText: draft,
            status: draft ? "partial" : "final",
          },
        ]
      : []),
    ...(words.length
      ? [
          {
            id: "reply-1",
            speaker: <MessageSender name="Assistant" kind="agent" size="xs" />,
            start: 7,
            text: words.map((word) => word.text).join(""),
            words,
            status: interrupted ? "interrupted" : undefined,
          },
        ]
      : []),
    ...(interrupted && time >= 16
      ? [
          {
            id: "user-2",
            speaker: "You",
            start: 16,
            text: "Keep the preview",
            draftText: time >= 18 ? ", though." : undefined,
            status: "partial",
          },
        ]
      : []),
  ];
  const activeId =
    phase === "listening"
      ? time >= 16
        ? "user-2"
        : "user-1"
      : speaking
        ? "reply-1"
        : undefined;
  const level =
    running && !ended
      ? 0.2 + 0.5 * Math.sin(time * (speaking ? 6.7 : 4.6)) ** 2
      : 0;
  const begin = () => {
    setTime(0);
    setEnded(false);
    setInterruptedAt(null);
    setMuted(false);
    setRunning(true);
  };
  const controls = running ? (
    <>
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label={muted ? "Unmute microphone" : "Mute microphone"}
        aria-pressed={muted}
        icon={muted ? <MicOff /> : <Mic />}
        onClick={() => {
          if (!muted) inputAtMute.current = time;
          setMuted((value) => !value);
        }}
      />
      {speaking && (
        <IconButton
          type="button"
          variant="ghost"
          size="icon"
          aria-label="Stop reply"
          icon={<Square />}
          onClick={() => setInterruptedAt(time)}
        />
      )}
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label="End voice"
        icon={<PhoneOff />}
        onClick={() => {
          setEnded(true);
          setRunning(false);
        }}
      />
    </>
  ) : (
    <Button
      type="button"
      variant="outline"
      size="sm"
      leadingIcon={time ? <RotateCcw /> : <Play />}
      onClick={begin}
    >
      {time ? "Replay" : "Start voice"}
    </Button>
  );
  return (
    <section
      data-preview-wide
      className="voice-session-demo"
      data-layout={"full"}
      aria-label="Design review voice chat"
    >
      <header className="voice-session-demo__header">
        <div>
          <h3>Design review</h3>
          <p>{ended ? "Voice chat ended" : "Voice chat"}</p>
        </div>
        <time
          className="voice-session-demo__time"
          dateTime={`PT${Math.floor(time)}S`}
        >{`00:${String(Math.floor(time)).padStart(2, "0")}`}</time>
      </header>
      <div className="voice-session-demo__body">
        <div className="voice-session-demo__presence">
          <VoiceIndicator
            state={phase}
            size="lg"
            inputLevel={phase === "listening" ? level : 0}
            outputLevel={speaking ? level : 0}
          />
        </div>
        <div className="voice-session-demo__transcript">
          <MessageScrollerProvider autoScroll defaultScrollPosition="end">
            <MessageScroller className="voice-session-demo__messages">
              <MessageScrollerViewport label="Live transcript">
                <MessageScrollerContent>
                  <Transcript.Root
                    variant="timed"
                    currentTime={time}
                    activeSegmentId={activeId}
                  >
                    {segments.length ? (
                      segments.map((segment) => (
                        <MessageScrollerItem
                          key={segment.id}
                          messageId={segment.id}
                        >
                          <Transcript.Segment segment={segment} />
                        </MessageScrollerItem>
                      ))
                    ) : (
                      <div className="voice-session-demo__empty">
                        <span>Ready when you are</span>
                        <p>Ask how to simplify your onboarding flow.</p>
                      </div>
                    )}
                  </Transcript.Root>
                </MessageScrollerContent>
              </MessageScrollerViewport>
              <MessageScrollerButton size="sm">
                Jump to live
              </MessageScrollerButton>
            </MessageScroller>
          </MessageScrollerProvider>
        </div>
      </div>
      <footer className="voice-session-demo__footer">
        <span>
          {running && muted ? "Microphone off" : ended ? "Transcript kept" : ""}
        </span>
        <div className="voice-session-demo__controls">{controls}</div>
      </footer>
    </section>
  );
}

var reply =
  "Keep the first screen focused on one task. Move the optional settings into the next step.".split(
    " ",
  );

```

voice-indicator-voice-chat-2.css

```css
/* apps/web/src/demos/ui/voice-compositions.css */
.voice-session-demo {
  container-type: inline-size;
  width: min(100%, 640px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-session-demo__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block-end: var(--space-4);
  border-block-end: 1px solid var(--border);
}
.voice-session-demo__header h3 {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
}
.voice-session-demo__header p {
  margin: 2px 0 0;
  color: var(--muted-foreground);
  font-size: var(--font-size-sm);
}
.voice-session-demo__time {
  color: var(--muted-foreground);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
}
.voice-session-demo__body {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-6);
  padding-block: var(--space-5);
}
.voice-session-demo__presence {
  display: grid;
  justify-items: center;
}
.voice-session-demo__transcript {
  min-width: 0;
}
.voice-session-demo__messages {
  height: 228px;
}
.voice-session-demo__empty {
  display: grid;
  align-content: center;
  min-height: 190px;
  padding-inline: var(--space-3);
}
.voice-session-demo__empty span {
  font-weight: var(--font-weight-regular);
}
.voice-session-demo__empty p {
  margin: var(--space-1) 0 0;
  color: var(--muted-foreground);
}
.voice-session-demo__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-block-start: var(--space-3);
  border-block-start: 1px solid var(--border);
}
.voice-session-demo__footer > span {
  color: var(--muted-foreground);
  font-size: var(--font-size-xs);
}
.voice-session-demo__controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}
.voice-session-demo[data-layout=focus] .voice-session-demo__body {
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}
.voice-session-demo[data-layout=focus] .voice-session-demo__messages {
  height: 160px;
}
@container (max-width: 440px) {
  .voice-session-demo__body {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    padding-block: var(--space-3);
  }
  .voice-session-demo__messages {
    height: 180px;
  }
  .voice-session-demo__empty {
    min-height: 150px;
    text-align: center;
  }
}
@container (max-width: 300px) {
  .voice-session-demo__footer > span {
    max-width: 110px;
  }
}

```

### Call bar

Use orientation="horizontal" to put the orb beside its label and state. Keep call controls in the same row, with the current caption below. The bar stays compact in a chat sidebar. It uses the same sample speech events as Voice chat.

voice-indicator-call-bar-3.jsx

```jsx
import * as React from "react";
import { Mic, MicOff, PhoneOff, Play, RotateCcw, Square } from "lucide-react";
import { Button, IconButton } from "@/components/ui/button";
import { VoiceIndicator } from "@/components/ui/voice-indicator";
import { MessageSender } from "@/components/ui/message-sender";
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  const [time, setTime] = React.useState(0);
  const [running, setRunning] = React.useState(false);
  const [muted, setMuted] = React.useState(false);
  const [ended, setEnded] = React.useState(false);
  const [interruptedAt, setInterruptedAt] = React.useState(null);
  const inputAtMute = React.useRef(0);
  React.useEffect(() => {
    if (!running) return;
    let previous = performance.now();
    const timer = window.setInterval(() => {
      const now = performance.now(),
        delta = Math.min(0.25, (now - previous) / 1000);
      previous = now;
      setTime((value) => Math.min(22, value + delta));
    }, 80);
    return () => window.clearInterval(timer);
  }, [running]);
  React.useEffect(() => {
    if (time >= 22) setRunning(false);
  }, [time]);
  const interrupted = interruptedAt !== null || time >= 15.5;
  const speaking =
    running && time >= 7 && time < 15.5 && interruptedAt === null;
  const phase = !running
    ? "idle"
    : speaking
      ? "speaking"
      : (time >= 5.2 && time < 7) || time >= 19.5
        ? "thinking"
        : muted
          ? "muted"
          : "listening";
  const inputTime = muted ? inputAtMute.current : time;
  const input =
    inputTime < 1.2
      ? ""
      : inputTime < 2.4
        ? "Can you help me"
        : inputTime < 3.6
          ? "Can you help me simplify"
          : inputTime < 5.2
            ? "Can you help me simplify the"
            : "Can you help me simplify the onboarding flow?";
  const draft =
    inputTime >= 1.2 && inputTime < 2.4
      ? " simplify"
      : inputTime >= 2.4 && inputTime < 3.6
        ? " the onboarding"
        : inputTime >= 3.6 && inputTime < 5.2
          ? " onboarding flow?"
          : undefined;
  const spokenTime = Math.min(time, interruptedAt ?? 15.5);
  const count =
    spokenTime < 7
      ? 0
      : Math.min(reply.length, Math.floor((spokenTime - 7) / 0.52) + 1);
  const words = reply.slice(0, count).map((text, index) => ({
    id: `reply-word-${index}`,
    text: `${index ? " " : ""}${text}`,
    start: 7 + index * 0.52,
    end: 7 + (index + 1) * 0.52,
  }));
  const segments = [
    ...(input
      ? [
          {
            id: "user-1",
            speaker: "You",
            start: 1.2,
            text: input,
            draftText: draft,
            status: draft ? "partial" : "final",
          },
        ]
      : []),
    ...(words.length
      ? [
          {
            id: "reply-1",
            speaker: <MessageSender name="Assistant" kind="agent" size="xs" />,
            start: 7,
            text: words.map((word) => word.text).join(""),
            words,
            status: interrupted ? "interrupted" : undefined,
          },
        ]
      : []),
    ...(interrupted && time >= 16
      ? [
          {
            id: "user-2",
            speaker: "You",
            start: 16,
            text: "Keep the preview",
            draftText: time >= 18 ? ", though." : undefined,
            status: "partial",
          },
        ]
      : []),
  ];
  const activeId =
    phase === "listening"
      ? time >= 16
        ? "user-2"
        : "user-1"
      : speaking
        ? "reply-1"
        : undefined;
  const level =
    running && !ended
      ? 0.2 + 0.5 * Math.sin(time * (speaking ? 6.7 : 4.6)) ** 2
      : 0;
  const begin = () => {
    setTime(0);
    setEnded(false);
    setInterruptedAt(null);
    setMuted(false);
    setRunning(true);
  };
  const controls = running ? (
    <>
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label={muted ? "Unmute microphone" : "Mute microphone"}
        aria-pressed={muted}
        icon={muted ? <MicOff /> : <Mic />}
        onClick={() => {
          if (!muted) inputAtMute.current = time;
          setMuted((value) => !value);
        }}
      />
      {speaking && (
        <IconButton
          type="button"
          variant="ghost"
          size="icon"
          aria-label="Stop reply"
          icon={<Square />}
          onClick={() => setInterruptedAt(time)}
        />
      )}
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label="End voice"
        icon={<PhoneOff />}
        onClick={() => {
          setEnded(true);
          setRunning(false);
        }}
      />
    </>
  ) : (
    <Button
      type="button"
      variant="outline"
      size="sm"
      leadingIcon={time ? <RotateCcw /> : <Play />}
      onClick={begin}
    >
      {time ? "Replay" : "Start voice"}
    </Button>
  );
  {
    const current = segments.at(-1);
    return (
      <section
        data-preview-wide
        className="voice-call-bar"
        aria-label="Compact voice call"
      >
        <div className="voice-call-bar__header">
          <VoiceIndicator
            state={phase}
            size="sm"
            orientation="horizontal"
            label="Design review"
            inputLevel={phase === "listening" ? level : 0}
            outputLevel={speaking ? level : 0}
          />
          <div className="voice-call-bar__controls">{controls}</div>
        </div>
        <div className="voice-call-bar__caption" aria-label="Current caption">
          {current ? (
            <Transcript.Root
              variant="plain"
              currentTime={speaking ? time : undefined}
            >
              <Transcript.Segment
                segment={{
                  ...current,
                  start: undefined,
                  status:
                    current.status === "interrupted"
                      ? "interrupted"
                      : undefined,
                }}
              />
            </Transcript.Root>
          ) : (
            <p>Talk through the next step in your design.</p>
          )}
        </div>
      </section>
    );
  }
}

var reply =
  "Keep the first screen focused on one task. Move the optional settings into the next step.".split(
    " ",
  );

```

voice-indicator-call-bar-3.css

```css
/* apps/web/src/demos/ui/voice-compositions.css */
.voice-call-bar__controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}
.voice-call-bar {
  container-type: inline-size;
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-call-bar__header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
}
.voice-call-bar__caption {
  padding-block-start: var(--space-3);
  margin-block-start: var(--space-3);
  border-block-start: 1px solid var(--border);
  min-height: 72px;
}
.voice-call-bar__caption > p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: var(--font-size-sm);
  line-height: var(--leading-copy);
}
@container (max-width: 300px) {
  .voice-call-bar__header {
    column-gap: var(--space-2);
  }
}

```

### Audio levels

Compare input and output levels while you change the voice state. These controls use sample values.

voice-indicator-audio-levels-4.jsx

```jsx
import * as React from "react";
import { Select } from "@/components/ui/select";
import { Slider } from "@/components/ui/slider";
import { VoiceIndicator } from "@/components/ui/voice-indicator";

export default function Example() {
  const [state, setState] = React.useState("listening");
  const [input, setInput] = React.useState(0.38),
    [output, setOutput] = React.useState(0.62);
  return (
    <div data-preview-wide className="voice-example">
      <div className="voice-example__settings">
        <VoiceIndicator
          state={state}
          inputLevel={input}
          outputLevel={output}
          size="lg"
        />
        <div className="voice-example__fields">
          <StateSelect
            state={state}
            onChange={setState}
            name="Sample voice state"
          />
          <Level label="Input level" value={input} onChange={setInput} />
          <Level label="Output level" value={output} onChange={setOutput} />
        </div>
      </div>
    </div>
  );
}

var states = [
  "idle",
  "connecting",
  "listening",
  "thinking",
  "speaking",
  "muted",
  "error",
];

var title = (value) => value[0].toUpperCase() + value.slice(1);

function StateSelect({ state, onChange, name }) {
  return (
    <label className="voice-example__field">
      <span>Voice state</span>
      <Select.Root
        value={state}
        items={states.map((value) => ({
          value,
          label: title(value),
        }))}
        onValueChange={(value) => {
          if (value) onChange(value);
        }}
      >
        <Select.Trigger aria-label={"Sample voice state"}>
          <Select.Value />
          <Select.Icon />
        </Select.Trigger>
        <Select.Portal>
          <Select.Positioner>
            <Select.Popup>
              <Select.List>
                {states.map((value) => (
                  <Select.Item key={value} value={value}>
                    <Select.ItemText>{title(value)}</Select.ItemText>
                    <Select.ItemIndicator />
                  </Select.Item>
                ))}
              </Select.List>
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
    </label>
  );
}

function Level({ label, value, onChange }) {
  return (
    <Slider.Root
      min={0}
      max={1}
      step={0.01}
      value={value}
      onValueChange={(next) =>
        onChange(Array.isArray(next) ? (next[0] ?? 0) : next)
      }
      valuePlacement="label"
      size="compact"
    >
      <div className="voice-example__level-label">
        <Slider.Label>{label}</Slider.Label>
        <Slider.Value>
          {(_, values) => `${Math.round((values[0] ?? 0) * 100)}%`}
        </Slider.Value>
      </div>
      <Slider.Control>
        <Slider.Track>
          <Slider.Indicator />
          <Slider.Thumb aria-label={label} />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

```

voice-indicator-audio-levels-4.css

```css
/* apps/web/src/demos/ui/voice-indicator-examples.css */
.voice-example {
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-example__settings {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-6);
  width: 100%;
}
.voice-example__fields {
  display: grid;
  gap: var(--space-4);
}
.voice-example__field {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.voice-example__field > span {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-regular);
}
.voice-example {
  container-type: inline-size;
}
@container (max-width: 400px) {
  .voice-example__settings {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: var(--space-4);
  }
  .voice-example__fields {
    width: 100%;
  }
}
.voice-example__level-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
}

```

### Voice indicator states

Compare Idle, Listening, Thinking, and Speaking.

voice-indicator-voice-indicator-states-5.jsx

```jsx
import { VoiceIndicator } from "@/components/ui/voice-indicator";

export default function Example() {
  const values = ["idle", "listening", "thinking", "speaking"];
  return (
    <div data-preview-wide className="voice-example">
      <div className="voice-example__grid">
        {values.map((state) => (
          <VoiceIndicator
            key={state}
            state={state}
            inputLevel={0.38}
            outputLevel={0.62}
            size="lg"
          />
        ))}
      </div>
    </div>
  );
}

```

voice-indicator-voice-indicator-states-5.css

```css
/* apps/web/src/demos/ui/voice-indicator-examples.css */
.voice-example {
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-example__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  width: 100%;
  align-items: start;
  justify-items: center;
}
.voice-example {
  container-type: inline-size;
}
@container (max-width: 400px) {
  .voice-example__grid {
    gap: var(--space-3);
  }
}

```

### Connection states

Show connection progress, a muted microphone, or an error. Connecting has a smaller form with traveling rim light. Muted looks quiet and desaturated; Error carries red inner reflections. Both keep gentle liquid movement and tap feedback. Reduced motion keeps the form still. Shape, light, and visible labels preserve meaning when motion stops.

Interruption is an event, not a lasting voice state. After stopping a reply, set state to what the session is doing next, such as listening, thinking, or idle. A separate frozen mode is not needed. Transcript segments can still retain their own interrupted status.

voice-indicator-connection-states-6.jsx

```jsx
import { VoiceIndicator } from "@/components/ui/voice-indicator";

export default function Example() {
  const values = ["connecting", "muted", "error"];
  return (
    <div data-preview-wide className="voice-example">
      <div className="voice-example__grid">
        {values.map((state) => (
          <VoiceIndicator
            key={state}
            state={state}
            inputLevel={0.38}
            outputLevel={0.62}
            size="lg"
          />
        ))}
      </div>
    </div>
  );
}

```

voice-indicator-connection-states-6.css

```css
/* apps/web/src/demos/ui/voice-indicator-examples.css */
.voice-example {
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-example__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  width: 100%;
  align-items: start;
  justify-items: center;
}
.voice-example {
  container-type: inline-size;
}
@container (max-width: 400px) {
  .voice-example__grid {
    gap: var(--space-3);
  }
}

```

### Voice indicator sizes

Use sm (48px) in a call bar, base (96px) in a panel, lg (160px) beside a transcript, and xl (240px) for a focused voice view. The default is base.

voice-indicator-voice-indicator-sizes-7.jsx

```jsx
import { VoiceIndicator } from "@/components/ui/voice-indicator";

export default function Example() {
  return (
    <div data-preview-wide className="voice-example">
      <div className="voice-example__sizes">
        {[
          ["sm", 48],
          ["base", 96],
          ["lg", 160],
          ["xl", 240],
        ].map(([size, px]) => (
          <div className="voice-example__size" key={size}>
            <VoiceIndicator state="listening" inputLevel={0.38} size={size} />
            <span>
              {size}
              {" \xB7 "}
              {px}px
            </span>
          </div>
        ))}
      </div>
    </div>
  );
}

```

voice-indicator-voice-indicator-sizes-7.css

```css
/* apps/web/src/demos/ui/voice-indicator-examples.css */
.voice-example {
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-example__sizes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  justify-items: center;
  gap: var(--space-6);
  width: 100%;
}
.voice-example__size {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  min-width: 96px;
}
.voice-example__size > span {
  color: var(--muted-foreground);
  font-size: var(--font-size-xs);
}
.voice-example {
  container-type: inline-size;
}

```

### Custom size

Use a number when an existing layout needs a specific size. This assistant panel uses 72px.

voice-indicator-custom-size-8.jsx

```jsx
import { VoiceIndicator } from "@/components/ui/voice-indicator";

export default function Example() {
  return (
    <div className="voice-example__custom">
      <VoiceIndicator state="thinking" size={72} />
      <div>
        <strong>Ask about this page</strong>
        <p>Preparing a reply about your onboarding flow.</p>
      </div>
    </div>
  );
}

```

voice-indicator-custom-size-8.css

```css
/* apps/web/src/demos/ui/voice-indicator-examples.css */
.voice-example {
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-example__custom {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: min(100%, 360px);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.voice-example__custom > div {
  display: grid;
  gap: var(--space-1);
}
.voice-example__custom strong {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
}
.voice-example__custom p {
  margin: 0;
  font-size: var(--font-size-sm);
  line-height: var(--leading-copy);
  color: var(--muted-foreground);
}
.voice-example {
  container-type: inline-size;
}

```

### Reduced motion

Keep the form still while its state remains clear. The operating-system preference takes priority over this control.

voice-indicator-reduced-motion-9.jsx

```jsx
import * as React from "react";
import { Select } from "@/components/ui/select";
import { Switch } from "@/components/ui/switch";
import { VoiceIndicator } from "@/components/ui/voice-indicator";

export default function Example() {
  const [state, setState] = React.useState("speaking"),
    [reduced, setReduced] = React.useState(true);
  return (
    <div
      data-preview-wide
      className="voice-example"
      style={{
        display: "grid",
        justifyItems: "center",
      }}
    >
      <VoiceIndicator
        state={state}
        inputLevel={0.38}
        outputLevel={0.62}
        size="lg"
        reducedMotion={reduced}
      />
      <div className="voice-example__controls">
        <StateSelect
          state={state}
          onChange={setState}
          name="State shown with reduced motion"
        />
        <label className="voice-example__motion-switch">
          <Switch.Root
            checked={reduced}
            onCheckedChange={setReduced}
            aria-label="Reduce motion"
          >
            <Switch.Thumb />
          </Switch.Root>
          <span>Reduce motion</span>
        </label>
      </div>
    </div>
  );
}

var states = [
  "idle",
  "connecting",
  "listening",
  "thinking",
  "speaking",
  "muted",
  "error",
];

var title = (value) => value[0].toUpperCase() + value.slice(1);

function StateSelect({ state, onChange, name }) {
  return (
    <label className="voice-example__field">
      <span>Voice state</span>
      <Select.Root
        value={state}
        items={states.map((value) => ({
          value,
          label: title(value),
        }))}
        onValueChange={(value) => {
          if (value) onChange(value);
        }}
      >
        <Select.Trigger aria-label={"State shown with reduced motion"}>
          <Select.Value />
          <Select.Icon />
        </Select.Trigger>
        <Select.Portal>
          <Select.Positioner>
            <Select.Popup>
              <Select.List>
                {states.map((value) => (
                  <Select.Item key={value} value={value}>
                    <Select.ItemText>{title(value)}</Select.ItemText>
                    <Select.ItemIndicator />
                  </Select.Item>
                ))}
              </Select.List>
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
    </label>
  );
}

```

voice-indicator-reduced-motion-9.css

```css
/* apps/web/src/demos/ui/voice-indicator-examples.css */
.voice-example {
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-example__field {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.voice-example__field > span {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-regular);
}
.voice-example__controls {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-block-start: var(--space-4);
}
.voice-example__controls .voice-example__field {
  width: 180px;
}
.voice-example__motion-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--space-8);
  color: var(--foreground);
  font-size: var(--font-size-sm);
}
.voice-example {
  container-type: inline-size;
}

```

## API reference

VoiceIndicator

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| VoiceIndicator | forwardRef<HTMLDivElement, VoiceIndicatorProps> | — | Native div group with forwarded attributes and ref. |
| state | VoiceIndicatorState | 'idle' | Caller-supplied state: idle, connecting, listening, thinking, speaking, muted, or error. |
| inputLevel | number | — | Optional normalized input level from 0 to 1. Finite values are clamped; missing or non-finite values resolve to zero. |
| outputLevel | number | — | Optional normalized output level from 0 to 1. Finite values are clamped; missing or non-finite values resolve to zero. |
| size | VoiceIndicatorSize | 'base' | Artwork size: sm (48px), base (96px), lg (160px), xl (240px), or a custom finite pixel size. Values below 1px resolve to 1px; non-finite numeric values use base. |
| orientation | 'vertical' \| 'horizontal' | 'vertical' | Place the label and state below the art, or beside it in a call bar. |
| reducedMotion | boolean | false | Requests the still artwork when true. The operating-system reduced-motion preference always overrides false. |
| label | string | — | Optional visible name associated with the state. |
| description | string | — | Optional visible supporting text, also referenced by aria-describedby. |
| children | React.ReactNode | — | Optional caller-owned content rendered after the state text. |

VoiceIndicatorState, VoiceIndicatorSize, and VoiceIndicatorProps are exported. The root has no action target or continuous live-region updates. Capture, playback, generated speech, application policy, and session controls remain caller-owned.
