Real-time canvas-based audio waveform visualizer with microphone input and customizable rendering modes.
Live Audio Waveform
Real-time microphone input visualization with audio reactivity
Installation
npx shadcn-svelte@latest add https://sv11.ui.twango.dev/r/live-waveform.json Usage
<script lang="ts">
import { LiveWaveform } from "$lib/registry/ui/live-waveform";
</script>
<LiveWaveform /> Examples
Static Mode
Render a symmetric frequency-band visualization with bars in fixed positions.
<script lang="ts">
import { LiveWaveform } from "$lib/registry/ui/live-waveform";
</script>
<LiveWaveform active mode="static" /> Scrolling Mode
Render the volume average as a timeline that scrolls right-to-left.
<script lang="ts">
import { LiveWaveform } from "$lib/registry/ui/live-waveform";
</script>
<LiveWaveform active mode="scrolling" /> Processing State
processing animates a placeholder wave while you wait for audio. The bars ease back to idle when both active and processing turn off.
<script lang="ts">
import { LiveWaveform } from "$lib/registry/ui/live-waveform";
</script>
<LiveWaveform processing mode="static" /> Custom Styling
Every rendering parameter is a plain prop — adjust bar geometry, color, height, and edge fade inline.
<script lang="ts">
import { LiveWaveform } from "$lib/registry/ui/live-waveform";
</script>
<LiveWaveform
active
barWidth={4}
barHeight={6}
barGap={2}
barColor="#3b82f6"
height={100}
fadeEdges
/> API Reference
Notes
- Uses the Web Audio API via
AnalyserNodefor real-time frequency analysis. - Automatically requests microphone permission when
activebecomestrueand tears down the stream and audio context when it flips back tofalse. - Canvas rendering is HiDPI-aware — internal
ResizeObserverscales the drawing buffer bydevicePixelRatio. mode="static"draws symmetric frequency bars in fixed positions;mode="scrolling"maintains ahistorySize-length ring buffer of volume averages that scrolls right-to-left.processingsmoothly crossfades from the last active frame into the synthetic wave, and a fade-out pass clears the canvas when both flags are off.deviceIdselects a specific input viaMediaDeviceInfo.deviceId; omit to use the default microphone.onStreamReady/onStreamEnd/onErrorare fire-and-forget callbacks for wiring the lifecycle into app state.