# Transcript

Read caller-supplied speech with optional speaker and timing.

## Preview

The meeting transcript shows the active turn at a supplied playback time.

transcript-preview-1.jsx

```jsx
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  return (
    <div
      style={{
        maxWidth: 560,
        marginInline: "auto",
      }}
    >
      <Transcript
        variant="timed"
        segments={meeting}
        currentTime={3.4}
        aria-label="Meeting transcript"
      />
    </div>
  );
}

var meeting = [
  {
    id: "rina-1",
    speaker: "Rina",
    start: 0,
    end: 2.8,
    text: "The rollout can move once staging confirms the retry fix.",
    words: [
      "The ",
      "rollout ",
      "can ",
      "move ",
      "once ",
      "staging ",
      "confirms ",
      "the ",
      "retry ",
      "fix.",
    ].map((text, index) => ({
      id: `w${index}`,
      text,
      start: [0, 0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6][index],
      end: [0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6, 2.8][index],
    })),
  },
  {
    id: "marco-1",
    speaker: "Marco",
    start: 3.1,
    end: 5.6,
    text: "I\u2019ll confirm coverage with the regional leads today.",
  },
  {
    id: "rina-2",
    speaker: "Rina",
    start: 6.2,
    end: 8.5,
    text: "Great. Keep the decision pending until both checks are in.",
  },
];

var readAloudWords = Array.from(
  "Keep the first screen focused on one task. Move the optional settings into the next step.".matchAll(
    /\S+/g,
  ),
  (match) => ({
    text: match[0],
    start: match.index,
    end: match.index + match[0].length,
  }),
);

```

## Design guidance

Keep recognition, audio playback, persistence, and transcript updates in the application. Transcript preserves the supplied segment order and IDs; it does not infer speaker identity, word timing, or finality. Only valid supplied intervals become seek controls. Partial speech has a trailing ellipsis by default. Keep capture and playback errors in the caller's composition. The shared --text-highlight theme role controls the rounded speech highlight for either speaker.

## Installation

Transcript uses the canonical Ghost Button for seek controls and MessageSender for string speaker names. To show an agent or custom artwork, supply a MessageSender element as speaker; custom React content remains caller-owned.

```sh
npx shadcn@latest add https://ghost-ui.com/r/transcript.json
```

## Basic usage

Use untimed segments when the source has no alignment data. Text is rendered as React text, with whitespace preserved.

```tsx
import { Transcript } from "@/components/ui/transcript";

const segments = [
  {
    id: "answer",
    speaker: "Rina",
    text: "The rollout remains on hold until staging confirms the retry fix.",
  },
];

export function TranscriptExample() {
  return (
    <Transcript segments={segments} aria-label="Voice message transcript" />
  );
}
```

## Structures

The convenience Transcript component and its Root, Segment, Speaker, Time, Text, and Words parts share the same exported owners. Parts accept native attributes and forward their refs. When composing parts directly, provide each segment and word's stable caller ID.

- Transcript.Root
  - Transcript.Segment
    - Transcript.Speaker
    - Transcript.Time
    - Transcript.Text
    - Transcript.Words

## Examples

Start with plain and timed parts, then partial speech and caller-owned playback or conversation compositions.

### Plain transcript

Keep short message transcripts inside the existing Message body without another card surface.

transcript-plain-transcript-2.jsx

```jsx
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  return (
    <Transcript
      segments={[
        {
          id: "note",
          text: "The team agreed to keep the rollout on hold until staging and regional coverage are confirmed.",
        },
      ]}
    />
  );
}

var meeting = [
  {
    id: "rina-1",
    speaker: "Rina",
    start: 0,
    end: 2.8,
    text: "The rollout can move once staging confirms the retry fix.",
    words: [
      "The ",
      "rollout ",
      "can ",
      "move ",
      "once ",
      "staging ",
      "confirms ",
      "the ",
      "retry ",
      "fix.",
    ].map((text, index) => ({
      id: `w${index}`,
      text,
      start: [0, 0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6][index],
      end: [0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6, 2.8][index],
    })),
  },
  {
    id: "marco-1",
    speaker: "Marco",
    start: 3.1,
    end: 5.6,
    text: "I\u2019ll confirm coverage with the regional leads today.",
  },
  {
    id: "rina-2",
    speaker: "Rina",
    start: 6.2,
    end: 8.5,
    text: "Great. Keep the decision pending until both checks are in.",
  },
];

var readAloudWords = Array.from(
  "Keep the first screen focused on one task. Move the optional settings into the next step.".matchAll(
    /\S+/g,
  ),
  (match) => ({
    text: match[0],
    start: match.index,
    end: match.index + match[0].length,
  }),
);

```

### Explicit parts

Use the same Root, Segment, Speaker, Time, Text, and Words owners when a custom layout needs direct control over transcript markup. The caller supplies segment identity, timing, and seeking state.

transcript-explicit-parts-3.jsx

```jsx
import { useState } from "react";
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  const [currentTime, setCurrentTime] = useState(1.6);
  return (
    <Transcript.Root
      data-preview-wide
      variant="timed"
      currentTime={currentTime}
      onSeek={setCurrentTime}
      aria-label="Meeting transcript"
    >
      <Transcript.Segment segment={transcriptSegment}>
        <Transcript.Speaker>{transcriptSegment.speaker}</Transcript.Speaker>
        <Transcript.Time seconds={transcriptSegment.start} />
        <Transcript.Text>
          <Transcript.Words
            words={transcriptSegment.words}
            segment={transcriptSegment}
          />
        </Transcript.Text>
      </Transcript.Segment>
    </Transcript.Root>
  );
}

var transcriptSegment = {
  id: "review-update",
  speaker: "Rina",
  start: 0,
  end: 3.2,
  text: "Keep the launch decision pending until both checks are complete.",
  words: [
    "Keep ",
    "the ",
    "launch ",
    "decision ",
    "pending ",
    "until ",
    "both ",
    "checks ",
    "are ",
    "complete.",
  ].map((text, index) => ({
    id: `word-${index}`,
    text,
    start: index * 0.32,
    end: (index + 1) * 0.32,
  })),
};

var initialEntries = [
  {
    id: "q1",
    actor: "user",
    text: "What changed in this release?",
    time: {
      dateTime: "2026-11-10T09:07:00+07:00",
      label: "Nov 10, 9:07 AM",
    },
  },
  {
    id: "a1",
    actor: "assistant",
    text: "Search now handles larger collections and keeps your position when results arrive.",
  },
  {
    id: "q2",
    actor: "user",
    text: "Does that affect existing integrations?",
    time: {
      dateTime: "2026-11-10T09:11:00+07:00",
      label: "Nov 10, 9:11 AM",
    },
  },
  {
    id: "a2",
    actor: "assistant",
    text: "The data and callback contracts stay the same. Existing integrations can adopt the improvements incrementally.",
  },
  {
    id: "q3",
    actor: "user",
    text: "What should we verify before shipping?",
    time: {
      dateTime: "2026-11-10T09:14:00+07:00",
      label: "Nov 10, 9:14 AM",
    },
  },
  {
    id: "a3",
    actor: "assistant",
    text: "Check keyboard navigation, empty results and a response arriving while someone reads earlier messages.",
  },
  {
    id: "q4",
    actor: "user",
    text: "Who owns the final review?",
    time: {
      dateTime: "2026-11-10T09:16:00+07:00",
      label: "Nov 10, 9:16 AM",
    },
  },
  {
    id: "a4",
    actor: "assistant",
    text: "Mira owns the release review. Noah will verify the installed consumer.",
  },
];

var historyEntries = [
  ...initialEntries,
  ...[
    [
      "What is the rollout plan?",
      "Start with internal accounts, then enable the release for one region before expanding.",
    ],
    [
      "How do we measure success?",
      "Watch search completion, response latency and the number of interrupted sessions.",
    ],
    [
      "What happens if error rates increase?",
      "Pause the rollout and restore the previous path while the owner investigates.",
    ],
    [
      "What should support tell customers?",
      "Existing integrations keep working. Ask for the request ID if a search fails.",
    ],
    [
      "When can we remove the old path?",
      "After every region is stable and the support team has reviewed the incident queue.",
    ],
  ].flatMap(([prompt, reply], index) => [
    {
      id: `history-q${index}`,
      actor: "user",
      text: prompt,
      time: {
        dateTime: `2026-11-10T09:${20 + index * 2}:00+07:00`,
        label: `Nov 10, 9:${20 + index * 2} AM`,
      },
    },
    {
      id: `history-a${index}`,
      actor: "assistant",
      text: reply,
    },
  ]),
];

```

### Timed speech

Use variant="timed" for turns with valid start and end times. A valid current time highlights the containing segment. The current word or phrase receives a rounded pastel text highlight; speaker names align with the speech after the fixed timestamp gutter. Long phrases wrap in the same left-aligned text flow.

transcript-timed-speech-4.jsx

```jsx
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  const [currentTime, setCurrentTime] = useState(0);
  return (
    <div
      style={{
        display: "grid",
        gap: "var(--space-3)",
      }}
    >
      <Transcript
        variant="timed"
        segments={meeting}
        currentTime={currentTime}
        onSeek={(seconds) => setCurrentTime(seconds)}
        aria-label="Meeting transcript"
      />
      <div
        style={{
          display: "flex",
          alignItems: "center",
          gap: "var(--space-2)",
        }}
      >
        <Button
          size="sm"
          variant="outline"
          onClick={() => setCurrentTime((time) => Math.min(time + 1, 8.5))}
        >
          Advance time
        </Button>
        <span
          aria-live="polite"
          style={{
            color: "var(--muted-foreground)",
            fontSize: "var(--font-size-xs)",
          }}
        >
          {currentTime.toFixed(1)}
          {" seconds"}
        </span>
      </div>
    </div>
  );
}

var meeting = [
  {
    id: "rina-1",
    speaker: "Rina",
    start: 0,
    end: 2.8,
    text: "The rollout can move once staging confirms the retry fix.",
    words: [
      "The ",
      "rollout ",
      "can ",
      "move ",
      "once ",
      "staging ",
      "confirms ",
      "the ",
      "retry ",
      "fix.",
    ].map((text, index) => ({
      id: `w${index}`,
      text,
      start: [0, 0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6][index],
      end: [0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6, 2.8][index],
    })),
  },
  {
    id: "marco-1",
    speaker: "Marco",
    start: 3.1,
    end: 5.6,
    text: "I\u2019ll confirm coverage with the regional leads today.",
  },
  {
    id: "rina-2",
    speaker: "Rina",
    start: 6.2,
    end: 8.5,
    text: "Great. Keep the decision pending until both checks are in.",
  },
];

var readAloudWords = Array.from(
  "Keep the first screen focused on one task. Move the optional settings into the next step.".matchAll(
    /\S+/g,
  ),
  (match) => ({
    text: match[0],
    start: match.index,
    end: match.index + match[0].length,
  }),
);

```

### Live draft and interruption

Keep finalized speech in text and the unfinished tail in draftText. Mark the segment partial to highlight the unfinished tail, show trailing dots, and show one Draft label. This treatment applies to both human and agent speech without an extra variant. Mark caller-truncated text interrupted to show one interruption label; a final segment has no extra status label.

transcript-live-draft-and-interruption-5.jsx

```jsx
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  return (
    <Transcript
      variant="captions"
      segments={[
        {
          id: "draft",
          speaker: "Rina",
          text: "Let\u2019s keep the launch decision",
          draftText: " pending until\u2026",
          status: "partial",
        },
        {
          id: "finished",
          speaker: "Marco",
          text: "I\u2019ll share the coverage review this afternoon.",
          status: "final",
        },
        {
          id: "interrupted",
          speaker: "Rina",
          text: "Before we close, one more item",
          status: "interrupted",
        },
      ]}
    />
  );
}

var meeting = [
  {
    id: "rina-1",
    speaker: "Rina",
    start: 0,
    end: 2.8,
    text: "The rollout can move once staging confirms the retry fix.",
    words: [
      "The ",
      "rollout ",
      "can ",
      "move ",
      "once ",
      "staging ",
      "confirms ",
      "the ",
      "retry ",
      "fix.",
    ].map((text, index) => ({
      id: `w${index}`,
      text,
      start: [0, 0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6][index],
      end: [0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6, 2.8][index],
    })),
  },
  {
    id: "marco-1",
    speaker: "Marco",
    start: 3.1,
    end: 5.6,
    text: "I\u2019ll confirm coverage with the regional leads today.",
  },
  {
    id: "rina-2",
    speaker: "Rina",
    start: 6.2,
    end: 8.5,
    text: "Great. Keep the decision pending until both checks are in.",
  },
];

var readAloudWords = Array.from(
  "Keep the first screen focused on one task. Move the optional settings into the next step.".matchAll(
    /\S+/g,
  ),
  (match) => ({
    text: match[0],
    start: match.index,
    end: match.index + match[0].length,
  }),
);

```

### Conversation composition

Use Message scroller for chronological conversation reading and Transcript for the supplied speech content. Each owner keeps its own job.

transcript-conversation-composition-6.jsx

```jsx
import {
  MessageScroller,
  MessageScrollerContent,
  MessageScrollerItem,
  MessageScrollerProvider,
  MessageScrollerViewport,
} from "@/components/ui/message-scroller";
import { Message, MessageBody } from "@/components/ui/message";
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  return (
    <MessageScrollerProvider defaultScrollPosition="start">
      <MessageScroller
        style={{
          blockSize: "18rem",
        }}
      >
        <MessageScrollerViewport label="Launch planning conversation">
          <MessageScrollerContent>
            <MessageScrollerItem messageId="assistant-transcript">
              <Message actor="assistant">
                <MessageBody>
                  <p>
                    The rollout remains on hold until staging and regional
                    coverage are confirmed.
                  </p>
                  <Transcript
                    variant="captions"
                    segments={meeting}
                    aria-label="Meeting transcript"
                  />
                </MessageBody>
              </Message>
            </MessageScrollerItem>
            <MessageScrollerItem messageId="user-reply">
              <Message actor="user">
                <MessageBody>
                  Share the final coverage review when it’s ready.
                </MessageBody>
              </Message>
            </MessageScrollerItem>
          </MessageScrollerContent>
        </MessageScrollerViewport>
      </MessageScroller>
    </MessageScrollerProvider>
  );
}

var meeting = [
  {
    id: "rina-1",
    speaker: "Rina",
    start: 0,
    end: 2.8,
    text: "The rollout can move once staging confirms the retry fix.",
    words: [
      "The ",
      "rollout ",
      "can ",
      "move ",
      "once ",
      "staging ",
      "confirms ",
      "the ",
      "retry ",
      "fix.",
    ].map((text, index) => ({
      id: `w${index}`,
      text,
      start: [0, 0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6][index],
      end: [0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6, 2.8][index],
    })),
  },
  {
    id: "marco-1",
    speaker: "Marco",
    start: 3.1,
    end: 5.6,
    text: "I\u2019ll confirm coverage with the regional leads today.",
  },
  {
    id: "rina-2",
    speaker: "Rina",
    start: 6.2,
    end: 8.5,
    text: "Great. Keep the decision pending until both checks are in.",
  },
];

var readAloudWords = Array.from(
  "Keep the first screen focused on one task. Move the optional settings into the next step.".matchAll(
    /\S+/g,
  ),
  (match) => ({
    text: match[0],
    start: match.index,
    end: match.index + match[0].length,
  }),
);

```

### Focus captions

The same Transcript highlight follows the active speech in this focused voice layout. The caller supplies the recognition and playback events.

transcript-focus-captions-7.jsx

```jsx
import * as React from "react";
import { Mic, MicOff, PhoneOff, Play, RotateCcw, Square } from "lucide-react";
import { Button, IconButton } from "@/components/ui/button";
import { VoiceIndicator } from "@/components/ui/voice-indicator";
import { MessageSender } from "@/components/ui/message-sender";
import { Transcript } from "@/components/ui/transcript";
import {
  MessageScroller,
  MessageScrollerProvider,
  MessageScrollerViewport,
  MessageScrollerContent,
  MessageScrollerItem,
  MessageScrollerButton,
} from "@/components/ui/message-scroller";

export default function Example() {
  const [time, setTime] = React.useState(0);
  const [running, setRunning] = React.useState(false);
  const [muted, setMuted] = React.useState(false);
  const [ended, setEnded] = React.useState(false);
  const [interruptedAt, setInterruptedAt] = React.useState(null);
  const inputAtMute = React.useRef(0);
  React.useEffect(() => {
    if (!running) return;
    let previous = performance.now();
    const timer = window.setInterval(() => {
      const now = performance.now(),
        delta = Math.min(0.25, (now - previous) / 1000);
      previous = now;
      setTime((value) => Math.min(22, value + delta));
    }, 80);
    return () => window.clearInterval(timer);
  }, [running]);
  React.useEffect(() => {
    if (time >= 22) setRunning(false);
  }, [time]);
  const interrupted = interruptedAt !== null || time >= 15.5;
  const speaking =
    running && time >= 7 && time < 15.5 && interruptedAt === null;
  const phase = !running
    ? "idle"
    : speaking
      ? "speaking"
      : (time >= 5.2 && time < 7) || time >= 19.5
        ? "thinking"
        : muted
          ? "muted"
          : "listening";
  const inputTime = muted ? inputAtMute.current : time;
  const input =
    inputTime < 1.2
      ? ""
      : inputTime < 2.4
        ? "Can you help me"
        : inputTime < 3.6
          ? "Can you help me simplify"
          : inputTime < 5.2
            ? "Can you help me simplify the"
            : "Can you help me simplify the onboarding flow?";
  const draft =
    inputTime >= 1.2 && inputTime < 2.4
      ? " simplify"
      : inputTime >= 2.4 && inputTime < 3.6
        ? " the onboarding"
        : inputTime >= 3.6 && inputTime < 5.2
          ? " onboarding flow?"
          : undefined;
  const spokenTime = Math.min(time, interruptedAt ?? 15.5);
  const count =
    spokenTime < 7
      ? 0
      : Math.min(reply.length, Math.floor((spokenTime - 7) / 0.52) + 1);
  const words = reply.slice(0, count).map((text, index) => ({
    id: `reply-word-${index}`,
    text: `${index ? " " : ""}${text}`,
    start: 7 + index * 0.52,
    end: 7 + (index + 1) * 0.52,
  }));
  const segments = [
    ...(input
      ? [
          {
            id: "user-1",
            speaker: "You",
            start: 1.2,
            text: input,
            draftText: draft,
            status: draft ? "partial" : "final",
          },
        ]
      : []),
    ...(words.length
      ? [
          {
            id: "reply-1",
            speaker: <MessageSender name="Assistant" kind="agent" size="xs" />,
            start: 7,
            text: words.map((word) => word.text).join(""),
            words,
            status: interrupted ? "interrupted" : undefined,
          },
        ]
      : []),
    ...(interrupted && time >= 16
      ? [
          {
            id: "user-2",
            speaker: "You",
            start: 16,
            text: "Keep the preview",
            draftText: time >= 18 ? ", though." : undefined,
            status: "partial",
          },
        ]
      : []),
  ];
  const activeId =
    phase === "listening"
      ? time >= 16
        ? "user-2"
        : "user-1"
      : speaking
        ? "reply-1"
        : undefined;
  const level =
    running && !ended
      ? 0.2 + 0.5 * Math.sin(time * (speaking ? 6.7 : 4.6)) ** 2
      : 0;
  const begin = () => {
    setTime(0);
    setEnded(false);
    setInterruptedAt(null);
    setMuted(false);
    setRunning(true);
  };
  const controls = running ? (
    <>
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label={muted ? "Unmute microphone" : "Mute microphone"}
        aria-pressed={muted}
        icon={muted ? <MicOff /> : <Mic />}
        onClick={() => {
          if (!muted) inputAtMute.current = time;
          setMuted((value) => !value);
        }}
      />
      {speaking && (
        <IconButton
          type="button"
          variant="ghost"
          size="icon"
          aria-label="Stop reply"
          icon={<Square />}
          onClick={() => setInterruptedAt(time)}
        />
      )}
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label="End voice"
        icon={<PhoneOff />}
        onClick={() => {
          setEnded(true);
          setRunning(false);
        }}
      />
    </>
  ) : (
    <Button
      type="button"
      variant="outline"
      size="sm"
      leadingIcon={time ? <RotateCcw /> : <Play />}
      onClick={begin}
    >
      {time ? "Replay" : "Start voice"}
    </Button>
  );
  return (
    <section
      data-preview-wide
      className="voice-session-demo"
      data-layout={"focus"}
      aria-label="Design review voice chat"
    >
      <header className="voice-session-demo__header">
        <div>
          <h3>Design review</h3>
          <p>{ended ? "Voice chat ended" : "Voice chat"}</p>
        </div>
        <time
          className="voice-session-demo__time"
          dateTime={`PT${Math.floor(time)}S`}
        >{`00:${String(Math.floor(time)).padStart(2, "0")}`}</time>
      </header>
      <div className="voice-session-demo__body">
        <div className="voice-session-demo__presence">
          <VoiceIndicator
            state={phase}
            size="lg"
            inputLevel={phase === "listening" ? level : 0}
            outputLevel={speaking ? level : 0}
          />
        </div>
        <div className="voice-session-demo__transcript">
          <MessageScrollerProvider autoScroll defaultScrollPosition="end">
            <MessageScroller className="voice-session-demo__messages">
              <MessageScrollerViewport label="Live transcript">
                <MessageScrollerContent>
                  <Transcript.Root
                    variant="timed"
                    currentTime={time}
                    activeSegmentId={activeId}
                  >
                    {segments.length ? (
                      segments.map((segment) => (
                        <MessageScrollerItem
                          key={segment.id}
                          messageId={segment.id}
                        >
                          <Transcript.Segment segment={segment} />
                        </MessageScrollerItem>
                      ))
                    ) : (
                      <div className="voice-session-demo__empty">
                        <span>Ready when you are</span>
                        <p>Ask how to simplify your onboarding flow.</p>
                      </div>
                    )}
                  </Transcript.Root>
                </MessageScrollerContent>
              </MessageScrollerViewport>
              <MessageScrollerButton size="sm">
                Jump to live
              </MessageScrollerButton>
            </MessageScroller>
          </MessageScrollerProvider>
        </div>
      </div>
      <footer className="voice-session-demo__footer">
        <span>
          {running && muted ? "Microphone off" : ended ? "Transcript kept" : ""}
        </span>
        <div className="voice-session-demo__controls">{controls}</div>
      </footer>
    </section>
  );
}

var reply =
  "Keep the first screen focused on one task. Move the optional settings into the next step.".split(
    " ",
  );

```

transcript-focus-captions-7.css

```css
/* apps/web/src/demos/ui/voice-compositions.css */
.voice-session-demo {
  container-type: inline-size;
  width: min(100%, 640px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-session-demo__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block-end: var(--space-4);
  border-block-end: 1px solid var(--border);
}
.voice-session-demo__header h3 {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
}
.voice-session-demo__header p {
  margin: 2px 0 0;
  color: var(--muted-foreground);
  font-size: var(--font-size-sm);
}
.voice-session-demo__time {
  color: var(--muted-foreground);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
}
.voice-session-demo__body {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-6);
  padding-block: var(--space-5);
}
.voice-session-demo__presence {
  display: grid;
  justify-items: center;
}
.voice-session-demo__transcript {
  min-width: 0;
}
.voice-session-demo__messages {
  height: 228px;
}
.voice-session-demo__empty {
  display: grid;
  align-content: center;
  min-height: 190px;
  padding-inline: var(--space-3);
}
.voice-session-demo__empty span {
  font-weight: var(--font-weight-regular);
}
.voice-session-demo__empty p {
  margin: var(--space-1) 0 0;
  color: var(--muted-foreground);
}
.voice-session-demo__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-block-start: var(--space-3);
  border-block-start: 1px solid var(--border);
}
.voice-session-demo__footer > span {
  color: var(--muted-foreground);
  font-size: var(--font-size-xs);
}
.voice-session-demo__controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}
.voice-session-demo[data-layout=focus] .voice-session-demo__body {
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}
.voice-session-demo[data-layout=focus] .voice-session-demo__messages {
  height: 160px;
}
@container (max-width: 440px) {
  .voice-session-demo__body {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    padding-block: var(--space-3);
  }
  .voice-session-demo__messages {
    height: 180px;
  }
  .voice-session-demo__empty {
    min-height: 150px;
    text-align: center;
  }
}
@container (max-width: 300px) {
  .voice-session-demo__footer > span {
    max-width: 110px;
  }
}

```

### Call bar

transcript-call-bar-8.jsx

```jsx
import * as React from "react";
import { Mic, MicOff, PhoneOff, Play, RotateCcw, Square } from "lucide-react";
import { Button, IconButton } from "@/components/ui/button";
import { VoiceIndicator } from "@/components/ui/voice-indicator";
import { MessageSender } from "@/components/ui/message-sender";
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  const [time, setTime] = React.useState(0);
  const [running, setRunning] = React.useState(false);
  const [muted, setMuted] = React.useState(false);
  const [ended, setEnded] = React.useState(false);
  const [interruptedAt, setInterruptedAt] = React.useState(null);
  const inputAtMute = React.useRef(0);
  React.useEffect(() => {
    if (!running) return;
    let previous = performance.now();
    const timer = window.setInterval(() => {
      const now = performance.now(),
        delta = Math.min(0.25, (now - previous) / 1000);
      previous = now;
      setTime((value) => Math.min(22, value + delta));
    }, 80);
    return () => window.clearInterval(timer);
  }, [running]);
  React.useEffect(() => {
    if (time >= 22) setRunning(false);
  }, [time]);
  const interrupted = interruptedAt !== null || time >= 15.5;
  const speaking =
    running && time >= 7 && time < 15.5 && interruptedAt === null;
  const phase = !running
    ? "idle"
    : speaking
      ? "speaking"
      : (time >= 5.2 && time < 7) || time >= 19.5
        ? "thinking"
        : muted
          ? "muted"
          : "listening";
  const inputTime = muted ? inputAtMute.current : time;
  const input =
    inputTime < 1.2
      ? ""
      : inputTime < 2.4
        ? "Can you help me"
        : inputTime < 3.6
          ? "Can you help me simplify"
          : inputTime < 5.2
            ? "Can you help me simplify the"
            : "Can you help me simplify the onboarding flow?";
  const draft =
    inputTime >= 1.2 && inputTime < 2.4
      ? " simplify"
      : inputTime >= 2.4 && inputTime < 3.6
        ? " the onboarding"
        : inputTime >= 3.6 && inputTime < 5.2
          ? " onboarding flow?"
          : undefined;
  const spokenTime = Math.min(time, interruptedAt ?? 15.5);
  const count =
    spokenTime < 7
      ? 0
      : Math.min(reply.length, Math.floor((spokenTime - 7) / 0.52) + 1);
  const words = reply.slice(0, count).map((text, index) => ({
    id: `reply-word-${index}`,
    text: `${index ? " " : ""}${text}`,
    start: 7 + index * 0.52,
    end: 7 + (index + 1) * 0.52,
  }));
  const segments = [
    ...(input
      ? [
          {
            id: "user-1",
            speaker: "You",
            start: 1.2,
            text: input,
            draftText: draft,
            status: draft ? "partial" : "final",
          },
        ]
      : []),
    ...(words.length
      ? [
          {
            id: "reply-1",
            speaker: <MessageSender name="Assistant" kind="agent" size="xs" />,
            start: 7,
            text: words.map((word) => word.text).join(""),
            words,
            status: interrupted ? "interrupted" : undefined,
          },
        ]
      : []),
    ...(interrupted && time >= 16
      ? [
          {
            id: "user-2",
            speaker: "You",
            start: 16,
            text: "Keep the preview",
            draftText: time >= 18 ? ", though." : undefined,
            status: "partial",
          },
        ]
      : []),
  ];
  const activeId =
    phase === "listening"
      ? time >= 16
        ? "user-2"
        : "user-1"
      : speaking
        ? "reply-1"
        : undefined;
  const level =
    running && !ended
      ? 0.2 + 0.5 * Math.sin(time * (speaking ? 6.7 : 4.6)) ** 2
      : 0;
  const begin = () => {
    setTime(0);
    setEnded(false);
    setInterruptedAt(null);
    setMuted(false);
    setRunning(true);
  };
  const controls = running ? (
    <>
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label={muted ? "Unmute microphone" : "Mute microphone"}
        aria-pressed={muted}
        icon={muted ? <MicOff /> : <Mic />}
        onClick={() => {
          if (!muted) inputAtMute.current = time;
          setMuted((value) => !value);
        }}
      />
      {speaking && (
        <IconButton
          type="button"
          variant="ghost"
          size="icon"
          aria-label="Stop reply"
          icon={<Square />}
          onClick={() => setInterruptedAt(time)}
        />
      )}
      <IconButton
        type="button"
        variant="ghost"
        size="icon"
        aria-label="End voice"
        icon={<PhoneOff />}
        onClick={() => {
          setEnded(true);
          setRunning(false);
        }}
      />
    </>
  ) : (
    <Button
      type="button"
      variant="outline"
      size="sm"
      leadingIcon={time ? <RotateCcw /> : <Play />}
      onClick={begin}
    >
      {time ? "Replay" : "Start voice"}
    </Button>
  );
  {
    const current = segments.at(-1);
    return (
      <section
        data-preview-wide
        className="voice-call-bar"
        aria-label="Compact voice call"
      >
        <div className="voice-call-bar__header">
          <VoiceIndicator
            state={phase}
            size="sm"
            orientation="horizontal"
            label="Design review"
            inputLevel={phase === "listening" ? level : 0}
            outputLevel={speaking ? level : 0}
          />
          <div className="voice-call-bar__controls">{controls}</div>
        </div>
        <div className="voice-call-bar__caption" aria-label="Current caption">
          {current ? (
            <Transcript.Root
              variant="plain"
              currentTime={speaking ? time : undefined}
            >
              <Transcript.Segment
                segment={{
                  ...current,
                  start: undefined,
                  status:
                    current.status === "interrupted"
                      ? "interrupted"
                      : undefined,
                }}
              />
            </Transcript.Root>
          ) : (
            <p>Talk through the next step in your design.</p>
          )}
        </div>
      </section>
    );
  }
}

var reply =
  "Keep the first screen focused on one task. Move the optional settings into the next step.".split(
    " ",
  );

```

transcript-call-bar-8.css

```css
/* apps/web/src/demos/ui/voice-compositions.css */
.voice-call-bar__controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}
.voice-call-bar {
  container-type: inline-size;
  width: min(100%, 560px);
  min-width: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
}
.voice-call-bar__header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
}
.voice-call-bar__caption {
  padding-block-start: var(--space-3);
  margin-block-start: var(--space-3);
  border-block-start: 1px solid var(--border);
  min-height: 72px;
}
.voice-call-bar__caption > p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: var(--font-size-sm);
  line-height: var(--leading-copy);
}
@container (max-width: 300px) {
  .voice-call-bar__header {
    column-gap: var(--space-2);
  }
}

```

### Recorded speech

This audio sample matches the supplied text and shares Audio player's actual media clock. Only whole-turn timing is supplied.

transcript-recorded-speech-9.jsx

```jsx
import { AudioPlayer, useAudioPlayer } from "@/components/ui/audio-player";
import { Transcript } from "@/components/ui/transcript";

export default function Example() {
  return (
    <div className="voice-composition">
      <AudioPlayer.Root
        src={"/audio/the-metal-forest.mp3"}
        label="The Metal Forest"
      >
        <TimedText />
        <AudioPlayer.ControlBar>
          <AudioPlayer.PlayPause />
          <AudioPlayer.Seek />
          <AudioPlayer.Time />
          <AudioPlayer.Mute />
          <AudioPlayer.Speed />
        </AudioPlayer.ControlBar>
      </AudioPlayer.Root>
    </div>
  );
}

function TimedText() {
  const player = useAudioPlayer();
  return (
    <Transcript
      variant="timed"
      currentTime={player.currentTime}
      onSeek={
        player.status === "loading" || player.status === "error"
          ? undefined
          : player.seek
      }
      segments={[
        {
          id: "metal-forest",
          speaker: "Narrator",
          text: "\u201CThe Metal Forest is in the Great Domed Cavern, the largest in all our dominions,\u201D replied Kaliko.",
          start: 0,
          end: player.duration || undefined,
          status: "final",
        },
      ]}
    />
  );
}

```

transcript-recorded-speech-9.css

```css
/* apps/web/src/demos/ui/voice-compositions.css */
.voice-composition {
  width: min(100%, 520px);
  min-width: 0;
  color: var(--foreground);
  font: var(--font-size-base)/var(--leading-copy) var(--font-sans);
}
.voice-composition .ui-message-body {
  min-width: 0;
}

```

### Read aloud

Read an existing response with the browser’s speech synthesis. The caller starts and stops playback and uses speech boundary events to highlight the current word. Browsers that do not report boundaries keep the full response highlighted while speaking. Available voices and speech support depend on the browser; Transcript does not generate audio.

transcript-read-aloud-10.jsx

```jsx
import { useEffect, useRef, useState } from "react";
import { Square, Volume2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Transcript } from "@/components/ui/transcript";
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  const [state, setState] = useState("ready");
  const [position, setPosition] = useState();
  const utterance = useRef(null);
  useEffect(() => {
    if (
      !("speechSynthesis" in window) ||
      !("SpeechSynthesisUtterance" in window)
    )
      setState("unavailable");
    return () => {
      if (utterance.current) {
        utterance.current = null;
        window.speechSynthesis.cancel();
      }
    };
  }, []);
  const stop = () => {
    utterance.current = null;
    window.speechSynthesis.cancel();
    setPosition(undefined);
    setState("ready");
  };
  const read = () => {
    const speech = new SpeechSynthesisUtterance(
      "Keep the first screen focused on one task. Move the optional settings into the next step.",
    );
    utterance.current = speech;
    speech.lang = "en-US";
    speech.onboundary = (event) => {
      if (utterance.current === speech) setPosition(event.charIndex);
    };
    const finish = (failed) => {
      if (utterance.current !== speech) return;
      utterance.current = null;
      setPosition(undefined);
      setState(failed ? "failed" : "ready");
    };
    speech.onend = () => finish(false);
    speech.onerror = () => finish(true);
    setState("speaking");
    try {
      window.speechSynthesis.speak(speech);
    } catch {
      finish(true);
    }
  };
  const word =
    position === undefined
      ? undefined
      : readAloudWords.find(
          (word2) => position >= word2.start && position < word2.end,
        );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-3)",
        width: "min(100%, 560px)",
      }}
    >
      <Transcript.Root aria-label="Assistant response">
        <Transcript.Segment
          segment={{
            id: "answer",
            text: "Keep the first screen focused on one task. Move the optional settings into the next step.",
          }}
        >
          <Transcript.Speaker>
            <MessageSender name="Assistant" kind="agent" size="xs" />
          </Transcript.Speaker>
          <Transcript.Text>
            {word ? (
              <>
                {"Keep the first screen focused on one task. Move the optional settings into the next step.".slice(
                  0,
                  word.start,
                )}
                <span className="ui-transcript-word" data-current="true">
                  {word.text}
                </span>
                {"Keep the first screen focused on one task. Move the optional settings into the next step.".slice(
                  word.end,
                )}
              </>
            ) : (
              <span
                className="ui-transcript-highlight"
                data-current={state === "speaking" || undefined}
              >
                {
                  "Keep the first screen focused on one task. Move the optional settings into the next step."
                }
              </span>
            )}
          </Transcript.Text>
        </Transcript.Segment>
      </Transcript.Root>
      <div>
        <Button
          size="sm"
          variant="outline"
          disabled={state === "unavailable"}
          leadingIcon={state === "speaking" ? <Square /> : <Volume2 />}
          onClick={state === "speaking" ? stop : read}
        >
          {state === "speaking" ? "Stop reading" : "Read aloud"}
        </Button>
      </div>
      {(state === "unavailable" || state === "failed") && (
        <p role="status">
          {state === "unavailable"
            ? "Read aloud is unavailable in this browser."
            : "Speech could not start. Try again."}
        </p>
      )}
    </div>
  );
}

var meeting = [
  {
    id: "rina-1",
    speaker: "Rina",
    start: 0,
    end: 2.8,
    text: "The rollout can move once staging confirms the retry fix.",
    words: [
      "The ",
      "rollout ",
      "can ",
      "move ",
      "once ",
      "staging ",
      "confirms ",
      "the ",
      "retry ",
      "fix.",
    ].map((text, index) => ({
      id: `w${index}`,
      text,
      start: [0, 0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6][index],
      end: [0.2, 0.9, 1.15, 1.4, 1.65, 1.9, 2.15, 2.4, 2.6, 2.8][index],
    })),
  },
  {
    id: "marco-1",
    speaker: "Marco",
    start: 3.1,
    end: 5.6,
    text: "I\u2019ll confirm coverage with the regional leads today.",
  },
  {
    id: "rina-2",
    speaker: "Rina",
    start: 6.2,
    end: 8.5,
    text: "Great. Keep the decision pending until both checks are in.",
  },
];

var readAloudWords = Array.from(
  "Keep the first screen focused on one task. Move the optional settings into the next step.".matchAll(
    /\S+/g,
  ),
  (match) => ({
    text: match[0],
    start: match.index,
    end: match.index + match[0].length,
  }),
);

```

For the live call composition, see [Voice indicator](/ai-elements/voice-indicator#live-voice).

## API reference

Transcript.Root

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| segments | readonly TranscriptSegmentData[] | [] | Ordered caller-supplied transcript segments. |
| variant | 'plain' \| 'timed' \| 'captions' | 'plain' | Plain has no frame; timed and captions show valid timestamps and supplied word controls. |
| currentTime | number | — | Current caller-owned playback time in seconds. Finite nonnegative values can highlight valid intervals. |
| activeSegmentId | string | — | Explicit caller-owned active segment ID for an untimed live turn or valid timed segment. |
| onSeek | (seconds, segment) => void | — | Called by valid timestamp and word Buttons. Transcript does not control media. |
| emptyFallback | React.ReactNode | 'No transcript available.' | Caller-replaceable empty content. |
| children | React.ReactNode | — | Optional caller composition when using the Root part. |

TranscriptSegmentData contains id, stable text, optional draftText, optional speaker, optional start/end, optional status (partial, final, or interrupted), and optional word intervals. TranscriptWordData contains stable id, exact text, start, and end; include any required spaces or punctuation in each word's text. Valid intervals have finite nonnegative starts and a finite end greater than the start. A valid segment start can be sought even when its end is not yet known; it cannot be highlighted as current without a complete interval. The explicit activeSegmentId can mark an untimed live segment current. Invalid intervals remain ordinary text and cannot be sought or highlighted. Time zero is valid. The component accepts native div attributes and forwards its ref; all parts have their matching native element attributes and refs. Root provides variant, current time, active ID, and seek behavior to manually composed Segment parts. No audio element, SDK, transport, inference, per-word live announcement, or scrolling behavior is owned here.
