{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "transcript-overlay",
  "title": "Transcript Overlay",
  "description": "Caption-style overlay for bot speech with word-by-word fade-in and turn-end fade-out.",
  "dependencies": [
    "@pipecat-ai/client-js@^1.14.0",
    "@pipecat-ai/client-react@^1.9.0",
    "class-variance-authority@^0.7.1",
    "tw-animate-css@^1.4.0"
  ],
  "files": [
    {
      "path": "src/components/transcript-overlay.tsx",
      "content": "\"use client\";\n\nimport type { BotOutputData } from \"@pipecat-ai/client-js\";\nimport { RTVIEvent } from \"@pipecat-ai/client-js\";\nimport {\n  useConversationContext,\n  usePipecatClientTransportState,\n  useRTVIClientEvent,\n} from \"@pipecat-ai/client-react\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { useState } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nconst transcriptOverlayVariants = cva(\n  \"mx-auto items-center justify-end text-center *:bg-foreground *:text-background *:mx-auto *:inline *:box-decoration-clone *:text-balance\",\n  {\n    variants: {\n      size: {\n        sm: \"*:rounded-md *:px-2 *:py-1 *:text-xs *:leading-4 *:font-medium\",\n        default:\n          \"*:rounded-lg *:px-3 *:py-1.5 *:text-sm *:leading-6 *:font-medium\",\n        lg: \"*:rounded-xl *:px-4 *:py-2 *:text-base *:leading-7 *:font-medium\",\n      },\n    },\n    defaultVariants: { size: \"default\" },\n  },\n);\n\nexport interface TranscriptOverlayViewProps extends VariantProps<\n  typeof transcriptOverlayVariants\n> {\n  /** Words to display as individually animated spans. */\n  words: string[];\n  /** Whether the speech turn has ended (triggers fade-out). */\n  turnEnd?: boolean;\n  /** Fade-in duration per word, ms. */\n  fadeInDuration?: number;\n  /** Fade-out duration for the whole overlay, ms. */\n  fadeOutDuration?: number;\n  className?: string;\n}\n\n/**\n * Caption-style overlay rendering words with per-word fade-in and a\n * fade-out when the turn ends. Line-wrapped background blocks.\n */\nexport function TranscriptOverlayView({\n  words,\n  turnEnd = false,\n  size,\n  fadeInDuration = 300,\n  fadeOutDuration = 1000,\n  className,\n}: TranscriptOverlayViewProps) {\n  const containerStyle = {\n    \"--fade-in-duration\": `${fadeInDuration}ms`,\n    ...(turnEnd && { animationDuration: `${fadeOutDuration}ms` }),\n  } as React.CSSProperties;\n\n  return (\n    <div\n      data-slot=\"transcript-overlay\"\n      className={cn(\n        transcriptOverlayVariants({ size }),\n        turnEnd && \"animate-out fade-out fill-mode-forwards\",\n        className,\n      )}\n      style={containerStyle}\n    >\n      <p>\n        {words.map((word, index) => (\n          <span\n            key={index}\n            className=\"animate-in fade-in\"\n            style={{ animationDuration: `${fadeInDuration}ms` }}\n          >\n            {word + (index < words.length - 1 ? \" \" : \"\")}\n          </span>\n        ))}\n      </p>\n    </div>\n  );\n}\n\nexport interface TranscriptOverlayProps extends Omit<\n  TranscriptOverlayViewProps,\n  \"words\" | \"turnEnd\"\n> {\n  /** \"remote\" shows bot speech; \"local\" is reserved for future use. */\n  participant?: \"local\" | \"remote\";\n}\n\n/**\n * Live caption overlay for bot speech, driven by BotOutput events\n * (requires RTVI 1.1.0+). Renders nothing until the client is ready and\n * speech arrives. Must be rendered inside a PipecatClientProvider.\n */\nexport function TranscriptOverlay({\n  participant = \"remote\",\n  ...props\n}: TranscriptOverlayProps) {\n  const [caption, setCaption] = useState({\n    words: [] as string[],\n    turnEnd: false,\n  });\n  const { botOutputSupported } = useConversationContext();\n  const transportState = usePipecatClientTransportState();\n\n  useRTVIClientEvent(RTVIEvent.TransportStateChanged, (state) => {\n    if (state !== \"ready\") setCaption({ words: [], turnEnd: false });\n  });\n\n  useRTVIClientEvent(RTVIEvent.BotOutput, (data: BotOutputData) => {\n    if (\n      participant === \"local\" ||\n      !botOutputSupported ||\n      transportState !== \"ready\"\n    ) {\n      return;\n    }\n    if (data.spoken === true && data.text) {\n      setCaption((prev) => ({\n        words: [...(prev.turnEnd ? [] : prev.words), data.text],\n        turnEnd: false,\n      }));\n    }\n  });\n\n  useRTVIClientEvent(RTVIEvent.BotStoppedSpeaking, () => {\n    if (participant === \"local\") return;\n    setCaption((prev) => ({ ...prev, turnEnd: true }));\n  });\n\n  if (\n    participant === \"local\" ||\n    !botOutputSupported ||\n    caption.words.length === 0 ||\n    transportState !== \"ready\"\n  ) {\n    return null;\n  }\n\n  return <TranscriptOverlayView {...caption} {...props} />;\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/transcript-overlay.tsx"
    }
  ],
  "docs": "Render inside a PipecatClientProvider. Requires a bot with RTVI 1.1.0+ (BotOutput events). Ensure tw-animate-css is imported in your globals.css.",
  "categories": [
    "voice"
  ],
  "type": "registry:component"
}