Voice
A glow that rises with your voice from the bottom of a chat input or phone screen.
How can I help you?
These play a synthetic voice. The playground can listen to your microphone.
Playground
<script>
import { VoiceBeam } from 'runeglow/voice-glow';
// A number from 0 to 1, or a function returning one, called every frame.
let { level } = $props();
</script>
<VoiceBeam {level}>
<ChatInput />
</VoiceBeam>Install
pnpm add runeglow Or copy just this library’s source into your project, with the shadcn-svelte CLI:
npx shadcn-svelte@latest add https://runeglow.dev/r/voice-glow.json import { VoiceBeam, useMicrophone } from 'runeglow/voice-glow';Usage
Wrap the element the voice belongs to and hand the beam a microphone stream. useMicrophone asks for it; call start from a
click so the browser lets audio begin.
<script>
import { VoiceBeam, useMicrophone } from 'runeglow/voice-glow';
const mic = useMicrophone();
</script>
<button onclick={mic.start}>Listen</button>
<VoiceBeam stream={mic.stream}>
<ChatInput />
</VoiceBeam>Or drive it yourself with level: a number from 0 to 1, or a function
the beam calls every frame.
<script>
import { VoiceBeam } from 'runeglow/voice-glow';
// From your own audio pipeline, a text-to-speech player, anything.
let { level } = $props();
</script>
<VoiceBeam type="pill" {level} colorVariant="ocean">
<RecordingPill />
</VoiceBeam>The microphone’s state is reactive, so the interface can follow it.
<script>
import { VoiceBeam, useMicrophone } from 'runeglow/voice-glow';
const mic = useMicrophone();
</script>
{#if mic.state === 'denied'}
<p>Microphone blocked. Allow it in the browser's site settings.</p>
{/if}
<VoiceBeam type="mobile" stream={mic.stream} active={mic.state === 'live'}>
<VoiceScreen />
</VoiceBeam>Props
type 'default' | 'pill' | 'mobile' 'default' The host the glow is tuned for: a chat input, a small recording pill, or the bottom of a phone screen.stream MediaStream | null null A live audio stream to listen to, usually mic.stream.level number | (() => number) 0 Drive the glow yourself, 0 to 1. A function is called every frame.sensitivity number 3.1 Gain on the incoming level.threshold number 0.015 Levels under this count as silence.attack number 0.325 Seconds the glow takes to rise.release number 0.86 Seconds the glow takes to fall.colorVariant 'colorful' | 'mono' | 'ocean' | 'sunset' | 'forest' | 'candy' | 'ice' | 'gold' 'colorful' The palette.colors string[] – Your own lobe colours, centre first then the pairs outward, up to seven.bandColors { core?, above?, mid?, below? } – Colours of the band of light along the glow’s ceiling.theme 'dark' | 'light' | 'auto' 'dark' Tunes the glow for the background it sits on.scale number per type One multiplier on every pixel dimension of the effect.active boolean true Fades the effect in and out.paused boolean false Holds the current frame.strength number per type Opacity of the effect layers, 0 to 1.borderRadius number auto Corner radius in px. Omit it to read the first child’s.motion VoiceBeamMotion | (() => VoiceBeamMotion) – { gather, offset, stretch, heldLevel, cornerFollow }. Gathers the glow into one beam you can move.css string – Extra CSS appended to the generated sheet. {id} is replaced with the instance id.onLevel (level: number) => void – Called every frame with the smoothed level the glow is showing.onActivate, onDeactivate () => void – Called when a fade in or out finishes.ref HTMLDivElement | null – The wrapper element. Bindable with bind:ref....rest HTMLAttributes<HTMLDivElement> – class, style and other attributes are forwarded to the wrapper.Shape and styling
Each of these has a tuned default for the type and theme. The playground has a slider for every one.
reach number per type How far the glow rises with the voice.spread number per type How much it widens as it rises.flow number per type Sideways drift of the colours, px per second.idle number per type How present the glow is in silence, 0 to 1.breatheDuration number 5.2 Seconds per idle breath.bands boolean true Split the voice into low, mid and high, one per lobe pair.bend, bandStrength, bandWidth, bandPosition, bandCurve, bandSpread, bandSkew, bandOffset number per type The band of light along the glow’s ceiling: how far it bows, how strong, how wide, where it sits and how it curves.bandTail, bandTailPosition, bandTailCurve, bandTailOverflow number per type How the band’s ends rise again toward the corners.bandAberration number per type Chromatic fringes on the band, 0 to 1.distortion, distortionDetail number per type A liquid warp under the band. Switched off on large hosts in Safari, where it is too slow.glowWidth, glowHeight, lobeSpacing number per type Size and spacing of the coloured lobes.rangeWidth, rangeHeight, softness number per type The area the glow may fill, and how softly it ends.coreSize, coreLight, coreLightWidth, coreLightHeight number per type The bright centre.strokeScale, innerScale, innerHeight, bloomScale, bloomHeight number per type Size of each of the three layers.glowSize, strokeOpacity, innerOpacity, bloomOpacity number per type Blur of the bloom and a multiplier on each layer’s opacity.brightness, saturation number per theme Multipliers on the glow.hueRange, hueDuration, staticColors number, number, boolean per theme The slow hue drift: its range in degrees, seconds per cycle, and an off switch.useMicrophone
Call it while a component is being set up. Read its values from the returned object, as they
are reactive: mic.stream, not a destructured copy.
stream MediaStream | null – The live stream to hand to VoiceBeam.state 'idle' | 'requesting' | 'live' | 'denied' | 'unsupported' | 'error' – Where the request stands.error Error | null – The error behind a denied or error state.supported boolean – Whether this browser can capture audio.start() () => Promise<MediaStream | null> – Asks for the microphone. Call it from a click.stop() () => void – Stops every track and drops the stream.Notes
- Nothing is recorded or played back. The stream is only analysed for its level.
- If the glow stays flat while you speak, the browser has probably opened an input that is
switched off, such as a laptop’s built-in microphone while its lid is closed. Pick the
input yourself with
useMicrophone({ constraints: { deviceId } }). - The wrapper is a block element. If the wrapped element is narrower than its container, give
the wrapper
style="width: fit-content". - The glow is drawn over the wrapped element, and its radius is read from that element’s
top-left corner. Give the text and buttons inside
position: relative; z-index: 5so they stay above the light, which matters most on a light surface. - The glow is authored in px for its type’s usual size. Use
scalewhen your element is much smaller or larger. - It pauses while offscreen, and holds still under
prefers-reduced-motion. - The React source also contains two unreleased looks, dots and lines. They are switched off here exactly as they are in the published React package.