Conversation
Voice Session
Voice mode of a chat — dot-column level bars that change with who's talking, a word-by-word transcript, barge-in marks, and mute, hold, voice and end controls.
1 variantMIT
Preview
Billing call
Wren · Ember voice
Listening00:00
You: I was charged twice for the Pro plan this month.
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://tuffui.com/r/voice-session.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { VoiceSession } from "@/components/ui/voice-session";
// Wire your realtime voice client: who has the floor, the transcript, and a
// level source read once per frame from an AnalyserNode.
export function VoiceMode({ call }: Props) {
const getLevel = () => {
const analyser = call.activity === "agent" ? call.playback : call.mic;
analyser.getByteTimeDomainData(buffer);
return rms(buffer) * 3; // 0–1
};
return (
<VoiceSession
title="Billing call"
agentName="Wren"
activity={call.activity} // "listening" | "user" | "thinking" | "agent"
getLevel={getLevel}
turns={call.transcript.map((t) => ({
id: t.id,
speaker: t.role, // "user" | "agent"
text: t.text,
spoken: t.final ? undefined : t.wordsSoFar, // live lines fill word by word
interrupted: t.bargedIn, // cut by the user talking over the agent
}))}
startedAt={call.startedAt}
muted={call.muted}
onMutedChange={call.setMuted}
held={call.onHold}
onHeldChange={call.setHold}
voices={[
{ value: "ember", label: "Ember", hint: "warm" },
{ value: "slate", label: "Slate", hint: "calm" },
]}
voice={call.voice}
onVoiceChange={call.setVoice}
onEnd={call.hangUp}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| activity* | "connecting" | "listening" | "user" | "thinking" | "agent" | — | Who has the floor. The user's voice scrolls in as brand-colored dot columns, the agent's is a centered spectrum, thinking is a small hump sweeping along the line, and listening shows the open mic faintly. |
| getLevel | () => number | — | Loudness 0–1 of whoever is speaking, read once per animation frame — no re-renders. Without it the bars move at a steady half level. Reduced motion draws a still frame instead. |
| turns* | VoiceTurn[] | — | The transcript, oldest first. A turn with `spoken` set is live: its words appear as the count grows and the newest is highlighted. Set `interrupted` on an agent line the user talked over. |
| agentName | string | "Agent" | Label on agent lines, in the legend and in the status pill. |
| title | string | "Voice" | Header title. |
| subtitle | string | "Wren · Ember voice" | Secondary line. Defaults to the agent name and the selected voice. |
| startedAt | number | Date | null | — | Start of the call. The timer counts up from it every second; it shows 00:00 until mounted so server and client match. |
| muted | boolean | — | Controlled mute. While muted the mic bars go flat and the pill says Muted; the agent's voice still shows. |
| defaultMuted | boolean | false | Starting mute state when uncontrolled. |
| onMutedChange | (muted: boolean) => void | — | Called by the Mute button. |
| held | boolean | — | Controlled hold. Bars go still and dim, the pill says On hold. |
| defaultHeld | boolean | false | Starting hold state when uncontrolled. |
| onHeldChange | (held: boolean) => void | — | Called by the Hold / Resume button. |
| voices | VoiceOption[] | [] | Voices for the selector in the controls. Empty hides it. |
| voice | string | — | Controlled voice `value`. |
| defaultVoice | string | voices[0].value | Starting voice when uncontrolled. |
| onVoiceChange | (voice: string) => void | — | Called when a voice is picked. |
| onEnd | () => void | — | Called by the End button. |
| className | string | — | Extra classes for the root element. |
type VoiceTurn = {
id: string;
speaker: "user" | "agent";
text: string; // the whole line; only the first `spoken` words show
spoken?: number; // words heard so far; omit once the line is final
interrupted?: boolean; // agent line cut by barge-in
};
type VoiceOption = {
value: string;
label: string; // "Ember"
hint?: string; // "warm"
};