{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "voiceprint-player-demo",
  "type": "registry:block",
  "title": "Voiceprint: Recording Player",
  "description": "Audio Waveform Background example, Recording Player: A transcription player for NASA's Apollo 11 tapes, where the print listens to the audio element itself and the tape's hiss stays under the noise gate. A take on the animated background (backdrop) and audio visualizer (waveform). Fits hero and features sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "hero",
    "features",
    "animated-background",
    "audio-visualizer",
    "background",
    "ai",
    "canvas"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/voiceprint#voiceprint-player-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/voiceprint.json"
  ],
  "files": [
    {
      "path": "components/voiceprint-player-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Voiceprint } from \"@/components/ui/voiceprint\";\n\ntype Line = { start: number; end: number; text: string };\ntype Tape = { id: string; title: string; when: string; src: string; page: string; duration: number; lines: Line[] };\n\n// Public-domain NASA recordings from Wikimedia Commons, which serves them with\n// CORS headers. Without those the analyser would only ever hear silence.\nconst TAPES: Tape[] = [\n  {\n    id: \"first-step\",\n    title: \"First step\",\n    when: \"Apollo 11 · 21 Jul 1969, 02:56 UTC\",\n    src: \"https://upload.wikimedia.org/wikipedia/commons/transcoded/d/dd/Armstrong_Small_Step.ogg/Armstrong_Small_Step.ogg.mp3\",\n    page: \"https://commons.wikimedia.org/wiki/File:Armstrong_Small_Step.ogg\",\n    duration: 24.1,\n    lines: [\n      { start: 3.6, end: 5.7, text: \"I'm going to step off the LM now.\" },\n      { start: 15.3, end: 17.8, text: \"That's one small step for man,\" },\n      { start: 20.6, end: 23.8, text: \"one giant leap for mankind.\" },\n    ],\n  },\n  {\n    id: \"landing\",\n    title: \"Tranquility Base\",\n    when: \"Apollo 11 · 20 Jul 1969, 20:17 UTC\",\n    src: \"https://upload.wikimedia.org/wikipedia/commons/8/87/Apollo_11_Eagle_Has_Landed.mp3\",\n    page: \"https://commons.wikimedia.org/wiki/File:Apollo_11_Eagle_Has_Landed.mp3\",\n    duration: 5.3,\n    lines: [\n      { start: 1.0, end: 3.6, text: \"Houston, Tranquility Base here.\" },\n      { start: 3.7, end: 5.1, text: \"The Eagle has landed.\" },\n    ],\n  },\n];\n\nconst clock = (s: number) => {\n  const whole = Math.max(0, Math.floor(s));\n  return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, \"0\")}`;\n};\n\nfunction PlayIcon({ playing }: { playing: boolean }) {\n  return playing ? (\n    <svg viewBox=\"0 0 16 16\" aria-hidden className=\"size-4\" fill=\"currentColor\">\n      <rect x=\"3.5\" y=\"2.5\" width=\"3\" height=\"11\" rx=\"1\" />\n      <rect x=\"9.5\" y=\"2.5\" width=\"3\" height=\"11\" rx=\"1\" />\n    </svg>\n  ) : (\n    <svg viewBox=\"0 0 16 16\" aria-hidden className=\"size-4 translate-x-px\" fill=\"currentColor\">\n      <path d=\"M4.5 2.9v10.2a.9.9 0 0 0 1.37.77l8.1-5.1a.9.9 0 0 0 0-1.54l-8.1-5.1A.9.9 0 0 0 4.5 2.9Z\" />\n    </svg>\n  );\n}\n\nexport function VoiceprintPlayerDemo() {\n  // The element in state for the print to listen to, and in a ref for the handlers that drive it.\n  const audioRef = React.useRef<HTMLAudioElement | null>(null);\n  const [audio, setAudio] = React.useState<HTMLAudioElement | null>(null);\n  const [tapeId, setTapeId] = React.useState(TAPES[0].id);\n  const [playing, setPlaying] = React.useState(false);\n  const [time, setTime] = React.useState(0);\n  const [duration, setDuration] = React.useState(TAPES[0].duration);\n  const [failed, setFailed] = React.useState(false);\n  const tape = TAPES.find((t) => t.id === tapeId) ?? TAPES[0];\n\n  // The playhead follows the tape every frame while it plays.\n  React.useEffect(() => {\n    if (!audio || !playing) return;\n    let raf = 0;\n    const tick = () => {\n      setTime(audio.currentTime);\n      raf = requestAnimationFrame(tick);\n    };\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n  }, [audio, playing]);\n\n  function toggle() {\n    const audio = audioRef.current;\n    if (!audio) return;\n    if (audio.paused) audio.play().catch(() => setFailed(true));\n    else audio.pause();\n  }\n\n  function pick(next: Tape) {\n    const audio = audioRef.current;\n    if (!audio || next.id === tape.id) return;\n    const resume = !audio.paused;\n    audio.src = next.src;\n    setTapeId(next.id);\n    setTime(0);\n    setDuration(next.duration);\n    setFailed(false);\n    if (resume) audio.play().catch(() => setFailed(true));\n  }\n\n  const progress = duration > 0 ? Math.min(1, time / duration) : 0;\n  const said = tape.lines.filter((l) => time >= l.start);\n  const latest = said.at(-1);\n  const live = latest !== undefined && time <= latest.end + 0.4;\n  const caption = latest ?? tape.lines[0];\n\n  return (\n    <Voiceprint\n      source={audio}\n      reach={0.5}\n      className=\"flex h-[var(--demo-height,36rem)] w-full flex-col items-center justify-between gap-6 rounded-2xl border border-zinc-950/10 bg-[#fafafa] px-4 py-8 text-zinc-950 sm:px-8 sm:py-10 dark:border-white/10 dark:bg-[#07080c] dark:text-zinc-50\"\n    >\n      <h2 className=\"max-w-[17ch] text-center text-4xl/[1.05] font-semibold tracking-[-0.03em] text-balance sm:text-[3.25rem]/[1.02]\">\n        Every word on the tape, pinned to its second\n      </h2>\n\n      <div className=\"w-full max-w-2xl rounded-2xl border border-zinc-950/10 bg-white p-4 shadow-sm sm:p-5 dark:border-white/10 dark:bg-zinc-950\">\n        {/* Not a React-controlled src: switching tapes keeps the same element, which the print listens to. */}\n        <audio\n          ref={(el) => {\n            audioRef.current = el;\n            setAudio(el);\n          }}\n          src={TAPES[0].src}\n          crossOrigin=\"anonymous\"\n          preload=\"metadata\"\n          onPlay={() => setPlaying(true)}\n          onPause={() => setPlaying(false)}\n          onTimeUpdate={(e) => setTime(e.currentTarget.currentTime)}\n          onLoadedMetadata={(e) => Number.isFinite(e.currentTarget.duration) && setDuration(e.currentTarget.duration)}\n          onError={() => setFailed(true)}\n        />\n\n        <div className=\"flex items-center gap-3\">\n          <button\n            type=\"button\"\n            onClick={toggle}\n            aria-label={playing ? \"Pause\" : \"Play\"}\n            className=\"grid size-11 shrink-0 place-items-center rounded-full bg-zinc-950 text-white transition-transform active:scale-[0.97] dark:bg-white dark:text-zinc-950\"\n          >\n            <PlayIcon playing={playing} />\n          </button>\n          <div className=\"min-w-0 flex-1\">\n            <p className=\"truncate text-sm font-medium\">{tape.title}</p>\n            <p className=\"truncate text-xs text-zinc-500\">{tape.when}</p>\n          </div>\n          <p className=\"shrink-0 text-xs text-zinc-500 tabular-nums\">\n            <span className=\"text-zinc-950 dark:text-zinc-50\">{clock(time)}</span> / {clock(duration)}\n          </p>\n        </div>\n\n        {/* The track marks where speech is, so the gaps on the tape are visible before you play it. */}\n        <div className=\"relative mt-3 h-6 rounded-full has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[#2747ff]\">\n          <div className=\"absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-zinc-950/10 dark:bg-white/10\" />\n          {tape.lines.map((l) => (\n            <div\n              key={l.start}\n              className=\"absolute top-1/2 h-1 -translate-y-1/2 rounded-full bg-zinc-950/25 dark:bg-white/25\"\n              style={{ left: `${(l.start / duration) * 100}%`, width: `${((l.end - l.start) / duration) * 100}%` }}\n            />\n          ))}\n          <div\n            className=\"absolute top-1/2 left-0 h-1 -translate-y-1/2 rounded-full bg-[#2747ff] dark:bg-[#6b84ff]\"\n            style={{ width: `${progress * 100}%` }}\n          />\n          <div\n            className=\"absolute top-1/2 size-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-[#2747ff] ring-2 ring-white dark:bg-[#6b84ff] dark:ring-zinc-950\"\n            style={{ left: `${progress * 100}%` }}\n          />\n          <input\n            type=\"range\"\n            min={0}\n            max={duration}\n            step={0.1}\n            value={time}\n            onChange={(e) => {\n              const audio = audioRef.current;\n              if (!audio) return;\n              audio.currentTime = Number(e.target.value);\n              setTime(audio.currentTime);\n            }}\n            aria-label=\"Seek\"\n            aria-valuetext={`${clock(time)} of ${clock(duration)}`}\n            className=\"absolute inset-0 w-full cursor-pointer opacity-0\"\n          />\n        </div>\n\n        <div className=\"mt-2 flex min-h-14 items-baseline gap-3\">\n          <span className=\"w-9 shrink-0 text-xs text-zinc-500 tabular-nums\">{clock(caption.start)}</span>\n          <div className=\"min-w-0\">\n            <p className=\"text-[11px] font-medium tracking-[0.08em] text-zinc-500 uppercase\">Neil Armstrong</p>\n            <p\n              className={cn(\n                \"mt-0.5 text-lg/7 font-medium text-pretty transition-colors duration-200\",\n                live ? \"text-zinc-950 dark:text-zinc-50\" : latest ? \"text-zinc-950/45 dark:text-zinc-50/45\" : \"text-zinc-950/25 dark:text-zinc-50/25\",\n              )}\n            >\n              {caption.text}\n            </p>\n          </div>\n        </div>\n\n        <div className=\"mt-3 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 border-t border-zinc-950/10 pt-3 dark:border-white/10\">\n          <div className=\"flex gap-1\">\n            {TAPES.map((t) => (\n              <button\n                key={t.id}\n                type=\"button\"\n                onClick={() => pick(t)}\n                aria-pressed={t.id === tape.id}\n                className={cn(\n                  \"h-8 rounded-full px-3 text-xs font-medium transition-colors\",\n                  t.id === tape.id\n                    ? \"bg-zinc-950/[0.06] text-zinc-950 dark:bg-white/10 dark:text-zinc-50\"\n                    : \"text-zinc-500 hover:text-zinc-950 dark:hover:text-zinc-50\",\n                )}\n              >\n                {t.title} <span className=\"text-zinc-400 tabular-nums\">{clock(t.duration)}</span>\n              </button>\n            ))}\n          </div>\n          <p className=\"text-[11px] text-zinc-500\">\n            {failed ? (\n              \"The recording didn't load. Try again in a moment.\"\n            ) : (\n              <>\n                Transcribed by{\" \"}\n                <a href=\"https://quillmark.example\" className=\"font-medium text-zinc-950 hover:underline dark:text-zinc-50\">\n                  Quillmark\n                </a>{\" \"}\n                · Audio:{\" \"}\n                <a href={tape.page} className=\"hover:underline\">\n                  NASA, public domain\n                </a>\n              </>\n            )}\n          </p>\n        </div>\n      </div>\n    </Voiceprint>\n  );\n}\n"
    }
  ]
}