Audio Visualizer
Live audio level as bars, a waveform or an orb: the mic meter of a call, a voice message, a voice assistant.
c2-audio-visualizer draws an audio level the way calls and voice apps do: the microphone meter of Meet and Discord, the waveform of a voice message, the orb of ChatGPT’s voice mode. It reads a microphone or a call participant’s stream, a playing <audio> element, or a level your call SDK already reports. With no audio at all, it shows what an agent is doing.
Import
import '@c2n/components/audio-visualizer'Usage
Sources
The first source set wins:
stream, aMediaStream(a microphone fromgetUserMedia, a participant’s track from your call SDK). The visualizer analyses it through Web Audio.media, an<audio>or<video>element that plays, such as a voice message. Once routed through Web Audio, the element is heard through it, as before.level, a number from 0 to 1, for an SDK that reports levels (LiveKit’saudioLevel, Daily’s audio levels). This is the cheapest: no Web Audio at all.
const meter = document.querySelector('c2-audio-visualizer')!
meter.stream = await navigator.mediaDevices.getUserMedia({ audio: true })Without a source, state animates an agent’s state while its audio plays elsewhere: idle (flat), listening (a slow breath), thinking (a turning shimmer) and speaking (a looping rhythm).
Looks
variant="bars" (the default) draws bars bars, loudest in the middle like a microphone meter. wave draws a waveform across --c2-audio-visualizer__wave--width, and orb a sphere that swells and glows with the level. muted draws a flat, greyed meter.
Speaking detection
speaking-change fires with { speaking } when the level crosses speaking-threshold (0.08 by default), held for 300 ms so the pauses between words do not flicker, and :state(speaking) matches meanwhile. c2-video-tile uses it to light a speaking participant’s outline.
Motion and accessibility
The visualizer draws only while it is on screen and the page is visible. Under reduced motion it is a steady meter, updated four times a second, with no breathing or turning. It is decorative by default; a label makes it an image of that name, for an orb that stands on its own.