Live Waveform
Draw audio as it happens, from a microphone stream, an analyser, or a level you measure.
Overview
When someone talks to a voice input, they want proof it hears them. Live Waveform draws that proof: bars of recent loudness that scroll in from the right, or a line of the current samples.
Give it a stream, an analyser, or a level. It never asks for the microphone itself, and it records nothing.
Anatomy
- CanvasThe bars or line, drawn each frame at the screen's pixel density
LiveWaveform is one component. It installs motion, which it uses to read the reduced motion setting.
Behavior
Sources
analyser wins over stream, and both win over level. Stopping the stream's tracks is up to you.
States
Without state, the waveform is active when it has a source and idle otherwise. The state is reported as data-state on the root.
Bars and line
variant="bars" keeps a history of loudness, one bar about every 45 ms, and fits as many bars as the width allows. Set barWidth and barGap to change the density. variant="line" draws the analyser's current samples; with only a level, it draws a calm wave of that size.
Size and color
The canvas fills its box, which is 40 px tall by default; set the height with className. Bars are drawn in the text color, read at draw time, so they follow the theme. Set a text color class to change it.
Accessibility
The waveform is a picture with the img role. Its name says the state, such as "Audio waveform, live". It is not a live region, so changes are not announced; announce recording start and stop in your own controls.
With reduced motion, bars change about four times a second instead of scrolling, the line holds still, and processing is a still row of bars.
Every string comes from labels.
Installation
Usage
import { LiveWaveform } from "@/components/ai/live-waveform"
<LiveWaveform stream={microphone} state={transcribing ? "processing" : undefined} />Examples
Microphone
The microphone opens only when the button is pressed, and stops when it is pressed again.
API reference
LiveWaveform
Accepts native div props beyond those listed.