Skip to content

Build your personal knowledge base with Trilium Notes

feat(attachments): fade in transcript text as it arrives

Elian Dorand32b58735d39
diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css
index 4fa52ec7ea..5fe22e2425 100644
--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css
+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css
@@ -63,8 +63,19 @@
}
}
+.transcript .transcript-new {
+ animation: transcript-new-appear 250ms ease-out;
+}
+
+@keyframes transcript-new-appear {
+ from {
+ opacity: 0;
+ }
+}
+
@media (prefers-reduced-motion: reduce) {
- .transcript .transcript-speaking .bx {
+ .transcript .transcript-speaking .bx,
+ .transcript .transcript-new {
animation: none;
}
}
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 400dd9a1d2..6a70831198 100644
--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx
@@ -10,7 +10,9 @@ 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";
+import TranscriptView, {
+ formatOffset, groupIntoTurns, parseTranscript, type TranscriptTurn
+} from "./TranscriptView";
vi.mock("../../../services/i18n", () => ({ t: (key: string) => key }));
@@ -22,6 +24,10 @@ function transcript(utterances: TranscriptUtterance[], startedAt = STARTED_AT) {
return JSON.stringify(content);
}
+function paragraphTexts(turn: TranscriptTurn) {
+ return turn.paragraphs.map((paragraph) => paragraph.map(({ text }) => text).join(" "));
+}
+
describe("transcript helpers", () => {
it("reads only version 1 transcripts", () => {
expect(parseTranscript(transcript([]))?.utterances).toEqual([]);
@@ -32,15 +38,19 @@ describe("transcript helpers", () => {
});
it("joins consecutive utterances of one source into a turn timed by its first", () => {
- expect(groupIntoTurns([
+ const turns = 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, paragraphs: [ "Hello. Can you hear me?" ] },
- { source: "system", offsetMs: 5000, paragraphs: [ "Yes." ] },
- { source: "microphone", offsetMs: 7000, paragraphs: [ "Good." ] }
+ ]);
+ expect(turns.map(({ source, offsetMs }) => ({ source, offsetMs }))).toEqual([
+ { source: "microphone", offsetMs: 1000 },
+ { source: "system", offsetMs: 5000 },
+ { source: "microphone", offsetMs: 7000 }
+ ]);
+ expect(turns.map(paragraphTexts)).toEqual([
+ [ "Hello. Can you hear me?" ], [ "Yes." ], [ "Good." ]
]);
});
@@ -51,7 +61,7 @@ describe("transcript helpers", () => {
{ source: "system", offsetMs: 12_600, durationMs: 2000, text: "Short pause." },
{ source: "system", offsetMs: 17_000, durationMs: 2000, text: "Second point." }
]);
- expect(turns.map((turn) => turn.paragraphs)).toEqual([
+ expect(turns.map(paragraphTexts)).toEqual([
[ "First point, continued. Short pause.", "Second point." ]
]);
});
@@ -99,6 +109,34 @@ describe("TranscriptView", () => {
expect(container.querySelectorAll(".transcript-microphone p")).toHaveLength(2);
});
+ it("fades in only the utterances that arrive after the transcript opens", async () => {
+ const first: TranscriptUtterance = { source: "system", offsetMs: 0, text: "Hi." };
+ const getBlob = vi.fn()
+ .mockResolvedValueOnce({ content: transcript([ first ]) })
+ .mockResolvedValueOnce({ content: transcript([
+ first, { source: "system", offsetMs: 2000, text: "Anyone?" }
+ ]) });
+ 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("Hi."));
+
+ const loadResults = new LoadResults([]);
+ loadResults.addAttachmentRow({ attachmentId: "transcript1", ownerId: "meeting" } as never);
+ await act(async () => {
+ await component.handleEvent("entitiesReloaded", { loadResults });
+ });
+ await vi.waitFor(() => expect(container.textContent).toContain("Anyone?"));
+
+ const spans = [ ...container.querySelectorAll(".transcript-turn p span") ]
+ .map((span) => [ span.textContent, span.classList.contains("transcript-new") ]);
+ expect(spans).toEqual([ [ "Hi.", false ], [ " Anyone?", true ] ]);
+ });
+
it("times turns by the clock, with the offset as a tooltip or alone", async () => {
const renderTimes = async (startedAt: string) => {
const utterance: TranscriptUtterance =
diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx
index 4db7b2b3c8..3c0da7cfe2 100644
--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx
+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx
@@ -29,6 +29,8 @@ export default function TranscriptView({ attachment }: { attachment: FAttachment
const scrollerRef = useRef<HTMLDivElement>(null);
/** The scroll height at the previous render, or `null` before the transcript first shows. */
const scrollHeightRef = useRef<number | null>(null);
+ /** How many utterances the first transcript read held; only later ones fade in. */
+ const initialCountRef = useRef<number | null>(null);
const load = useCallback(() => {
let current = true;
@@ -72,6 +74,8 @@ export default function TranscriptView({ attachment }: { attachment: FAttachment
return <NoItems icon="bx bx-microphone" text={t("transcript.empty")} />;
}
+ initialCountRef.current ??= transcript.utterances.length;
+ const arrived = new Set(transcript.utterances.slice(initialCountRef.current));
const turns = groupIntoTurns(transcript.utterances);
const lastTurn = turns.at(-1);
const speaking = (
@@ -88,7 +92,18 @@ export default function TranscriptView({ attachment }: { attachment: FAttachment
<span className="transcript-speaker">{speakerName(turn.source)}</span>
<TurnTime startedAt={transcript.startedAt} offsetMs={turn.offsetMs} />
</div>
- {turn.paragraphs.map((paragraph, index) => <p key={index}>{paragraph}</p>)}
+ {turn.paragraphs.map((paragraph, index) => (
+ <p key={index}>
+ {paragraph.map((utterance, position) => (
+ <span
+ key={utterance.offsetMs}
+ className={arrived.has(utterance) ? "transcript-new" : undefined}
+ >
+ {position ? ` ${utterance.text}` : utterance.text}
+ </span>
+ ))}
+ </p>
+ ))}
{turn === lastTurn && pending.includes(turn.source) && speaking}
</div>
))}
@@ -131,7 +146,7 @@ function TurnTime({ startedAt, offsetMs }: { startedAt: string; offsetMs: number
export interface TranscriptTurn {
source: TranscriptSource;
offsetMs: number;
- paragraphs: string[];
+ paragraphs: TranscriptUtterance[][];
}
/** Reads a transcript attachment's content, or returns `null` for content of another shape. */
@@ -157,14 +172,15 @@ export function parseTranscript(content: string | null): Transcript | null {
export function groupIntoTurns(utterances: TranscriptUtterance[]): TranscriptTurn[] {
const turns: TranscriptTurn[] = [];
let previousEndMs: number | null = null;
- for (const { source, offsetMs, durationMs, text } of utterances) {
+ for (const utterance of utterances) {
+ const { source, offsetMs, durationMs } = utterance;
const last = turns.at(-1);
if (last?.source !== source) {
- turns.push({ source, offsetMs, paragraphs: [ text ] });
+ turns.push({ source, offsetMs, paragraphs: [ [ utterance ] ] });
} else if (previousEndMs !== null && offsetMs - previousEndMs >= PARAGRAPH_PAUSE_MS) {
- last.paragraphs.push(text);
+ last.paragraphs.push([ utterance ]);
} else {
- last.paragraphs[last.paragraphs.length - 1] += ` ${text}`;
+ last.paragraphs.at(-1)?.push(utterance);
}
previousEndMs = durationMs === undefined ? null : offsetMs + durationMs;
}