import { useMemo } from "react"; const Chunk = ({ chunk, currentTime, onClick, ...props }) => { const { text, timestamp } = chunk; const [start, end] = timestamp; const bolded = start <= currentTime && currentTime < end; return ( {text.startsWith(" ") ? " " : ""} x.toFixed(2)).join(" → ")} style={{ textDecoration: bolded ? "underline" : "none", textShadow: bolded ? "0 0 1px #000" : "none", }} > {text.trim()} ); }; const Transcript = ({ transcript, currentTime, setCurrentTime, ...props }) => { const jsonTranscript = useMemo(() => { return ( JSON.stringify(transcript, null, 2) // post-process the JSON to make it more readable .replace(/( {4}"timestamp": )\[\s+(\S+)\s+(\S+)\s+\]/gm, "$1[$2 $3]") ); }, [transcript]); const downloadTranscript = () => { const blob = new Blob([jsonTranscript], { type: "application/json" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "transcript.json"; a.click(); URL.revokeObjectURL(url); }; return ( <>
{transcript.chunks.map((chunk, i) => ( { setCurrentTime(chunk.timestamp[0]); // Set to start of chunk }} /> ))}
); }; export default Transcript;