Voice first composer (Pro)
ProIncluded in $99A composer where talking comes first: a large mic that becomes the live waveform, the words appearing as you speak, and one tap to switch to typing without losing any of them.
On this page
Installation
Needs chatcn Pro
This command works with a Pro license, along with every Pro component.
Or start free: sign up and get three Pro components on us, with a new one every month.
Usage
import { VoiceFirstComposer } from "@/components/ui/chatcn/pro/voice-first-composer"
<VoiceFirstComposer
value={heard}
onValueChange={setHeard}
interim={partial}
listening={mic.open}
onListeningChange={(open) => (open ? mic.start() : mic.stop())}
level={mic.getLevel}
onSubmit={({ text, via }) => send(text)}
/>The mic is one object in two shapes. At rest it is a round ink button; pressed, the circle stretches into a pill that holds the elapsed time, the live waveform and a stop square, so the thing you pressed is the thing that is listening. The words appear above as your recognizer sends them: settled words in ink, the ones still being heard in gray. Type, or a tap on the words, switches to the keyboard and takes everything said so far, the unsettled words too, with the caret at the end; Talk switches back and opens the mic. Send while listening closes the mic and sends what was said. Audio capture and recognition stay in your app: append final words to value, pass the in-flight words as interim and a level getter for the waveform. Text mode is the free PromptInput, with the same Enter, paste and IME behaviour.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
value, defaultValue, onValueChange | string | What was said or typed. Your recognizer appends final words here |
interim | string | Words heard but not settled. Kept when switching to typing |
listening, onListeningChange | boolean | The mic is open, and the mic button was pressed |
level | number | () => number | Input level from 0 to 1 for the waveform |
processing | boolean | The last words are settling after the mic closed |
error | ReactNode | true | Replaces the transcript. true shows the blocked mic message |
mode, defaultMode, onModeChange | "voice" | "text" | Default voice |
onSubmit | ({ text, via }) => void | via says whether the last words were spoken or typed |
status, onStop | "idle" | "submitting" | "streaming" | Send becomes Stop in the same footprint |
tools, attachments | ReactNode | Text mode toolbar, and above the words |
disabled, labels | Every string is a label |
Keyboard
| Key | Action |
|---|---|
| Space or Enter on the mic | Open or close the microphone |
| Escape | Close the microphone, keeping the words. Stops a streaming reply otherwise |
| Enter on the words | Switch to typing with the caret at the end |
| Enter, Shift Enter in text mode | Send, new line. Never sends while an IME is composing |
Accessibility
- The mic is a toggle button with
aria-pressed; its name changes between Start talking and Stop listening. - Opening the mic is announced once, politely; the transcript is not announced word by word.
- A blocked mic is an alert that says how to fix it, and Type stays available.
- The focus ring is clipped to the same shape as the mic, so it follows the circle and the pill.
Motion
The circle opens into the pill in 280 ms on the kit's ease out by animating only its clip path, which also clips the hit area; the time, waveform and stop square fade in 75 ms later. The mic glyph leaves with a 2 px blur. Reduced motion snaps the shape and keeps the fades, and the waveform rests on its own reduced form.