Ballmac UI home

Voice Input

A microphone control as a round button or an expanding recorder with a scrolling waveform, timer, discard and send, plus a hook that reads the real microphone level.

Press the button and speak.

Installation

$ pnpm dlx shadcn@latest add @ballmac/voice-input

Usage

import { VoiceInput, useMicrophoneLevel, formatClock } from "@/components/ballmac/voice-input"

The full example is in the Code tab above.

Examples

Button with live glow

Uses your real microphone level. Nothing is recorded or sent.

API reference

PropTypeDefault
state

Current state (controlled). Without it the component keeps its own state and moves idle → listening → processing.

VoiceState—
onStart

Called when recording should begin.

() => void—
onStop

Called when the person finishes and wants the audio used.

() => void—
onCancel

Called when the person throws the recording away.

() => void—
level

Loudness from 0 to 1, for example from `useMicrophoneLevel`. Drives the waveform and the button's glow.

number0
variant

"button" is a single round microphone button. "bar" expands into a recorder with waveform, timer, cancel and send.

"button" | "bar""button"
duration

Seconds recorded. When omitted the component times itself.

number—
processingLabel

Text in the bar while processing.

string—
label

Accessible name of the button when idle.

string—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Enter / SpaceStarts, and while listening stops and uses the recording
EscapeDiscards the recording while listening
Screen readersButton names change with state; status is announced politely; the waveform is decorative

Use with AI

The component draws the control; you record. onStart, onStop, onCancel fire; state (idle | listening | processing) can be controlled. Feed level (0 to 1) from useMicrophoneLevel(active) for a real waveform. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Voice Input (@ballmac/voice-input) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Dictation in a composer
  • Voice messages

Not for

  • Text entry; use prompt-input
  • Playing audio; use audio-player

Registry JSON: https://ui.ballmac.com/r/voice-input.json

Credits

Free to use in personal and commercial projects.