Voice composer Free
Free forever. One command, source you own.
Install
npx shadcn@latest add https://cottoncandy.dev/r/voice-composer.jsonFree. Lands in components/mu/voice-composer/ with the shared foundation. Needs React 19, Tailwind v4 and motion; reads your shadcn theme, and dark mode follows .dark.
Usage
import { VoiceComposer } from "@/components/mu/voice-composer/VoiceComposer";
<VoiceComposer
onStream={(stream) => recorder.start(stream)} // the microphone it opened, to record
onVoice={(seconds) => recorder.stop()}
onCancel={() => recorder.cancel()}
onSend={(text) => send(text)}
onAttach={() => pickFile()}
/>Use with an agent Beta
npx shadcn@latest add https://cottoncandy.dev/r/uisdk/voice-composer.jsonOptional. An AI agent in your app can read and set this piece by name, and you can ask before anything it can’t undo. The piece itself doesn’t change. Built on UI SDK 0.1.0-beta.23, which is in beta too, so this add-on follows its releases.
Source
How it works
Building with an agent? Hand it a ready prompt for this piece.
Input and reduced motion
- Pointer / touch: tap the mic to start, then send (↑) or cancel (✕). Or hold the mic to talk: the rim lights as you press, listening starts after a beat, and it sends when you let go; slide more than 24px off the key before letting go to cancel. A held mic never scrolls the page (
touch-action: noneon the key), so a finger that drifts keeps the message. After a voice send the key keeps its dome for about a second while the point of light lands on it; it is already the mic again (named Speak), so pressing it starts a new message at once. - Keyboard: the mic, send and cancel keys are real buttons with names; Enter in the field sends typed text, and Escape cancels listening (it takes the key, so a dialog around the composer stays open; an Escape something else already took is left alone). Cancelling from the ✕ key without
onAttachmoves focus to the mic, so it is never lost. A polite live region says "Listening". - Reduced motion: the thread keeps one fixed shape with no travel (no moving carrier, no drifting syllables), and only its height follows the voice: the same level, through the same gate, flat in silence. The rim and the spill light without fading, a send clears the thread at once with no point of light or flare, and the field swaps without fading.
- Off screen the thread's frame loop pauses and the microphone's audio graph is suspended; the loop runs only while listening or while a send is landing, and paints only while the thread moves.
- Performance: the light is its own small canvas, shown scaled up, so the compositor enlarges it rather than the main thread; while listening the rim and the spill sit on their own layers, so the level only fades them (at rest they are plain paint). A listening frame reuses its working arrays and the thread's fade. What a frame still costs is drawing the three strands, which a phone's GPU does off the main thread: listening costs 41–52 ms/s of main thread on a 4× slowed CPU at a 3× phone's density with a GPU canvas, and 116–141 ms/s without one.
Props
| Prop | Default | What it does |
|---|---|---|
level | the microphone | your own input level 0..1 (an RMS or peak amplitude): a number, or a function () => number read every frame while listening (so a meter needn't re-render the composer); given, the composer never opens the microphone, and the level goes through the same noise gate. **Changed 27 Nov:** it was a 0–1 drive shown as given; it is now an amplitude through the gate (a steady value reads as the room and falls silent within about 6s), and without it the composer opens the microphone where it used to simulate a voice |
value | — | controlled: the field's text (pair it with onValueChange) |
defaultValue | "" | the field's text at first, when value is left out: a draft to prefill |
onValueChange | — | called with the field's text whenever it changes: typing, the clear on a send, an unsent message coming back |
disabled | false | out of use for a moment (a reply streaming): the field is read-only and the keys ignore presses, at 50% with a not-allowed cursor, and all stay focusable (aria-disabled). A listen already under way can still be sent or cancelled |
name | — | the field's name: in a <form>, a send (Enter or the key) submits the form with the text under that name, then clears the field |
onStart | — | called when listening starts (on the press, before the microphone answers) |
onStream | — | called with the microphone's MediaStream once it is open, so you can record the same stream; the composer stops its tracks when listening ends |
onVoice | — | called with the seconds spoken when a voice message is sent. Return a promise and the send key is busy (aria-busy, a progress cursor, data-pending on the root) until it settles; resolve false, reject or throw, and the field says "Message not sent" (unsent) |
onCancel | — | called when listening is cancelled, including when the microphone is blocked or missing |
onSend | — | called with the text when a typed message is sent. Return a promise as for onVoice; a message that wasn't sent comes back into an empty field, so a press sends it again |
onAttach | — | called by the + key; without it the + key is hidden (its place is kept) |
placeholder | Ask anything | the field's placeholder |
labels | English | { attach, message, speak, send, cancel, listening, denied, noMic, busy, insecure, failed, unsent } (denied: "Microphone is blocked", noMic: "No microphone found", busy: "Microphone is in use", insecure: "Microphone needs HTTPS", failed: "Microphone didn't start", when it opened but its audio couldn't be read), and unsent ("Message not sent", said and shown when onSend or onVoice fails) |
sound | off | tones for listen, send and cancel: true, or a volume 0–1 (see Sound) |
accent | false | lights the composer with --mu-signal instead of its own cool blue; the ink stays neutral |
className | — | added to the root |
Sound
Off by default. With sound (or a volume, sound={0.5}) listening opens with a rising tone (after the beat, when held), sending lifts and cancelling falls, typed sends included. setMuted(true) from components/mu/sounds.ts silences every cottoncandy item at once.
Licence
Free to use in your projects, under the terms on the licence.
A message field that listens. Press the mic and speak: the field becomes one fine thread of ink that carries your voice, with a single light under it that glows in the dark. Send, and the thread folds into a point of light that runs into the send key.
For AI chat input and voice promptsMore in AI & agents