Skip to Content
zjkm-ui
Components

Voice Glow

A glow that reacts to voice.

ProPro, coming soon.
Props
16px
<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

PropTypeDefaultDescription
childrenReactNodeYour mic button or avatar.
levelnumberHow loud the voice is right now, from 0 to 1.
colorstring"#38bdf8"Glow colour.
blurnumber16Blur in pixels.
classNamestringClasses for the wrapper.

With reduced motion, the glow brightens with the voice but doesn't swell.

On this page