Skip to content
Eskais UI

Forms

Voice Input

A voice input whose visual follows the microphone level in real time, built with definePrimitive: a mic toggle with a ring that grows as you speak, or a composer bar with cancel, a live waveform and a timer. The level comes from a Web Audio AnalyserNode on one shared AudioContext, written as CSS custom properties on animation frames with no React render per frame; useAudioLevel gives it to your own visual and requestMicrophone maps getUserMedia's errors. It doesn't record or transcribe.

Example

Press the microphone and speak.

Installation

npx shadcn@latest add @eskais/voice-input
npm packageslucide-react

Usage

Import
import {  barProfile,  elapsedDateTime,  formatElapsed,  levelFromDb,  rms,  silenceDb,  smoothLevel,  stepLevel,  toDbfs,} from "@/lib/audio-level"import { audioContextStatus, createAudioMeter, primeAudioContext } from "@/lib/audio-meter"import { microphoneError, requestMicrophone, stopStream } from "@/lib/microphone"import { voiceInput } from "@/components/ui/voice-input-primitive"import { useAudioLevel } from "@/components/ui/use-audio-level"import { useElapsedSeconds } from "@/components/ui/use-elapsed-seconds"import { VoiceInput, voiceInputLabels, voiceInputTone } from "@/components/ui/voice-input"

Reach for it to dictate into a composer or a field: you get the microphone in onStart and transcribe in onConfirm; it shows that the person is heard.

API reference

VoiceInput

Takes Omit<PartProps<"div", VoiceInputRootState>, "children" | "ref" | "defaultValue"> &.

Other exports

barProfileelapsedDateTimeformatElapsedlevelFromDbrmssilenceDbsmoothLevelstepLeveltoDbfsaudioContextStatuscreateAudioMeterprimeAudioContextmicrophoneErrorrequestMicrophonestopStreamvoiceInputuseAudioLeveluseElapsedSecondsvoiceInputLabelsvoiceInputTonetype AudioLevelFrametype AudioMetertype AudioMeterOptionstype MicrophoneErrortype MicrophoneResulttype VoiceInputOptionstype VoiceInputStatetype VoiceInputStateChangeReasontype VoiceInputStateDetailstype UseAudioLevelOptionstype VoiceInputLabelstype VoiceInputPropstype VoiceInputVariant

Accessibility

  • The Dictate toggle is pressed while listening: Enter or Space starts and finishes, Escape cancels, and the cancel button hands focus back to the toggle.
  • Every state is announced politely (Listening, Processing, Microphone access denied); the ring and the waveform are aria-hidden.
  • Under reduced motion the level moves in four steps and the bars hold still.
  • The demo never asks for the microphone on load: it plays a synthetic voice until you turn on Try with your microphone.

Agent actions

Agents find it by its label and call start, confirm and cancel; onStart sees details.source === "agent", so you decide whether an agent may open the microphone.

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.