āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/elevenlabs/ui/components/bar-visualizer ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
<ComponentPreview name="bar-visualizer-demo" description="A bar visualizer showing audio frequency bands with various states." />
npx @elevenlabs/cli@latest components add bar-visualizer
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="bar-visualizer" title="components/ui/bar-visualizer.tsx" />
<Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </CodeTabs>import {
BarVisualizer,
useAudioVolume,
useBarAnimator,
useMultibandVolume,
type AgentState,
type AudioAnalyserOptions,
type BarVisualizerProps,
type MultiBandVolumeOptions,
} from "@/components/ui/bar-visualizer"
<BarVisualizer state="listening" barCount={15} mediaStream={stream} />
<BarVisualizer state="speaking" demo={true} centerAlign={true} />
The main visualizer component that displays animated frequency bars.
<BarVisualizer state="speaking" mediaStream={stream} />
| Prop | Type | Description |
| ----------- | ---------------- | ------------------------------------------------------------------------------ |
| state | AgentState | Voice assistant state: connecting, initializing, listening, speaking, thinking |
| barCount | number | Number of bars to display. Default: 15 |
| mediaStream | MediaStream | Audio source for real-time visualization |
| minHeight | number | Minimum bar height as percentage. Default: 20 |
| maxHeight | number | Maximum bar height as percentage. Default: 100 |
| demo | boolean | Enable demo mode with fake audio data. Default: false |
| centerAlign | boolean | Align bars from center instead of bottom. Default: false |
| ...props | HTMLDivElement | All standard div element props |
Get the overall volume level from an audio stream.
const volume = useAudioVolume(mediaStream, {
fftSize: 32,
smoothingTimeConstant: 0,
})
| Parameter | Type | Description |
| ----------- | ---------------------- | --------------------------------- |
| mediaStream | MediaStream \| null | The audio stream to analyze |
| options | AudioAnalyserOptions | FFT size, smoothing, and dB range |
Track volume across multiple frequency bands for visualization.
const frequencyBands = useMultibandVolume(mediaStream, {
bands: 15,
loPass: 100,
hiPass: 200,
updateInterval: 32,
})
| Parameter | Type | Description |
| ----------- | ------------------------ | ------------------------------------- |
| mediaStream | MediaStream \| null | The audio stream to analyze |
| options | MultiBandVolumeOptions | Band count, frequency range, interval |
Create animation sequences for different states.
const highlightedIndices = useBarAnimator("connecting", 15, 100)
| Parameter | Type | Description |
| --------- | ---------------- | ------------------------------ |
| state | AnimationState | Current animation state |
| columns | number | Number of bars |
| interval | number | Animation frame interval in ms |
type AgentState =
| "connecting" // Establishing connection
| "initializing" // Setting up
| "listening" // Listening for input
| "speaking" // Playing audio output
| "thinking" // Processing
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā