Type and press Enter, or tap the waveform to talk
Controls

Voice Bar

Preview
Reduced motion

Simulates prefers-reduced-motion for the demo. Off follows your system setting.

Keyboard stepping

Steps focus through the demo with ] and [. Tab, arrows, and Escape stay native so the component behaves as shipped.

Voice Bar

A prompt bar for typing or talking to an AI, with a wave of soft pixels along the bottom that listens, thinks and speaks.

Dependencies

lucide-react

Installation

npx shadcn@latest add ikislay/pixel-ui/voice-bar

How to use

import { useState } from "react";
import { VoiceBar, useVoiceAudio } from "@/components/ui/voice-bar";
export default function Demo() {
const [stream, setStream] = useState<MediaStream | null>(null);
const audio = useVoiceAudio(stream);
return (
<VoiceBar
{...audio}
onSubmit={(prompt) => fetch("/api/chat", { method: "POST", body: prompt })}
onVoiceStart={async () => setStream(await navigator.mediaDevices.getUserMedia({ audio: true }))}
onCancel={() => {
stream?.getTracks().forEach((t) => t.stop());
setStream(null);

Source Code

// Loading…

Props

Options you can pass to customize this component.

Prop
Type
Description
state
idlelisteningthinkingspeaking

Controls the mode yourself, with onStateChange. Leave it out and the bar moves on its own: the waveform starts listening, X returns to idle.

onSubmit
(value: string) => unknown

Runs when a typed prompt is sent. Return a promise to show Thinking until it settles; a rejection puts the prompt back and shows the error's message.

onVoiceStart
() => void

Runs when the waveform button starts voice mode. Start the microphone here.

onCancel
() => void

Runs when voice mode ends through the X button or Escape.

transcript
string

Live dictation or the streamed reply. Each new word forms out of the wave while listening or speaking.

getLevel
() => number

Read every frame for loudness from 0 to 1. Spread useVoiceAudio(stream) to get it and getSpectrum. Without it, the wave plays a simulated voice.

getSpectrum
() => ArrayLike<number>

Read every frame for 8 frequency bands from 0 to 1, low to high. Shapes the crest of the wave.

muted
boolean

Controls the mic toggle yourself, with onMutedChange.

value
string

Controls the typed prompt yourself, with onValueChange.

attachments
ReactNode

Chips shown above the prompt. The row folds open when set and closed when empty.

error
ReactNode

A message shown under the prompt, such as a blocked microphone.

leading
ReactNode

Replaces the + button on the left, for example with a mode picker. Pass null to hide it.

onAttach
() => void

Runs when the + button is pressed. A ripple runs out of the button into the wave.

placeholder
string

Placeholder and accessible label of the prompt.

disabled
boolean

Turns off typing and every button.

ref
Ref<{ pulse(options?) }>

Call pulse({ kind, origin }) to send a "ripple", "wipe" or "tick" through the wave from an element or a 0 to 1 position.

Controls

Voice Bar

Preview
Reduced motion

Simulates prefers-reduced-motion for the demo. Off follows your system setting.

Keyboard stepping

Steps focus through the demo with ] and [. Tab, arrows, and Escape stay native so the component behaves as shipped.

Voice Bar
Type and press Enter, or tap the waveform to talk

Voice Bar

A prompt bar for typing or talking to an AI, with a wave of soft pixels along the bottom that listens, thinks and speaks.

Dependencies

lucide-react

Installation

npx shadcn@latest add ikislay/pixel-ui/voice-bar

How to use

import { useState } from "react";
import { VoiceBar, useVoiceAudio } from "@/components/ui/voice-bar";
export default function Demo() {
const [stream, setStream] = useState<MediaStream | null>(null);
const audio = useVoiceAudio(stream);
return (
<VoiceBar
{...audio}
onSubmit={(prompt) => fetch("/api/chat", { method: "POST", body: prompt })}
onVoiceStart={async () => setStream(await navigator.mediaDevices.getUserMedia({ audio: true }))}
onCancel={() => {
stream?.getTracks().forEach((t) => t.stop());
setStream(null);

Source Code

// Loading…

Props

Options you can pass to customize this component.

Prop
Type
Description
state
idlelisteningthinkingspeaking

Controls the mode yourself, with onStateChange. Leave it out and the bar moves on its own: the waveform starts listening, X returns to idle.

onSubmit
(value: string) => unknown

Runs when a typed prompt is sent. Return a promise to show Thinking until it settles; a rejection puts the prompt back and shows the error's message.

onVoiceStart
() => void

Runs when the waveform button starts voice mode. Start the microphone here.

onCancel
() => void

Runs when voice mode ends through the X button or Escape.

transcript
string

Live dictation or the streamed reply. Each new word forms out of the wave while listening or speaking.

getLevel
() => number

Read every frame for loudness from 0 to 1. Spread useVoiceAudio(stream) to get it and getSpectrum. Without it, the wave plays a simulated voice.

getSpectrum
() => ArrayLike<number>

Read every frame for 8 frequency bands from 0 to 1, low to high. Shapes the crest of the wave.

muted
boolean

Controls the mic toggle yourself, with onMutedChange.

value
string

Controls the typed prompt yourself, with onValueChange.

attachments
ReactNode

Chips shown above the prompt. The row folds open when set and closed when empty.

error
ReactNode

A message shown under the prompt, such as a blocked microphone.

leading
ReactNode

Replaces the + button on the left, for example with a mode picker. Pass null to hide it.

onAttach
() => void

Runs when the + button is pressed. A ripple runs out of the button into the wave.

placeholder
string

Placeholder and accessible label of the prompt.

disabled
boolean

Turns off typing and every button.

ref
Ref<{ pulse(options?) }>

Call pulse({ kind, origin }) to send a "ripple", "wipe" or "tick" through the wave from an element or a 0 to 1 position.