diff --git a/web/src/components/transcript.tsx b/web/src/components/transcript.tsx index 38ad3246..3766ebad 100644 --- a/web/src/components/transcript.tsx +++ b/web/src/components/transcript.tsx @@ -69,10 +69,57 @@ export function Transcript({ } }, [scrollButtonRef]); + const handleDownloadTranscript = () => { + // Create CSV content + let csvContent = "Timestamp,Participant,Text\n"; + + displayTranscriptions.forEach(({ segment, participant, timestamp }) => { + const csvRow = [ + new Date(timestamp || 0).toLocaleTimeString([], { + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false + }), + participant?.isAgent ? "Agent" : "User", + `"${segment.text.trim().replace(/"/g, '""')}"`, // Escape quotes in the text + ].join(","); + + csvContent += csvRow + "\n"; + }); + + // Create Blob + const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" }); + + // Create download link + const link = document.createElement("a"); + if (link.download !== undefined) { + const url = URL.createObjectURL(blob); + link.setAttribute("href", url); + link.setAttribute( + "download", + `transcript_${new Date().toISOString()}.csv` + ); + link.style.visibility = "hidden"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } + console.log("Downloading transcript..."); + }; + return ( <> -