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(transcript): gray out filler words while they are shown
Elian Doran455e96c5ab85
diff --git a/.claude/skills/working-with-transcription/SKILL.md b/.claude/skills/working-with-transcription/SKILL.mdindex e491b54bc5..75401bb03e 100644--- a/.claude/skills/working-with-transcription/SKILL.md+++ b/.claude/skills/working-with-transcription/SKILL.md@@ -50,7 +50,7 @@ The main process opens the capture window, starts the transcription process andNothing the transcription process imports may reach `@triliumnext/core` or `@triliumnext/server` (the data directory module creates directories when it loads): it gets its paths and a `Logger` from the main process.| `packages/commons/src/lib/transcript.ts` | The `Transcript` format (`version: 1`, `startedAt`, `speakers`, `utterances`), `parseTranscript()`, speaker keys and `setSpeakerName()`; `cleanUtteranceText()`, the filler and stutter cleanup |-| Cleanup | The stored transcript stays verbatim. `TranscriptView` shows each utterance through `cleanUtteranceText()` while the synced option `transcriptCleanupEnabled` (default on, the "Hide filler words" switch above the transcript) holds, and leaves out utterances it empties. The rules are English-only for stutters (a function-word list) and keep numbers, comma-separated repeats and "that that"/"it it" |+| Cleanup | The stored transcript stays verbatim. `TranscriptView` shows each utterance through `cleanUtteranceText()` while the synced option `transcriptCleanupEnabled` (default on, the "Hide filler words" switch above the transcript) holds, and leaves out utterances it empties; with the switch off, it grays out the words the cleanup would remove, from `markDisfluencies()`, which shares its pass with `cleanUtteranceText()`. The rules are English-only for stutters (a function-word list) and keep numbers, comma-separated repeats and "that that"/"it it" || Speaker names | While a recording writes the transcript, `TranscriptView` renames through `electronApi.transcription.renameSpeaker(attachmentId, …)` (by attachment, since a note can hold an older transcript beside the running one): `AttachmentSink`, the only writer then, applies `setSpeakerName()` to the stored names in one transaction, so no utterance is overwritten. Otherwise it saves the stored transcript whole through the generic `POST notes/:noteId/attachments?matchBy=attachmentId`; attachments get no route of their own. `AttachmentSink` re-reads `speakers` before each rewrite, so a rename from another window or device survives the next utterance || `apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx` | Turns, clock times, the "Speaking…" line, fade-in, the level meters (`TranscriptRecordingLevels`) || `apps/client/src/widgets/launch_bar/RecordMeetingButton.tsx` | The launcher and `useTranscriptionState()` |diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.cssindex ab27dfb8b9..39da0569bf 100644--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css@@ -106,6 +106,10 @@margin-top: 0.5rem;}+ .transcript-disfluency {+ color: var(--muted-text-color);+ }+.transcript-speaking {user-select: none;display: flex;diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsxindex 709910e03e..d8972886ea 100644--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx@@ -601,7 +601,7 @@ describe("TranscriptView", () => {expect(edges()).toEqual([ "more-above" ]);});- it("hides filler words and stutters while the option is on, and saves the toggle", async () => {+ it("hides filler words and stutters while the option is on, else grays them out", async () => {options.set("transcriptCleanupEnabled", "true");const content = transcript([{ source: "system", offsetMs: 0, text: "Uh the the data is old." },@@ -614,10 +614,13 @@ describe("TranscriptView", () => {<TranscriptView attachment={attachment as unknown as FAttachment} /></ParentComponent.Provider>);- const spans = () => [ ...container.querySelectorAll(".transcript-turn p span") ]+ const spans = () => [ ...container.querySelectorAll(".transcript-turn p > span") ]+ .map((span) => span.textContent);+ const disfluencies = () => [ ...container.querySelectorAll(".transcript-disfluency") ].map((span) => span.textContent);await vi.waitFor(() => expect(spans()).toHaveLength(2));expect(spans()).toEqual([ "The data is old.", " I know, I know." ]);+ expect(disfluencies()).toEqual([]);const toggle = container.querySelector<HTMLButtonElement>(".transcript-options button.transcript-cleanup");@@ -630,6 +633,7 @@ describe("TranscriptView", () => {});expect(h.put).toHaveBeenCalledWith("options", { transcriptCleanupEnabled: "false" });expect(toggle?.getAttribute("aria-pressed")).toBe("false");+ expect(disfluencies()).toEqual([ "Uh", "the", "Uh." ]);expect(spans()).toEqual([ "Uh the the data is old.", " Uh.", " I know, I know." ]);});diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsxindex 051d021a3f..f324f2c605 100644--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx@@ -1,10 +1,11 @@import "./TranscriptView.css";import {- cleanUtteranceText, getSpeakerKey, MAX_SPEAKER_NAME_LENGTH, parseTranscript, setSpeakerName,- type TranscriptSource, type TranscriptUtterance+ cleanUtteranceText, getSpeakerKey, markDisfluencies, MAX_SPEAKER_NAME_LENGTH, parseTranscript,+ setSpeakerName, type TranscriptSource, type TranscriptUtterance} from "@triliumnext/commons";import clsx from "clsx";+import { Fragment } from "preact";import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";import type FAttachment from "../../../entities/fattachment";@@ -33,8 +34,10 @@ const PARAGRAPH_PAUSE_MS = 2000;* Shows a `transcript` attachment as the conversation it records, one paragraph per speaker turn.* Follows the attachment as a running recording rewrites it, shows which speakers the recording* hears before their words are transcribed, keeps a reader who is at the end there as new- * turns arrive, and fades its top and bottom edges while more turns are above or below. With `transcriptCleanupEnabled`, shows each utterance through- * `cleanUtteranceText()` and leaves out the ones it empties; the stored transcript stays verbatim.+ * turns arrive, and fades its top and bottom edges while more turns are above or below. With+ * `transcriptCleanupEnabled`, shows each utterance through `cleanUtteranceText()` and leaves out+ * the ones it empties; without, shows every word, the ones the cleanup removes grayed out. The+ * stored transcript stays verbatim.*/export default function TranscriptView({ attachment }: { attachment: FAttachment }) {const [ content, setContent ] = useState<string | null>();@@ -166,7 +169,8 @@ export default function TranscriptView({ attachment }: { attachment: FAttachmentkey={utterance.offsetMs}className={arrived.has(utterance) ? "transcript-new" : undefined}>- {position ? ` ${text}` : text}+ {position ? " " : ""}+ {isCleanedUp ? text : <SaidText text={text} />}</span>);})}@@ -189,6 +193,22 @@ export default function TranscriptView({ attachment }: { attachment: FAttachment);}+/** An utterance as said, its disfluencies grayed out. */+function SaidText({ text }: { text: string }) {+ return (+ <>+ {markDisfluencies(text).map((word, index) => (+ <Fragment key={index}>+ {index ? " " : ""}+ {word.isDisfluency+ ? <span className="transcript-disfluency">{word.text}</span>+ : word.text}+ </Fragment>+ ))}+ </>+ );+}+const LEVEL_ICONS: Record<TranscriptSource, string> = {microphone: "bx-microphone",system: "bx-volume-full"diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Meeting transcription.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Meeting transcription.htmlindex 917dabd294..97e81885bc 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Meeting transcription.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Meeting transcription.html@@ -75,8 +75,9 @@or clear the name to restore the default one.</li><li>To show the transcript with or without hesitations such as "uh", "um"and stuttered words, press the <span class="tn-icon bx bx-eraser"></span> <em>Hide filler words</em> button- above it, which shows as pressed while they are hidden. This affects only- what is shown; the stored transcript keeps every word.</li>+ above it, which shows as pressed while they are hidden. While they are+ shown, they are grayed out, so you can see what hiding them would remove.+ This affects only what is shown; the stored transcript keeps every word.</li><li>To copy the transcript as plain text, press the <span class="tn-icon bx bx-copy"></span> <em>Copy transcript</em> buttonabove it. Each turn is copied with the speaker's name and the time it started,as shown, so the copy leaves out filler words while they are hidden.</li>diff --git a/docs/User Guide/User Guide/Meeting transcription.md b/docs/User Guide/User Guide/Meeting transcription.mdindex a98ca68ec2..af03c3ef5d 100644--- a/docs/User Guide/User Guide/Meeting transcription.md+++ b/docs/User Guide/User Guide/Meeting transcription.md@@ -36,7 +36,7 @@ The transcript is stored as an [attachment](Basic%20Concepts%20and%20Features/No* What you say into your microphone is labeled _Me_.* What the other participants say is labeled _Speaker 1_, _Speaker 2_ and so on, while _Identify speakers_ is on; otherwise it is labeled _Others_.* To name a speaker, click their name, type the new name and press <kbd>Enter</kbd>. The name changes on every turn of that speaker. Press <kbd>Esc</kbd> to cancel, or clear the name to restore the default one.-* To show the transcript with or without hesitations such as "uh", "um" and stuttered words, press the <span class="tn-icon bx bx-eraser"></span> _Hide filler words_ button above it, which shows as pressed while they are hidden. This affects only what is shown; the stored transcript keeps every word.+* To show the transcript with or without hesitations such as "uh", "um" and stuttered words, press the <span class="tn-icon bx bx-eraser"></span> _Hide filler words_ button above it, which shows as pressed while they are hidden. While they are shown, they are grayed out, so you can see what hiding them would remove. This affects only what is shown; the stored transcript keeps every word.* To copy the transcript as plain text, press the <span class="tn-icon bx bx-copy"></span> _Copy transcript_ button above it. Each turn is copied with the speaker's name and the time it started, as shown, so the copy leaves out filler words while they are hidden.If the meeting note is [protected](Basic%20Concepts%20and%20Features/Notes/Protected%20Notes.md) and the protected session is locked during the meeting, the transcript cannot be saved. Trilium keeps it in memory and saves it once you enter the protected session again, as long as Trilium stays open.diff --git a/packages/commons/src/lib/transcript.spec.ts b/packages/commons/src/lib/transcript.spec.tsindex b18cffbe8f..eb4463356d 100644--- a/packages/commons/src/lib/transcript.spec.ts+++ b/packages/commons/src/lib/transcript.spec.ts@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";import {cleanUtteranceText, getSpeakerKey, getTranscriptionModel, getTranscriptionResources,- MAX_SPEAKER_NAME_LENGTH, parseTranscript, setSpeakerName,+ markDisfluencies, MAX_SPEAKER_NAME_LENGTH, parseTranscript, setSpeakerName,type Transcript} from "./transcript.js";@@ -73,6 +73,20 @@ describe("transcript", () => {}});+ it("marks the words the cleanup removes, keeping every word as it was said", () => {+ const marked = (text: string) => markDisfluencies(text)+ .map(({ text, isDisfluency }) => isDisfluency ? `[${text}]` : text)+ .join(" ");+ expect(marked("Uh the data is a bit old.")).toBe("[Uh] the data is a bit old.");+ expect(marked("a good point, uh, because uh.")).toBe("a good point, [uh,] because [uh.]");+ expect(marked("we have the uh the memory")).toBe("we have [the] [uh] the memory");+ expect(marked("that was on the on the board")).toBe("that was [on] [the] on the board");+ expect(marked("Because it's d as you can see")).toBe("Because it's [d] as you can see");+ expect(marked("I know, I know.")).toBe("I know, I know.");+ expect(marked("Uh.")).toBe("[Uh.]");+ expect(markDisfluencies(" ")).toEqual([]);+ });+it("matches words through the punctuation around them, in time linear in their length", () => {expect(cleanUtteranceText("So “uh” (um) we’re we're done")).toBe("So we're done");expect(cleanUtteranceText("And (the) the plan")).toBe("And the plan");diff --git a/packages/commons/src/lib/transcript.ts b/packages/commons/src/lib/transcript.tsindex d924e680ba..76471f5fe2 100644--- a/packages/commons/src/lib/transcript.ts+++ b/packages/commons/src/lib/transcript.ts@@ -138,10 +138,20 @@ const KEPT_AT_END = "'-";const NUMBER_WORD = /^(\d|zero$|one$|two$|three$|four$|five$|six$|seven$|eight$|nine$|ten$)/;+/** A word of an utterance as said, and whether {@link cleanUtteranceText} removes it. */+export interface MarkedWord {+ text: string;+ isDisfluency: boolean;+}+interface Word {+ /** The word as the cleaned text shows it, which can take a removed filler's sentence end. */text: string;+ /** The word as said. */+ said: string;/** The word lowercased, without surrounding punctuation. */key: string;+ isDisfluency: boolean;}/**@@ -153,12 +163,7 @@ interface Word {*/export function cleanUtteranceText(text: string): string {const startsCapitalized = /^\p{Lu}/u.test(text);- let words: Word[] = text.split(/\s+/).filter(Boolean)- .map((word) => ({ text: word, key: toKey(word) }));-- words = removeFillers(words);- words = words.filter((word) => !/^[b-hj-z][,.]?$/.test(word.text));- collapseRestarts(words);+ const words = findDisfluencies(text).filter((word) => !word.isDisfluency);let cleaned = words.map((word) => word.text).join(" ").replace(/^[,;:]\s*/, "")@@ -170,6 +175,29 @@ export function cleanUtteranceText(text: string): string {return cleaned;}+/**+ * Splits the text of one utterance into its words as said, marking the ones+ * {@link cleanUtteranceText} removes.+ */+export function markDisfluencies(text: string): MarkedWord[] {+ return findDisfluencies(text)+ .map(({ said, isDisfluency }) => ({ text: said, isDisfluency }));+}++/** Marks the disfluencies of `text`, in the order {@link cleanUtteranceText} documents. */+function findDisfluencies(text: string) {+ const words: Word[] = text.split(/\s+/).filter(Boolean)+ .map((word) => ({ text: word, said: word, key: toKey(word), isDisfluency: false }));++ const kept = markFillers(words)+ .filter((word) => {+ word.isDisfluency = /^[b-hj-z][,.]?$/.test(word.text);+ return !word.isDisfluency;+ });+ markRestarts(kept);+ return words;+}+/*** Names the speaker of `key`, or gives back its default name when `name` is blank. Returns a new* transcript; the utterances are shared.@@ -184,14 +212,18 @@ export function setSpeakerName(transcript: Transcript, key: string, name: stringreturn { ...transcript, speakers };}-/** Drops filler words; the sentence end a filler carried ("…because uh.") moves to the word before. */-function removeFillers(words: Word[]) {+/**+ * Marks filler words, and returns the others; the sentence end a filler carried ("…because uh.")+ * moves to the word before.+ */+function markFillers(words: Word[]) {const kept: Word[] = [];for (const word of words) {if (!FILLER_WORDS.has(word.key)) {kept.push(word);continue;}+ word.isDisfluency = true;const sentenceEnd = /[.?!]$/.exec(word.text)?.[0];const previous = kept.at(-1);if (sentenceEnd && previous && !/[.?!]$/.test(previous.text)) {@@ -201,13 +233,15 @@ function removeFillers(words: Word[]) {return kept;}-/** Removes the first copy of each immediately repeated phrase, longest phrases first. */-function collapseRestarts(words: Word[]) {+/** Marks the first copy of each immediately repeated phrase, longest phrases first. */+function markRestarts(words: Word[]) {for (let size = MAX_RESTART_WORDS; size >= 1; size--) {let start = 0;while (start + 2 * size <= words.length) {if (isRestart(words, start, size)) {- words.splice(start, size);+ for (const word of words.splice(start, size)) {+ word.isDisfluency = true;+ }} else {start++;}