Components
Voice Glow
A glow that reacts to voice.
ProPro, coming soon.
<VoiceGlow level={level}>
<MicButton />
</VoiceGlow>Get notified
Voice Glow is a Pro effect. Join the waitlist and we'll email you when it's available.
Usage
A glow behind your element swells and brightens with the speaker's voice. You feed it a level from 0 to 1, from the microphone, a voice call or a speech model's audio.
import { VoiceGlow } from "@zjkm/pro/voice-glow";
import { useEffect, useState } from "react";
// Loudness of a MediaStream, 0–1, updated every frame.
function useLevel(stream: MediaStream | null) {
const [level, setLevel] = useState(0);
useEffect(() => {
if (!stream) return;
const audio = new AudioContext();
const analyser = audio.createAnalyser();
audio.createMediaStreamSource(stream).connect(analyser);
const data = new Uint8Array(analyser.fftSize);
let raf = 0;
const tick = () => {
analyser.getByteTimeDomainData(data);
const rms = Math.sqrt(data.reduce((sum, v) => sum + ((v - 128) / 128) ** 2, 0) / data.length);
setLevel(Math.min(1, rms * 4));
raf = requestAnimationFrame(tick);
};
tick();
return () => {
cancelAnimationFrame(raf);
audio.close();
};
}, [stream]);
return level;
}
export function MicButton({ stream }: { stream: MediaStream | null }) {
return (
<VoiceGlow level={useLevel(stream)}>
<button aria-label="Microphone">🎙</button>
</VoiceGlow>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Your mic button or avatar. | |
level | number | How loud the voice is right now, from 0 to 1. | |
color | string | "#38bdf8" | Glow colour. |
blur | number | 16 | Blur in pixels. |
className | string | Classes for the wrapper. |
With reduced motion, the glow brightens with the voice but doesn't swell.