Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(attachments): show a meeting transcript as its conversation
Elian Doran3e72a29b8889
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex c463114f7d..9912cd5894 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4584,5 +4584,11 @@"starting": "Starting the recording…","stop": "Stop recording","stopping": "Finishing the transcript…"+ },+ "transcript": {+ "speaker_me": "Me",+ "speaker_others": "Others",+ "empty": "Nothing has been transcribed yet.",+ "unreadable": "This transcript cannot be read."}}diff --git a/apps/client/src/widgets/type_widgets/Attachment.spec.tsx b/apps/client/src/widgets/type_widgets/Attachment.spec.tsxindex 78c7aa1951..b12024c83b 100644--- a/apps/client/src/widgets/type_widgets/Attachment.spec.tsx+++ b/apps/client/src/widgets/type_widgets/Attachment.spec.tsx@@ -94,6 +94,26 @@ describe("AttachmentList", () => {expect(drawingBlob).not.toHaveBeenCalled();});+ it("shows a transcript as its conversation, not through the content renderer", async () => {+ const content = JSON.stringify({+ version: 1,+ startedAt: "2026-10-13T14:30:00.000Z",+ utterances: [ { source: "system", offsetMs: 3000, text: "Yes." } ]+ });+ const transcript = {+ ...role("transcript"),+ mime: "application/json",+ getBlob: async () => ({ content })+ };+ getRenderedContent.mockClear();+ const container = await mount([ transcript ] as FAttachment[]);++ await vi.waitFor(() =>+ expect(container.querySelector(".attachment-transcript .transcript-turn")).not.toBeNull());+ expect(container.querySelector(".attachment-transcript")?.textContent).toContain("Yes.");+ expect(getRenderedContent).not.toHaveBeenCalled();+ });+it("says plainly that there is nothing where a note carries nothing at all", async () => {const container = await mount([]);diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsxindex 5b7dd3747b..ece910312d 100644--- a/apps/client/src/widgets/type_widgets/Attachment.tsx+++ b/apps/client/src/widgets/type_widgets/Attachment.tsx@@ -44,6 +44,7 @@ import { ParentComponent, refToJQuerySelector } from "../react/react_utils";import SiblingNavigator from "../react/SiblingNavigator";import { TextPreview } from "./File";import MediaPreview from "./file/MediaPreview";+import TranscriptView from "./transcript/TranscriptView";import { TypeWidgetProps } from "./type_widget";const CanvasDrawingDetail = lazy(() =>@@ -236,7 +237,8 @@ function AttachmentInfo({ attachment, isFullDetail, ownerNote, noteContext, viewconst isEditableDrawing = !!isFullDetail && !!ownerNote && isFileLike&& attachment.mime === CANVAS_ATTACHMENT_MIME&& (!attachment.isProtected || protected_session_holder.isProtectedSessionAvailable());- const rendersItself = isZoomableImage || isPlayableMedia || isEditableDrawing;+ const isTranscript = attachment.role === "transcript";+ const rendersItself = isZoomableImage || isPlayableMedia || isEditableDrawing || isTranscript;const imageSrc = getAttachmentImageUrl(attachment.attachmentId, attachment.title, modified);/** Unmounts whatever the content renderer previously mounted here (a media player), so that replacing@@ -365,6 +367,10 @@ function AttachmentInfo({ attachment, isFullDetail, ownerNote, noteContext, view/></Suspense></div>+ ) : isTranscript ? (+ <div key="transcript" className="attachment-content-wrapper attachment-transcript">+ <TranscriptView attachment={attachment} />+ </div>) : (<div key="rendered" ref={contentWrapper} className="attachment-content-wrapper" />)}diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.cssnew file mode 100644index 0000000000..2634c1ce19--- /dev/null+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css@@ -0,0 +1,38 @@+.transcript {+ padding: 0.5rem 1rem 1rem;+ max-width: var(--preferred-max-content-width, 900px);++ .transcript-turn {+ margin-bottom: 1rem;+ }++ .transcript-turn-header {+ display: flex;+ align-items: baseline;+ gap: 0.5rem;+ margin-bottom: 0.25rem;+ }++ .transcript-speaker {+ font-weight: 600;+ }++ .transcript-microphone .transcript-speaker {+ color: var(--main-text-color);+ }++ .transcript-system .transcript-speaker {+ color: var(--muted-text-color);+ }++ .transcript-time {+ font-size: 0.85em;+ font-variant-numeric: tabular-nums;+ color: var(--muted-text-color);+ }++ p {+ margin: 0;+ white-space: pre-wrap;+ }+}diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsxnew file mode 100644index 0000000000..5cf11270c6--- /dev/null+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx@@ -0,0 +1,81 @@+import type { Transcript, TranscriptUtterance } from "@triliumnext/commons";+import { act } from "preact/test-utils";+import { describe, expect, it, vi } from "vitest";++import Component from "../../../components/component";+import type FAttachment from "../../../entities/fattachment";+import LoadResults from "../../../services/load_results";+import { renderInto } from "../../../test/render";+import { ParentComponent } from "../../react/react_utils";+import TranscriptView, { formatOffset, groupIntoTurns, parseTranscript } from "./TranscriptView";++vi.mock("../../../services/i18n", () => ({ t: (key: string) => key }));++function transcript(utterances: TranscriptUtterance[]) {+ const content: Transcript = { version: 1, startedAt: "2026-10-13T14:30:00.000Z", utterances };+ return JSON.stringify(content);+}++describe("transcript helpers", () => {+ it("reads only version 1 transcripts", () => {+ expect(parseTranscript(transcript([]))?.utterances).toEqual([]);+ expect(parseTranscript(null)).toBeNull();+ expect(parseTranscript("not json")).toBeNull();+ expect(parseTranscript(JSON.stringify({ version: 2, utterances: [] }))).toBeNull();+ expect(parseTranscript(JSON.stringify({ version: 1 }))).toBeNull();+ });++ it("joins consecutive utterances of one source into a turn timed by its first", () => {+ expect(groupIntoTurns([+ { source: "microphone", offsetMs: 1000, text: "Hello." },+ { source: "microphone", offsetMs: 3000, text: "Can you hear me?" },+ { source: "system", offsetMs: 5000, text: "Yes." },+ { source: "microphone", offsetMs: 7000, text: "Good." }+ ])).toEqual([+ { source: "microphone", offsetMs: 1000, text: "Hello. Can you hear me?" },+ { source: "system", offsetMs: 5000, text: "Yes." },+ { source: "microphone", offsetMs: 7000, text: "Good." }+ ]);+ });++ it("formats offsets as m:ss, with hours once there are any", () => {+ expect(formatOffset(0)).toBe("0:00");+ expect(formatOffset(65_900)).toBe("1:05");+ expect(formatOffset(3_725_000)).toBe("1:02:05");+ expect(formatOffset(-5)).toBe("0:00");+ });+});++describe("TranscriptView", () => {+ it("shows the turns, and the new content once the recording rewrites it", async () => {+ const getBlob = vi.fn()+ .mockResolvedValueOnce({ content: transcript([]) })+ .mockResolvedValueOnce({ content: transcript([+ { source: "microphone", offsetMs: 1500, text: "Can you hear me?" },+ { source: "system", offsetMs: 3000, text: "Yes." }+ ]) });+ const attachment = { attachmentId: "transcript1", getBlob } as unknown as FAttachment;+ const component = new Component();++ const container = renderInto(+ <ParentComponent.Provider value={component}>+ <TranscriptView attachment={attachment} />+ </ParentComponent.Provider>+ );+ await vi.waitFor(() => expect(container.textContent).toContain("transcript.empty"));++ const loadResults = new LoadResults([]);+ loadResults.addAttachmentRow({ attachmentId: "transcript1", ownerId: "meeting" } as never);+ await act(async () => {+ await component.handleEvent("entitiesReloaded", { loadResults });+ });++ const turns = () => [ ...container.querySelectorAll(".transcript-turn") ]+ .map((turn) => turn.textContent);+ await vi.waitFor(() => expect(turns()).toHaveLength(2));+ expect(turns()).toEqual([+ "transcript.speaker_me0:01Can you hear me?",+ "transcript.speaker_others0:03Yes."+ ]);+ });+});diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsxnew file mode 100644index 0000000000..547de4283e--- /dev/null+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx@@ -0,0 +1,113 @@+import "./TranscriptView.css";++import type { Transcript, TranscriptSource, TranscriptUtterance } from "@triliumnext/commons";+import { useCallback, useEffect, useState } from "preact/hooks";++import type FAttachment from "../../../entities/fattachment";+import { t } from "../../../services/i18n";+import { useTriliumEvent } from "../../react/hooks";+import NoItems from "../../react/NoItems";++/**+ * Shows a `transcript` attachment as the conversation it records, one paragraph per speaker turn.+ * Follows the attachment as a running recording rewrites it.+ */+export default function TranscriptView({ attachment }: { attachment: FAttachment }) {+ const [ content, setContent ] = useState<string | null>();++ const load = useCallback(() => {+ let current = true;+ void attachment.getBlob().then((blob) => {+ if (current) {+ setContent(blob?.content ?? null);+ }+ });+ return () => {+ current = false;+ };+ }, [ attachment ]);+ useEffect(load, [ load ]);+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {+ const { attachmentId } = attachment;+ if (loadResults.getAttachmentRows().some((row) => row.attachmentId === attachmentId)) {+ load();+ }+ });++ if (content === undefined) {+ return null;+ }++ const transcript = parseTranscript(content);+ if (!transcript) {+ return <NoItems icon="bx bx-error" text={t("transcript.unreadable")} />;+ }+ if (!transcript.utterances.length) {+ return <NoItems icon="bx bx-microphone" text={t("transcript.empty")} />;+ }++ return (+ <div className="transcript">+ {groupIntoTurns(transcript.utterances).map((turn) => (+ <div key={turn.offsetMs} className={`transcript-turn transcript-${turn.source}`}>+ <div className="transcript-turn-header">+ <span className="transcript-speaker">{speakerName(turn.source)}</span>+ <span className="transcript-time">{formatOffset(turn.offsetMs)}</span>+ </div>+ <p>{turn.text}</p>+ </div>+ ))}+ </div>+ );+}++/** Consecutive utterances from one source, read as one paragraph. */+export interface TranscriptTurn {+ source: TranscriptSource;+ offsetMs: number;+ text: string;+}++/** Reads a transcript attachment's content, or returns `null` for content of another shape. */+export function parseTranscript(content: string | null): Transcript | null {+ if (!content) {+ return null;+ }++ try {+ const parsed = JSON.parse(content) as Partial<Transcript>;+ const isTranscript = parsed.version === 1 && Array.isArray(parsed.utterances);+ return isTranscript ? parsed as Transcript : null;+ } catch {+ return null;+ }+}++/** Joins each run of utterances from one source into a turn, timed by its first utterance. */+export function groupIntoTurns(utterances: TranscriptUtterance[]): TranscriptTurn[] {+ const turns: TranscriptTurn[] = [];+ for (const { source, offsetMs, text } of utterances) {+ const last = turns.at(-1);+ if (last?.source === source) {+ last.text += ` ${text}`;+ } else {+ turns.push({ source, offsetMs, text });+ }+ }+ return turns;+}++/** `m:ss`, or `h:mm:ss` from the first hour on. */+export function formatOffset(milliseconds: number) {+ const totalSeconds = Math.max(0, Math.floor(milliseconds / 1000));+ const hours = Math.floor(totalSeconds / 3600);+ const minutes = Math.floor(totalSeconds / 60) % 60;+ const seconds = String(totalSeconds % 60).padStart(2, "0");+ return hours+ ? `${hours}:${String(minutes).padStart(2, "0")}:${seconds}`+ : `${minutes}:${seconds}`;+}++function speakerName(source: TranscriptSource) {+ return source === "microphone" ? t("transcript.speaker_me") : t("transcript.speaker_others");+}