Skip to content

Build your personal knowledge base with Trilium Notes

feat(attachments): time transcript turns by the clock

Elian Doran680aacbde551
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 1b2c20dabd..5ecdc12a95 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4590,6 +4590,7 @@
"speaker_others": "Others",
"empty": "Nothing has been transcribed yet.",
"unreadable": "This transcript cannot be read.",
- "speaking": "Speaking…"
+ "speaking": "Speaking…",
+ "offset": "{{offset}} into the recording"
}
}
diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx
index 80692013c6..400dd9a1d2 100644
--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx
@@ -1,6 +1,7 @@
import type {
Transcript, TranscriptionState, TranscriptSource, TranscriptUtterance
} from "@triliumnext/commons";
+import { Tooltip } from "bootstrap";
import { act } from "preact/test-utils";
import { describe, expect, it, vi } from "vitest";
@@ -13,8 +14,11 @@ import TranscriptView, { formatOffset, groupIntoTurns, parseTranscript } from ".
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 };
+/** Local time, so that the clock times the spec expects hold in every time zone. */
+const STARTED_AT = "2026-10-13T14:29:55";
+
+function transcript(utterances: TranscriptUtterance[], startedAt = STARTED_AT) {
+ const content: Transcript = { version: 1, startedAt, utterances };
return JSON.stringify(content);
}
@@ -89,13 +93,44 @@ describe("TranscriptView", () => {
.map((turn) => turn.textContent);
await vi.waitFor(() => expect(turns()).toHaveLength(2));
expect(turns()).toEqual([
- "transcript.speaker_me0:01Can you hear me?Hello?",
- "transcript.speaker_others0:08Yes."
+ "transcript.speaker_me14:29Can you hear me?Hello?",
+ "transcript.speaker_others14:30Yes."
]);
expect(container.querySelectorAll(".transcript-microphone p")).toHaveLength(2);
});
- it("shows who is speaking in the meeting its note records, before the words arrive", async () => {
+ it("times turns by the clock, with the offset as a tooltip or alone", async () => {
+ const renderTimes = async (startedAt: string) => {
+ const utterance: TranscriptUtterance =
+ { source: "system", offsetMs: 65_000, text: "Yes." };
+ const content = transcript([ utterance ], startedAt);
+ const attachment = { attachmentId: "transcript1", getBlob: async () => ({ content }) };
+ const container = renderInto(
+ <ParentComponent.Provider value={new Component()}>
+ <TranscriptView attachment={attachment as unknown as FAttachment} />
+ </ParentComponent.Provider>
+ );
+ await vi.waitFor(() =>
+ expect(container.querySelector(".transcript-time")).not.toBeNull());
+ return container.querySelector<HTMLElement>(".transcript-time");
+ };
+
+ const time = await renderTimes(STARTED_AT);
+ expect(time?.textContent).toBe("14:31");
+ expect(time?.getAttribute("datetime"))
+ .toBe(new Date("2026-10-13T14:31:00").toISOString());
+ const tooltip = time && Tooltip.getInstance(time);
+ expect(tooltip).toBeTruthy();
+ act(() => tooltip?.show());
+ expect(document.querySelector(".tooltip")?.textContent).toBe("transcript.offset");
+ act(() => tooltip?.dispose());
+
+ const offset = await renderTimes("not a date");
+ expect(offset?.textContent).toBe("1:05");
+ expect(offset && Tooltip.getInstance(offset)).toBeNull();
+ });
+
+ it("shows who is speaking in the recorded meeting, before the words arrive", async () => {
let onStateChanged: (state: TranscriptionState) => void = () => {};
const recording = (noteId: string, pendingSources: TranscriptSource[]) =>
act(() => onStateChanged({ status: "recording", noteId, pendingSources }));
@@ -136,12 +171,12 @@ describe("TranscriptView", () => {
});
await recording("meeting", [ "microphone", "system" ]);
await vi.waitFor(() => expect(turns()).toEqual([
- "transcript.speaker_me0:01Hello?transcript.speaking",
+ "transcript.speaker_me14:29Hello?transcript.speaking",
"transcript.speaker_otherstranscript.speaking"
]));
await recording("other", [ "system" ]);
- expect(turns()).toEqual([ "transcript.speaker_me0:01Hello?" ]);
+ expect(turns()).toEqual([ "transcript.speaker_me14:29Hello?" ]);
window.electronApi = undefined;
});
diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx
index 13f376f811..4db7b2b3c8 100644
--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx
+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx
@@ -1,12 +1,13 @@
import "./TranscriptView.css";
import type { Transcript, TranscriptSource, TranscriptUtterance } from "@triliumnext/commons";
-import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
+import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
import type FAttachment from "../../../entities/fattachment";
import { t } from "../../../services/i18n";
+import utils from "../../../services/utils";
import { useTranscriptionState } from "../../launch_bar/RecordMeetingButton";
-import { useTriliumEvent } from "../../react/hooks";
+import { useStaticTooltip, useTriliumEvent } from "../../react/hooks";
import NoItems from "../../react/NoItems";
/** How close to the end, in pixels, still counts as reading the newest turn. */
@@ -85,7 +86,7 @@ export default function TranscriptView({ attachment }: { attachment: FAttachment
<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>
+ <TurnTime startedAt={transcript.startedAt} offsetMs={turn.offsetMs} />
</div>
{turn.paragraphs.map((paragraph, index) => <p key={index}>{paragraph}</p>)}
{turn === lastTurn && pending.includes(turn.source) && speaking}
@@ -103,6 +104,29 @@ export default function TranscriptView({ attachment }: { attachment: FAttachment
);
}
+/**
+ * When a turn began, in local clock time, with its offset into the recording as the tooltip. Shows
+ * the offset alone when the transcript's `startedAt` cannot be read.
+ */
+function TurnTime({ startedAt, offsetMs }: { startedAt: string; offsetMs: number }) {
+ const timeRef = useRef<HTMLTimeElement>(null);
+ const offset = formatOffset(offsetMs);
+ const startedAtMs = Date.parse(startedAt);
+ const time = Number.isNaN(startedAtMs) ? null : new Date(startedAtMs + offsetMs);
+ const tooltip = time ? t("transcript.offset", { offset }) : "";
+ const tooltipConfig = useMemo(() => ({ title: tooltip }), [ tooltip ]);
+ useStaticTooltip(timeRef, tooltipConfig);
+
+ if (!time) {
+ return <span className="transcript-time">{offset}</span>;
+ }
+ return (
+ <time ref={timeRef} className="transcript-time" dateTime={time.toISOString()}>
+ {utils.formatTime(time)}
+ </time>
+ );
+}
+
/** Consecutive utterances from one source, split into paragraphs at long pauses. */
export interface TranscriptTurn {
source: TranscriptSource;