Bar Visualizer
sv11-twango/bar-visualizerFreeComponent
A discrete bar-style audio level visualizer driven by a frequency array.
Live preview
live · rendered by the registry
Rendered by sv11-twango on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add http://sv11.ui.twango.dev/r/bar-visualizer.jsonSource
1<script lang="ts" module>2 import type { HTMLAttributes } from "svelte/elements";34 export type AgentState = "connecting" | "initializing" | "listening" | "speaking" | "thinking";56 export type BarVisualizerProps = HTMLAttributes<HTMLDivElement> & {7 /**8 * Voice-agent lifecycle state. Drives the bar highlight sequence and9 * animation cadence. Leave undefined for a static row.10 */11 state?: AgentState;12 /**13 * Number of bars to render across the visualizer.14 * @default 1515 */16 barCount?: number;17 /**18 * Live audio source used for FFT analysis. Ignored when `demo` is19 * `true`. Pass `null` to disable analysis without unmounting.20 */21 mediaStream?: MediaStream | null;22 /**23 * Minimum bar height as a percentage of the container.24 * @default 2025 */26 minHeight?: number;27 /**28 * Maximum bar height as a percentage of the container.29 * @default 10030 */31 maxHeight?: number;32 /**33 * When `true`, replaces the FFT feed with a synthetic oscillating34 * pattern. Useful for previews and documentation.35 * @default false36 */37 demo?: boolean;38 /**39 * Align bars from the vertical center rather than growing up from the40 * bottom.41 * @default false42 */43 centerAlign?: boolean;44 /** Bound reference to the root container element. */45 ref?: HTMLDivElement | null;46 };47</script>4849<script lang="ts">50 import { cn } from "$UTILS$.js";51 import {52 createAudioAnalyser,53 generateConnectingSequenceBar,54 generateListeningSequenceBar,55 normalizeDb,56 } from "./utils.js";5758 let {59 state: agentState,60 barCount = 15,61 mediaStream,62 minHeight = 20,63 maxHeight = 100,64 demo = false,65 centerAlign = false,66 class: className,67 style,68 ref = $bindable(null),69 ...restProps70 }: BarVisualizerProps = $props();7172 let realBands = $state<number[]>(new Array(barCount).fill(0));73 let fakeBands = $state<number[]>(new Array(barCount).fill(0.2));74 let highlightedIndices = $state<number[]>([]);7576 const volumeBands = $derived(demo ? fakeBands : realBands);7778 const animInterval = $derived(79 agentState === "connecting"80 ? 2000 / barCount81 : agentState === "thinking"82 ? 15083 : agentState === "listening"84 ? 50085 : 100086 );8788 // useMultibandVolume — real FFT analysis89 $effect(() => {90 if (demo || !mediaStream) {91 realBands = new Array(barCount).fill(0);92 return;93 }94 const currentBarCount = barCount;95 const { analyser, cleanup } = createAudioAnalyser(mediaStream, { fftSize: 2048 });9697// … truncated
More from sv11-twango
All 29 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Audio Playeraudio-player | sv11-twango | Components | Free | 2 deps | |
| Conversationconversation | sv11-twango | Components | Free | 2 deps | |
| Conversation Barconversation-bar | sv11-twango | Components | Free | 1 dep | |
| Live Waveformlive-waveform | sv11-twango | Components | Free | no deps | |
| Matrixmatrix | sv11-twango | Components | Free | no deps | |
| Messagemessage | sv11-twango | Components | Free | 2 deps | |
| Mic Selectormic-selector | sv11-twango | Components | Free | 1 dep | |
| Orborb | sv11-twango | Components | Free | 4 deps |
