Simulates prefers-reduced-motion for the demo. Off follows your system setting.
Steps focus through the demo with ] and [. Tab, arrows, and Escape stay native so the component behaves as shipped.
A prompt bar for typing or talking to an AI, with a wave of soft pixels along the bottom that listens, thinks and speaks.
npx shadcn@latest add ikislay/pixel-ui/voice-barimport { 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);
1// Loading…
Options you can pass to customize this component.
stateidlelisteningthinkingspeakingControls 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) => unknownRuns 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() => voidRuns when the waveform button starts voice mode. Start the microphone here.
onCancel() => voidRuns when voice mode ends through the X button or Escape.
transcriptstringLive dictation or the streamed reply. Each new word forms out of the wave while listening or speaking.
getLevel() => numberRead 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.
mutedbooleanControls the mic toggle yourself, with onMutedChange.
valuestringControls the typed prompt yourself, with onValueChange.
attachmentsReactNodeChips shown above the prompt. The row folds open when set and closed when empty.
errorReactNodeA message shown under the prompt, such as a blocked microphone.
leadingReactNodeReplaces the + button on the left, for example with a mode picker. Pass null to hide it.
onAttach() => voidRuns when the + button is pressed. A ripple runs out of the button into the wave.
placeholderstringPlaceholder and accessible label of the prompt.
disabledbooleanTurns off typing and every button.
refRef<{ 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.
Simulates prefers-reduced-motion for the demo. Off follows your system setting.
Steps focus through the demo with ] and [. Tab, arrows, and Escape stay native so the component behaves as shipped.
1
A prompt bar for typing or talking to an AI, with a wave of soft pixels along the bottom that listens, thinks and speaks.
npx shadcn@latest add ikislay/pixel-ui/voice-barimport { 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);
1// Loading…
Options you can pass to customize this component.
stateidlelisteningthinkingspeakingControls 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) => unknownRuns 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() => voidRuns when the waveform button starts voice mode. Start the microphone here.
onCancel() => voidRuns when voice mode ends through the X button or Escape.
transcriptstringLive dictation or the streamed reply. Each new word forms out of the wave while listening or speaking.
getLevel() => numberRead 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.
mutedbooleanControls the mic toggle yourself, with onMutedChange.
valuestringControls the typed prompt yourself, with onValueChange.
attachmentsReactNodeChips shown above the prompt. The row folds open when set and closed when empty.
errorReactNodeA message shown under the prompt, such as a blocked microphone.
leadingReactNodeReplaces the + button on the left, for example with a mode picker. Pass null to hide it.
onAttach() => voidRuns when the + button is pressed. A ripple runs out of the button into the wave.
placeholderstringPlaceholder and accessible label of the prompt.
disabledbooleanTurns off typing and every button.
refRef<{ 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.