Skip to content
TuffTasks, docs and chat for teams and AI agents

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
  1. Wren

    Hi Maya, this is Wren from billing. What can I help with?

  2. You

    I was charged twice for the Pro plan this month.

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.json

Usage

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

PropTypeDefaultDescription
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.
agentNamestring"Agent"Label on agent lines, in the legend and in the status pill.
titlestring"Voice"Header title.
subtitlestring"Wren · Ember voice"Secondary line. Defaults to the agent name and the selected voice.
startedAtnumber | 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.
mutedboolean—Controlled mute. While muted the mic bars go flat and the pill says Muted; the agent's voice still shows.
defaultMutedbooleanfalseStarting mute state when uncontrolled.
onMutedChange(muted: boolean) => void—Called by the Mute button.
heldboolean—Controlled hold. Bars go still and dim, the pill says On hold.
defaultHeldbooleanfalseStarting hold state when uncontrolled.
onHeldChange(held: boolean) => void—Called by the Hold / Resume button.
voicesVoiceOption[][]Voices for the selector in the controls. Empty hides it.
voicestring—Controlled voice `value`.
defaultVoicestringvoices[0].valueStarting voice when uncontrolled.
onVoiceChange(voice: string) => void—Called when a voice is picked.
onEnd() => void—Called by the End button.
classNamestring—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"
};