React VU meter component designed to work from legacy React (16.8+) up to React 19. It computes RMS from Web Audio in real time and drives the needle with VU ballistics (~300 ms attack/release). Comes with light/dark themes and responsive sizing.
When published on npm:
npm i vu-meter-reactimport { VUMeter } from "vu-meter-react";
// Stereo (L/R)
<VUMeter
audioContext={audioContext}
sourceNode={sourceNode}
referenceLevel={-18}
options={{ width: 300, theme: "light" }}
/>
// Mono
<VUMeter
audioContext={audioContext}
sourceNode={sourceNode}
mono
referenceLevel={-20}
options={{ width: 260, theme: "dark" }}
/>VUMeter(props: VUMeterProps)- Single component that renders either a single (mono) meter or a stereo pair (L/R)
-
VUMeterPropsaudioContext: AudioContext | nullsourceNode: AudioNode | nullmono?: boolean— mono meter when true, stereo when false (default: false)label?: string— mono: "MONO", stereo: "L"/"R" by defaultreferenceLevel?: number— dBFS treated as 0 VU (default: -18)options?: VUMeterOptions
-
VUMeterOptionstheme?: 'dark' | 'light'(default: 'light')needleColor?: stringlabelColor?: stringbackgroundColor?: stringboxColor?: stringfontFamily?: stringwidth?: number— height is auto-calculated by aspect ratio when unspecifiedheight?: number— width is auto-calculated by aspect ratio when unspecifiedpeakHoldMs?: number— peak lamp hold time after the last clip in milliseconds (default: 1000)peakFadeMs?: number— peak lamp fade-out duration in milliseconds (default: 5000)clipThresholdDeg?: number— needle angle threshold in degrees to treat as clip (default: 23)
- SVG scale rendering with color accents for warning zones
- Needle is rotated via CSS transform; tuned for smooth animation
- Peak lamp turns on near the upper range; once the signal falls below the clip threshold it stays on for
peakHoldMsand then fades out overpeakFadeMs(defaults: hold 1s, fade 5s) - RMS via
getFloatTimeDomainData(), converted to dBFS, then mapped to VU with measured piecewise interpolation - VU ballistics (~300 ms attack/release) for natural motion
- Due to browser autoplay policies, create/resume
AudioContextfrom a user gesture (e.g., clicking Play) - In stereo mode, the component internally uses a
ChannelSplitterNodeto meter L/R
- Build (ESM/CJS + d.ts):
npm run build→dist/index.mjs,dist/index.cjs,dist/index.d.ts - Generate docs (TypeDoc):
npm run docs→ outputs todocs/
MIT