Skip to content
Sign in
VoicePush to talkMenu

Push to talkPro

Hold the button or Space to talk, with a ring that follows your voice, and let go to send. Slide away or press Escape to cancel, too short holds cancel with a hint, and keyboard users can latch it with Enter.

ProA channel with a dispatch agent. Hold the button or Space and talk; let go to send, slide away or press Escape to cancel.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/push-to-talk

Usage

tsx
import { PushToTalk } from "@/components/ui/chatcn/pro/push-to-talk"

<PushToTalk
  level={mic.getLevel}
  onStart={recorder.start}
  onSend={() => recorder.stopAndSend()}
  onCancel={recorder.discard}
/>

Space works anywhere on the page unless the user is typing or another control has focus; pass hotkey={false} to limit it to the focused button. Losing the window mid hold cancels, so a microphone is never left open. status="sending" shows a spinner until you set it back.

Examples

Every state

ProReady, holding, about to cancel, the keyboard latch, sending, a blocked microphone, disabled and inline.

Props

PropTypeNotes
levelnumber | () => numberThe input level for the ring
onStart() => voidOpen the mic
onSend(durationMs: number) => voidReleased with enough audio
onCancel(reason: "slide" | "escape" | "short" | "interrupted") => voidLet go without sending
status"ready" | "sending" | "error"Default ready
errorReactNodeShown in the error status. Say how to fix it
hotkeystring | falseDefault " " (Space)
minDuration, maxDurationnumberDefault 400 ms and 60 s. The limit sends by itself
layout"stacked" | "inline"Inline puts the status at the start, for composer rows
size"md" | "lg"56 or 72 px
previewPhase, previewElapsedstring, numberShow a phase without input, for docs

Keyboard

KeyAction
Hold SpaceTalk; release to send
EnterStart recording on the focused button; Enter again sends
EscapeCancel the recording

Accessibility

  • A button with aria-pressed while recording and aria-keyshortcuts for the hotkey.
  • Recording, sent with its length, cancelled and too short are announced politely.
  • The Enter latch means nobody has to hold a key or a pointer to talk.

Motion

  • The button presses to 0.97 while held and the ring swells with the level; under reduced motion the ring holds still at one size.
  • Sliding past 72 px turns the button to the cancel mark at once: no animation on a decision the finger is making.