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(transcription): say which source is not captured, silent or stalled
Elian Doran510eba8a5041
diff --git a/.claude/skills/working-with-transcription/SKILL.md b/.claude/skills/working-with-transcription/SKILL.mdindex 75401bb03e..b025859589 100644--- a/.claude/skills/working-with-transcription/SKILL.md+++ b/.claude/skills/working-with-transcription/SKILL.md@@ -25,13 +25,13 @@ capture window (hidden, offscreen) transcription process (Electron│ parentPort: ready / pending / level / utterance / log / stoppedmain process: TranscriptionWorker → AttachmentSink (transcript attachment)state broadcast "transcription-state" (status, noteId, pendingSources,- stalledSources, error); each chunk's RMS on "transcription-level"+ sourceIssues, error); each chunk's RMS on "transcription-level"```The main process opens the capture window, starts the transcription process and connects the two with a `MessageChannelMain`; per chunk it does nothing, per utterance it writes the attachment. Each recording gets a process of its own, which loads the model (~1.3 s) and exits after `stop`.- **Stopping** runs in order: `CaptureWindow.stop()` calls the page's `finishCapture()`, which flushes each worklet's partial chunk (padded with silence to whole 512-sample VAD windows) and posts `{ end: true }`; then the process, told to stop, waits for that marker (it travels on another port than the stop request, up to 2 s) before flushing the VADs and the decode queue.-- **A stalled source**: the main process marks a source in `stalledSources` once it has delivered no chunk for 10 s (`NO_AUDIO_MS`, checked every second) and clears it on the next chunk; a muted source still delivers silence. `TranscriptRecordingLevels` (in `TranscriptView.tsx`, fed by `onLevel()`, shown while its meeting records in the header of the pinned section through `Collapsible`'s `headerActions`) marks that source _No audio_; the launcher turns its time badge red and shows an error once.+- **Source issues**: `updateSourceIssues()` in the main process (on every level and every second) keeps `sourceIssues`, at most one issue per source: `not_captured` for a source `CaptureWindow.start()` did not return (it never gets a `lastHeard`), `no_audio` once it has delivered no chunk for 10 s (`NO_AUDIO_MS`), and `silent` once every chunk has had an RMS of exactly 0 for `SILENCE_MS` (microphone 15 s, since a working one always picks up some noise; system 60 s, since the loopback is digital silence whenever nobody speaks, so a quiet meeting can trip it). The last two clear on the next chunk or the next sound. `TranscriptRecordingLevels` (in `TranscriptView.tsx`, fed by `onLevel()`, shown while its meeting records in the header of the pinned section through `Collapsible`'s `headerActions`) marks the source _Not captured_, _No audio_ or _Only silence_; the launcher turns its time badge red and shows an error, one per source and issue, saying which source and what to do.- **Quitting** during a recording is held back (`before-quit`) until that stop finishes, at most 15 s.- **Failures** reach every window as a state with an `error`, which the launcher shows as a toast; `getState()` never returns it. The process dying ends the recording, keeping what was written; the capture page crashing or every source ending (`render-process-gone`, a track's `ended`) stops it normally, transcribing what was captured; a transcript that cannot be saved (a protected note while the protected session is locked) is reported once and kept in memory, and `AttachmentSink.save()` writes it on the next utterance or on `ENTER_PROTECTED_SESSION`.diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex aa78a1351b..b6f8af820d 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4605,9 +4605,13 @@"stop": "Stop transcribing","stopping": "Finishing the transcript…","title_keeping_recordings": "{{title}} (keeps the audio for troubleshooting)",- "stop_no_audio": "Stop transcribing (no audio is arriving)",+ "stop_with_issue": "Stop transcribing (some audio is not being transcribed)",+ "not_captured_microphone": "Your microphone could not be captured, so what you say is not being transcribed. Check that a microphone is connected and that Trilium is allowed to use it, then start the transcription again.",+ "not_captured_system": "The meeting audio could not be captured, so what the others say is not being transcribed. If your system asks for permission to record the screen or its audio, allow it for Trilium, then start the transcription again.","no_audio_microphone": "No audio has arrived from your microphone for 10 seconds, so what you say is not being transcribed. Stop the transcription and start it again.","no_audio_system": "No audio has arrived from the meeting for 10 seconds, so what the others say is not being transcribed. Stop the transcription and start it again.",+ "silent_microphone": "Only silence has arrived from your microphone for 15 seconds. Check that it is not muted and that it is the default microphone of your system.",+ "silent_system": "Only silence has arrived from the meeting for a minute. If the others are speaking, check that the meeting plays through the default speakers or headphones of your system.","consent": "Let everyone in the meeting know that it is being transcribed, and ask for their consent.","consent_keeping_recordings": "Let everyone in the meeting know that it is being transcribed and its audio kept, and ask for their consent."},@@ -4621,7 +4625,9 @@"speaking": "Speaking…","offset": "{{offset}} into the transcription","cleanup": "Hide filler words",+ "not_captured": "Not captured","no_audio": "No audio",+ "silent": "Only silence","copy": "Copy transcript"},"resource_download": {diff --git a/apps/client/src/widgets/launch_bar/RecordMeetingButton.css b/apps/client/src/widgets/launch_bar/RecordMeetingButton.cssindex c876c70327..be48e17200 100644--- a/apps/client/src/widgets/launch_bar/RecordMeetingButton.css+++ b/apps/client/src/widgets/launch_bar/RecordMeetingButton.css@@ -32,7 +32,7 @@box-shadow: var(--left-pane-item-selected-shadow);font-variant-numeric: tabular-nums;- &.stalled {+ &.has-issue {--color: var(--danger-color, #dc3545);color: #fff;}diff --git a/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsx b/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsxindex 2188526d76..de490f0f35 100644--- a/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsx+++ b/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsx@@ -295,7 +295,7 @@ describe("RecordMeetingButton", () => {window.electronApi = undefined;});- it("says once for each source that stops delivering audio, and marks the time", async () => {+ it("says once why each source is not transcribed, and marks the time", async () => {let onStateChanged: (state: TranscriptionState) => void = () => {};const recording: TranscriptionState = {status: "recording", noteId: "meeting", pendingSources: [], startedAt: Date.now()@@ -321,21 +321,26 @@ describe("RecordMeetingButton", () => {const button = () => (container as HTMLElement | null)?.querySelector("button");await vi.waitFor(() => expect(badge()).not.toBeNull());- expect(badge()?.classList.contains("stalled")).toBe(false);- await report({ stalledSources: [ "system" ] });- await report({ stalledSources: [ "system" ] });- expect(badge()?.classList.contains("stalled")).toBe(true);- expect(button()?.textContent).toContain("record_meeting.stop_no_audio");+ expect(badge()?.classList.contains("has-issue")).toBe(false);+ await report({ sourceIssues: { system: "not_captured" } });+ await report({ sourceIssues: { system: "not_captured" } });+ expect(badge()?.classList.contains("has-issue")).toBe(true);+ expect(button()?.textContent).toContain("record_meeting.stop_with_issue");expect(mocks.showError).toHaveBeenCalledExactlyOnceWith(- expect.stringContaining("record_meeting.no_audio_system"));+ expect.stringContaining("record_meeting.not_captured_system"));await report({});- expect(badge()?.classList.contains("stalled")).toBe(false);- expect(button()?.textContent).not.toContain("no_audio");- await report({ stalledSources: [ "microphone", "system" ] });- expect(mocks.showError).toHaveBeenCalledTimes(3);- expect(mocks.showError).toHaveBeenCalledWith(- expect.stringContaining("record_meeting.no_audio_microphone"));+ expect(badge()?.classList.contains("has-issue")).toBe(false);+ expect(button()?.textContent).not.toContain("stop_with_issue");+ await report({ sourceIssues: { microphone: "no_audio", system: "silent" } });+ await report({ sourceIssues: { microphone: "silent", system: "silent" } });+ const keys = mocks.showError.mock.calls.map(([ message ]) => String(message).split(" ")[0]);+ expect(keys).toEqual([+ "record_meeting.not_captured_system",+ "record_meeting.no_audio_microphone",+ "record_meeting.silent_system",+ "record_meeting.silent_microphone"+ ]);window.electronApi = undefined;});diff --git a/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsx b/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsxindex d9e9a6b6c3..917e3d8502 100644--- a/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsx+++ b/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsx@@ -2,7 +2,7 @@ import "./RecordMeetingButton.css";import {dayjs, getTranscriptionResources, MEETING_RECORDING_LABEL, type TranscriptionState,- type TranscriptionStatus, type TranscriptSource+ type TranscriptionStatus, type TranscriptSource, type TranscriptSourceIssue} from "@triliumnext/commons";import clsx from "clsx";import { useCallback, useEffect, useRef, useState } from "preact/hooks";@@ -28,13 +28,14 @@ import {* Launcher button that records a meeting: the first click creates the meeting note and starts the* recording, the second stops it. Desktop only, since the main process does the recording, and* shown only while `transcriptionEnabled` is on and the computer can transcribe. Its corner badge reads "Beta" while idle and the- * time elapsed while recording, which turns red, with a message once, when a source stops- * delivering audio. A recording started from this window opens a reminder beside the button, for+ * time elapsed while recording, which turns red, with a message once per issue, while a source is+ * not captured, delivers no audio or only silence. A recording started from this window opens a reminder beside the button, for* 10 s, to ask the people in the meeting for their consent.*/export default function RecordMeetingButton({ launcherNote }: LauncherNoteProps) {const { icon, title } = useLauncherIconAndTitle(launcherNote);- const { status, error, startedAt, stalledSources } = useTranscriptionState();+ const { status, error, startedAt, sourceIssues } = useTranscriptionState();+ const hasIssue = !!sourceIssues && Object.keys(sourceIssues).length > 0;const [ isEnabled ] = useTriliumOptionBool("transcriptionEnabled");const isSupported = useTranscriptionSupported(isEnabled);const [ keepsRecordings ] = useTriliumOptionBool("transcriptionKeepRecordings");@@ -71,7 +72,7 @@ export default function RecordMeetingButton({ launcherNote }: LauncherNoteProps)}}, [ error ]);- useStalledSourceWarnings(stalledSources);+ useSourceIssueWarnings(sourceIssues);useEffect(() => {if (status !== "recording") {@@ -92,7 +93,7 @@ export default function RecordMeetingButton({ launcherNote }: LauncherNoteProps)<LaunchBarActionButtonlauncherNote={launcherNote}onClick={handleClick}- {...getAppearance(status, icon, title, keepsRecordings, !!stalledSources?.length)}+ {...getAppearance(status, icon, title, keepsRecordings, hasIssue)}/>{status === "idle" && (<Badge text={t("common.beta")} className="record-meeting-beta-badge" />@@ -100,9 +101,7 @@ export default function RecordMeetingButton({ launcherNote }: LauncherNoteProps){status === "recording" && startedAt !== undefined && (<Badgetext={formatElapsed(now - startedAt)}- className={clsx("record-meeting-time-badge", {- stalled: !!stalledSources?.length- })}+ className={clsx("record-meeting-time-badge", { "has-issue": hasIssue })}/>)}{isShowingConsent && (@@ -147,22 +146,43 @@ function ConsentReminder({ getAnchorRect, keepsRecordings, onDismiss }: {);}-/** Shows an error once for each source that joins `stalledSources`. */-function useStalledSourceWarnings(stalledSources: TranscriptSource[] | undefined) {- const warned = useRef<TranscriptSource[]>([]);- const key = stalledSources?.join() ?? "";+type SourceIssues = TranscriptionState["sourceIssues"];++/** Shows an error once each time a source gets an issue in `sourceIssues`, or another one. */+function useSourceIssueWarnings(sourceIssues: SourceIssues) {+ const warned = useRef<SourceIssues>({});+ const key = JSON.stringify(sourceIssues ?? {});useEffect(() => {- const stalled = stalledSources ?? [];- for (const source of stalled.filter((source) => !warned.current.includes(source))) {- toast.showError(source === "microphone"- ? t("record_meeting.no_audio_microphone")- : t("record_meeting.no_audio_system"));+ const issues = sourceIssues ?? {};+ for (const source of Object.keys(issues) as TranscriptSource[]) {+ const issue = issues[source];+ if (issue && warned.current?.[source] !== issue) {+ toast.showError(getIssueWarning(source, issue));+ }}- warned.current = stalled;+ warned.current = issues;}, [ key ]);}+function getIssueWarning(source: TranscriptSource, issue: TranscriptSourceIssue) {+ const isMicrophone = source === "microphone";+ switch (issue) {+ case "not_captured":+ return isMicrophone+ ? t("record_meeting.not_captured_microphone")+ : t("record_meeting.not_captured_system");+ case "no_audio":+ return isMicrophone+ ? t("record_meeting.no_audio_microphone")+ : t("record_meeting.no_audio_system");+ case "silent":+ return isMicrophone+ ? t("record_meeting.silent_microphone")+ : t("record_meeting.silent_system");+ }+}+const BUSY_ICON = "bx bx-loader-alt bx-spin";/**@@ -171,7 +191,7 @@ const BUSY_ICON = "bx bx-loader-alt bx-spin";*/function getAppearance(status: TranscriptionStatus, idleIcon: string, idleTitle: string, keepsRecordings: boolean,- isStalled: boolean+ hasIssue: boolean) {switch (status) {case "idle":@@ -186,7 +206,7 @@ function getAppearance(case "recording":return {icon: "bx bx-stop-circle",- text: isStalled ? t("record_meeting.stop_no_audio") : t("record_meeting.stop"),+ text: hasIssue ? t("record_meeting.stop_with_issue") : t("record_meeting.stop"),className: "record-meeting-active"};case "stopping":diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.cssindex 39da0569bf..e170fdfb36 100644--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.css@@ -175,7 +175,7 @@}}- &.stalled {+ &.has-issue {color: var(--danger-color, #dc3545);.transcript-level-bar {diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsxindex d8972886ea..62122b3feb 100644--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.spec.tsx@@ -525,11 +525,15 @@ describe("TranscriptView", () => {expect(fill("system")).toBe(0);expect(meter("microphone")?.getAttribute("aria-valuenow")).toBe("0.5");- await report({ stalledSources: [ "system" ] });- expect(meter("system")?.classList.contains("stalled")).toBe(true);+ await report({ sourceIssues: { system: "no_audio" } });+ expect(meter("system")?.classList.contains("has-issue")).toBe(true);expect(meter("system")?.textContent).toContain("transcript.no_audio");- expect(meter("microphone")?.classList.contains("stalled")).toBe(false);- expect(meter("microphone")?.textContent).not.toContain("transcript.no_audio");+ expect(meter("microphone")?.classList.contains("has-issue")).toBe(false);+ expect(meter("microphone")?.querySelector(".transcript-level-warning")).toBeNull();+ await report({ sourceIssues: { microphone: "silent", system: "not_captured" } });+ expect(meter("microphone")?.textContent).toContain("transcript.silent");+ expect(meter("system")?.textContent).toContain("transcript.not_captured");+ expect(meter("system")?.textContent).not.toContain("transcript.no_audio");await report({ noteId: "other" });expect(meter("microphone")).toBeNull();diff --git a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsxindex f324f2c605..637ee9754e 100644--- a/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx+++ b/apps/client/src/widgets/type_widgets/transcript/TranscriptView.tsx@@ -2,7 +2,7 @@ import "./TranscriptView.css";import {cleanUtteranceText, getSpeakerKey, markDisfluencies, MAX_SPEAKER_NAME_LENGTH, parseTranscript,- setSpeakerName, type TranscriptSource, type TranscriptUtterance+ setSpeakerName, type TranscriptSource, type TranscriptSourceIssue, type TranscriptUtterance} from "@triliumnext/commons";import clsx from "clsx";import { Fragment } from "preact";@@ -214,32 +214,40 @@ const LEVEL_ICONS: Record<TranscriptSource, string> = {system: "bx-volume-full"};const LEVEL_SOURCES = Object.keys(LEVEL_ICONS) as TranscriptSource[];+const ISSUE_LABELS: Record<TranscriptSourceIssue, () => string> = {+ not_captured: () => t("transcript.not_captured"),+ no_audio: () => t("transcript.no_audio"),+ silent: () => t("transcript.silent")+};/*** While the meeting of `attachment` records, one meter per source, named as the transcript names- * it, filled to its latest level, and saying so when the source delivers no audio. Shown in the- * header of the transcript's section, so it stays in view while the turns scroll or are collapsed.+ * it, filled to its latest level, and saying so when the source is not captured, delivers no+ * audio or only silence. Shown in the header of the transcript's section, so it stays in view+ * while the turns scroll or are collapsed.*/export function TranscriptRecordingLevels({ attachment }: { attachment: FAttachment }) {- const { status, noteId, stalledSources } = useTranscriptionState();+ const { status, noteId, sourceIssues } = useTranscriptionState();if (status !== "recording" || noteId !== attachment.ownerId) {return null;}- return <TranscriptLevels stalledSources={stalledSources ?? []} />;+ return <TranscriptLevels sourceIssues={sourceIssues ?? {}} />;}-function TranscriptLevels({ stalledSources }: { stalledSources: TranscriptSource[] }) {+function TranscriptLevels({ sourceIssues }: {+ sourceIssues: Partial<Record<TranscriptSource, TranscriptSourceIssue>>;+}) {const levels = useTranscriptionLevels();return (<div className="transcript-levels">{LEVEL_SOURCES.map((source) => {const level = levelToMeter(levels[source]);- const isStalled = stalledSources.includes(source);+ const issue = sourceIssues[source];return (<spankey={source}data-source={source}- className={clsx("transcript-level", { stalled: isStalled })}+ className={clsx("transcript-level", { "has-issue": issue })}role="meter"aria-label={speakerName(source)}aria-valuemin={0}@@ -250,9 +258,9 @@ function TranscriptLevels({ stalledSources }: { stalledSources: TranscriptSource<span className={`bx ${LEVEL_ICONS[source]}`} aria-hidden="true" />{speakerName(source)}<span className="transcript-level-bar" aria-hidden="true" />- {isStalled && (+ {issue && (<span className="transcript-level-warning">- {t("transcript.no_audio")}+ {ISSUE_LABELS[issue]()}</span>)}</span>diff --git a/apps/desktop/src/services/transcription/index.spec.ts b/apps/desktop/src/services/transcription/index.spec.tsindex d9d353a374..b259cee63c 100644--- a/apps/desktop/src/services/transcription/index.spec.ts+++ b/apps/desktop/src/services/transcription/index.spec.ts@@ -271,7 +271,8 @@ describe("transcription IPC", () => {}expect(h.broadcast.at(-1)).toEqual(recording);await tick();- expect(h.broadcast.at(-1)).toEqual({ ...recording, stalledSources: [ "microphone" ] });+ expect(h.broadcast.at(-1))+ .toEqual({ ...recording, sourceIssues: { microphone: "no_audio" } });expect(await invoke("transcription-get-state")).toEqual(h.broadcast.at(-1));expect(h.log.error).toHaveBeenCalledExactlyOnceWith("Transcription: no audio from the microphone for 10 s.");@@ -290,6 +291,62 @@ describe("transcription IPC", () => {vi.useRealTimers();});+ it("flags a source that could not be captured from the start, and never as stalled", async () => {+ const invoke = await loadService();+ vi.useFakeTimers();+ h.capture.start.mockResolvedValue([ "microphone" ]);+ await invoke("transcription-start", "meeting");+ const recording = {+ status: "recording", noteId: "meeting", pendingSources: [], startedAt: STARTED_AT,+ sourceIssues: { system: "not_captured" }+ };++ expect(h.broadcast.at(-1)).toEqual(recording);+ for (let second = 1; second <= 12; second++) {+ await vi.advanceTimersByTimeAsync(1000);+ h.listeners?.onLevel("microphone", 0.1);+ }+ expect(h.broadcast.at(-1)).toEqual(recording);+ await invoke("transcription-stop");+ expect(h.broadcast.at(-1)).toEqual(IDLE);+ });++ it("flags a source that delivers only silence, the microphone sooner, until it sounds", async () => {+ const invoke = await loadService();+ vi.useFakeTimers();+ await invoke("transcription-start", "meeting");+ const recording = {+ status: "recording", noteId: "meeting", pendingSources: [], startedAt: STARTED_AT+ };+ const runFor = async (seconds: number) => {+ for (let second = 0; second < seconds; second++) {+ await vi.advanceTimersByTimeAsync(1000);+ h.listeners?.onLevel("microphone", 0);+ h.listeners?.onLevel("system", 0);+ }+ };++ await runFor(14);+ expect(h.broadcast.at(-1)).toEqual(recording);+ await runFor(1);+ expect(h.broadcast.at(-1)).toEqual({ ...recording, sourceIssues: { microphone: "silent" } });+ expect(h.log.error).toHaveBeenCalledExactlyOnceWith(+ "Transcription: only silence from the microphone for 15 s.");++ h.listeners?.onLevel("microphone", 0.01);+ expect(h.broadcast.at(-1)).toEqual(recording);+ expect(h.log.info).toHaveBeenCalledWith("Transcription: audio from the microphone again.");++ await runFor(45);+ expect(h.broadcast.at(-1)).toEqual({+ ...recording, sourceIssues: { microphone: "silent", system: "silent" }+ });+ expect(h.log.error).toHaveBeenCalledWith(+ "Transcription: only silence from the system for 60 s.");+ await invoke("transcription-stop");+ vi.useRealTimers();+ });+it("says once that a locked protected session holds back the transcript, and saves it on unlocking", async () => {h.isProtected = true;const invoke = await loadService();diff --git a/apps/desktop/src/services/transcription/index.ts b/apps/desktop/src/services/transcription/index.tsindex 0e4082db56..8b5c374450 100644--- a/apps/desktop/src/services/transcription/index.ts+++ b/apps/desktop/src/services/transcription/index.ts@@ -1,5 +1,5 @@import type {- TranscriptionState, TranscriptSource, TranscriptUtterance+ TranscriptionState, TranscriptSource, TranscriptSourceIssue, TranscriptUtterance} from "@triliumnext/commons";import { becca, events, getLog, options, protected_session } from "@triliumnext/core";import dataDirs from "@triliumnext/server/src/services/data_dir.js";@@ -31,11 +31,24 @@ const QUIT_TIMEOUT_MS = 15_000;*/const NO_AUDIO_MS = 10_000;+/**+ * How long a source can deliver only digital silence before it counts as silent. A working+ * microphone picks up some noise even in a quiet room, while the meeting audio is digital silence+ * whenever nobody speaks, so the meeting gets longer.+ */+const SILENCE_MS: Record<TranscriptSource, number> = {+ microphone: 15_000,+ system: 60_000+};+const SOURCES = Object.keys(SILENCE_MS) as TranscriptSource[];+interface Recording {worker: TranscriptionWorker;capture: CaptureWindow;- /** When each source last delivered a chunk, in milliseconds since the epoch. */+ /** When each captured source last delivered a chunk, in milliseconds since the epoch. */lastHeard: Map<TranscriptSource, number>;+ /** When each captured source last delivered a chunk that was not digital silence. */+ lastSound: Map<TranscriptSource, number>;audioCheck?: ReturnType<typeof setInterval>;}@@ -102,7 +115,8 @@ export async function startRecording(noteId: unknown): Promise<string> {onUnexpectedExit: (code) => handleUnexpectedExit(recording, code),log: getLog()}),- lastHeard: new Map()+ lastHeard: new Map(),+ lastSound: new Map()};activeRecording = recording;try {@@ -121,9 +135,11 @@ export async function startRecording(noteId: unknown): Promise<string> {getLog().info(`Transcription: recording ${sources.join(" and ")} for note ${noteId}.`);for (const source of sources) {recording.lastHeard.set(source, Date.now());+ recording.lastSound.set(source, Date.now());}- recording.audioCheck = setInterval(() => checkAudio(recording), 1000);+ recording.audioCheck = setInterval(() => updateSourceIssues(recording), 1000);setState({ ...state, status: "recording", startedAt });+ updateSourceIssues(recording);return "";} catch (e) {activeRecording = null;@@ -299,44 +315,79 @@ function handleUnexpectedExit(recording: Recording, code: number) {broadcast({ ...IDLE, error: t("transcription.stopped-unexpectedly") });}-/** Passes a source's level on to every window, and clears that source's stall. */+/** Passes a source's level on to every window, and updates the sources' issues. */function handleLevel(recording: Recording, source: TranscriptSource, level: number) {if (activeRecording !== recording) {return;}- recording.lastHeard.set(source, Date.now());- if (state.stalledSources?.includes(source)) {- getLog().info(`Transcription: audio from the ${source} again.`);- setStalledSources(state.stalledSources.filter((stalled) => stalled !== source));+ const now = Date.now();+ recording.lastHeard.set(source, now);+ if (level > 0) {+ recording.lastSound.set(source, now);}for (const window of BrowserWindow.getAllWindows()) {window.webContents.send("transcription-level", source, level);}+ updateSourceIssues(recording);}-/** Reports the sources that have delivered nothing for {@link NO_AUDIO_MS}. */-function checkAudio(recording: Recording) {+/** Works out the issue of every source, logs each one that changed, and reports them. */+function updateSourceIssues(recording: Recording) {if (activeRecording !== recording || state.status !== "recording") {return;}const now = Date.now();- const stalled = [ ...recording.lastHeard ]- .filter(([ , lastHeard ]) => now - lastHeard >= NO_AUDIO_MS)- .map(([ source ]) => source)- .sort();- const current = state.stalledSources ?? [];- if (stalled.join() === current.join()) {+ const current = state.sourceIssues ?? {};+ const issues: Partial<Record<TranscriptSource, TranscriptSourceIssue>> = {};+ let hasChanged = false;+ for (const source of SOURCES) {+ const issue = getSourceIssue(recording, source, now);+ if (issue) {+ issues[source] = issue;+ }+ if (issue !== current[source]) {+ hasChanged = true;+ logSourceIssue(source, issue);+ }+ }+ if (!hasChanged) {return;}- for (const source of stalled.filter((source) => !current.includes(source))) {- getLog().error(`Transcription: no audio from the ${source} for ${NO_AUDIO_MS / 1000} s.`);+ const { sourceIssues: _, ...rest } = state;+ setState(Object.keys(issues).length ? { ...rest, sourceIssues: issues } : rest);+}++function getSourceIssue(+ recording: Recording, source: TranscriptSource, now: number+): TranscriptSourceIssue | undefined {+ const lastHeard = recording.lastHeard.get(source);+ if (lastHeard === undefined) {+ return "not_captured";+ }+ if (now - lastHeard >= NO_AUDIO_MS) {+ return "no_audio";+ }+ if (now - (recording.lastSound.get(source) ?? lastHeard) >= SILENCE_MS[source]) {+ return "silent";}- setStalledSources(stalled);}-function setStalledSources(stalledSources: TranscriptSource[]) {- const { stalledSources: _, ...rest } = state;- setState(stalledSources.length ? { ...rest, stalledSources } : rest);+function logSourceIssue(source: TranscriptSource, issue: TranscriptSourceIssue | undefined) {+ switch (issue) {+ case "not_captured":+ getLog().error(`Transcription: the ${source} is not captured.`);+ break;+ case "no_audio":+ getLog().error(`Transcription: no audio from the ${source} for ${NO_AUDIO_MS / 1000} s.`);+ break;+ case "silent":+ getLog().error(+ `Transcription: only silence from the ${source} for ${SILENCE_MS[source] / 1000} s.`);+ break;+ case undefined:+ getLog().info(`Transcription: audio from the ${source} again.`);+ break;+ }}function setState(newState: TranscriptionState) {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 53ede9e291..18d5c09a10 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@@ -47,11 +47,26 @@<p>Only one meeting can be transcribed at a time. The note itself is an ordinarytext note: you can take notes in it during the meeting, rename it or moveit anywhere in the tree. It carries the <code>#meetingRecording</code> label.</p>-<p>If no audio arrives from your microphone or from the meeting for 10 seconds,- Trilium shows a message, the time on the button turns red and the button's- tooltip says that no audio is arriving. Silence does not cause this: a- muted microphone still delivers audio. Stop the transcription and start- it again; what was transcribed until then is kept.</p>+<p>Trilium tells you when your microphone or the meeting's audio is not being+ transcribed. It shows a message saying which one and why, the time on the+ button turns red and the button's tooltip says that some audio is not being+ transcribed:</p>+<ul>+ <li><strong>Not captured</strong>: the transcription started without that+ audio, for example because there is no microphone or because Trilium was+ not allowed to record the screen and its audio. Connect the microphone+ or allow the recording, then stop the transcription and start it again.</li>+ <li><strong>No audio</strong>: nothing has arrived from it for 10 seconds,+ as when its capture hangs. Stop the transcription and start it again; what+ was transcribed until then is kept.</li>+ <li><strong>Only silence</strong>: it has delivered nothing but silence, for+ 15 seconds from your microphone or for a minute from the meeting. A microphone+ muted in your system's settings, or with a mute button of its own, does+ this. A meeting nobody speaks in for a minute does it too, so this message+ can be ignored when the others are just quiet.</li>+</ul>+<p>Each message shows once. <em>No audio</em> and <em>Only silence</em> clear+ by themselves once sound arrives again.</p><p>If the transcription stops on its own, for example because the audio couldno longer be captured, Trilium shows a message and keeps everything transcribeduntil then. Closing Trilium during a meeting waits for the transcription@@ -64,10 +79,10 @@transcribed, the header of the <em>Transcript</em> section shows the levelof your microphone (<em>Me</em>) and of the meeting's audio (<em>Others</em>),so you can tell that both are being heard, even while the section is collapsed;- a source that delivers no audio is marked <em>No audio</em>. While someone- is talking, <em>Speaking…</em> shows under their name until their words are- transcribed. If you are reading the end of the transcript, it scrolls to- follow new text.</p>+ a source that is not being transcribed is marked <em>Not captured</em>, <em>No audio</em> or <em>Only silence</em>.+ While someone is talking, <em>Speaking…</em> shows under their name until+ their words are transcribed. If you are reading the end of the transcript,+ it scrolls to follow new text.</p><ul><li>What you say into your microphone is labeled <em>Me</em>.</li><li>What the other participants say is labeled <em>Speaker 1</em>, <em>Speaker 2</em> anddiff --git a/docs/User Guide/User Guide/Meeting transcription.md b/docs/User Guide/User Guide/Meeting transcription.mdindex 2f8b88cbf1..25e2aad40a 100644--- a/docs/User Guide/User Guide/Meeting transcription.md+++ b/docs/User Guide/User Guide/Meeting transcription.md@@ -25,13 +25,19 @@ The speech recognition models are not part of Trilium. The first time you transcOnly one meeting can be transcribed at a time. The note itself is an ordinary text note: you can take notes in it during the meeting, rename it or move it anywhere in the tree. It carries the `#meetingRecording` label.-If no audio arrives from your microphone or from the meeting for 10 seconds, Trilium shows a message, the time on the button turns red and the button's tooltip says that no audio is arriving. Silence does not cause this: a muted microphone still delivers audio. Stop the transcription and start it again; what was transcribed until then is kept.+Trilium tells you when your microphone or the meeting's audio is not being transcribed. It shows a message saying which one and why, the time on the button turns red and the button's tooltip says that some audio is not being transcribed:++* **Not captured**: the transcription started without that audio, for example because there is no microphone or because Trilium was not allowed to record the screen and its audio. Connect the microphone or allow the recording, then stop the transcription and start it again.+* **No audio**: nothing has arrived from it for 10 seconds, as when its capture hangs. Stop the transcription and start it again; what was transcribed until then is kept.+* **Only silence**: it has delivered nothing but silence, for 15 seconds from your microphone or for a minute from the meeting. A microphone muted in your system's settings, or with a mute button of its own, does this. A meeting nobody speaks in for a minute does it too, so this message can be ignored when the others are just quiet.++Each message shows once. _No audio_ and _Only silence_ clear by themselves once sound arrives again.If the transcription stops on its own, for example because the audio could no longer be captured, Trilium shows a message and keeps everything transcribed until then. Closing Trilium during a meeting waits for the transcription to finish first.## The transcript-The transcript is stored as an [attachment](Basic%20Concepts%20and%20Features/Notes/Attachments.md) of the meeting note and is shown in a collapsible _Transcript_ section above the note's content. It updates as the meeting goes on, one paragraph per speaker turn, each with the time it started. While the meeting is being transcribed, the header of the _Transcript_ section shows the level of your microphone (_Me_) and of the meeting's audio (_Others_), so you can tell that both are being heard, even while the section is collapsed; a source that delivers no audio is marked _No audio_. While someone is talking, _Speaking…_ shows under their name until their words are transcribed. If you are reading the end of the transcript, it scrolls to follow new text.+The transcript is stored as an [attachment](Basic%20Concepts%20and%20Features/Notes/Attachments.md) of the meeting note and is shown in a collapsible _Transcript_ section above the note's content. It updates as the meeting goes on, one paragraph per speaker turn, each with the time it started. While the meeting is being transcribed, the header of the _Transcript_ section shows the level of your microphone (_Me_) and of the meeting's audio (_Others_), so you can tell that both are being heard, even while the section is collapsed; a source that is not being transcribed is marked _Not captured_, _No audio_ or _Only silence_. While someone is talking, _Speaking…_ shows under their name until their words are transcribed. If you are reading the end of the transcript, it scrolls to follow new text.* 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_.diff --git a/packages/commons/src/lib/electron_api_interface.ts b/packages/commons/src/lib/electron_api_interface.tsindex 303402bb24..e5feb42b72 100644--- a/packages/commons/src/lib/electron_api_interface.ts+++ b/packages/commons/src/lib/electron_api_interface.ts@@ -717,6 +717,13 @@ export interface ElectronDialogApi {/** Phase of the meeting transcription; at most one recording runs at a time. */export type TranscriptionStatus = "idle" | "starting" | "recording" | "stopping";+/**+ * Why a source's audio is not being transcribed: its capture did not start (`not_captured`), it+ * has delivered no audio for 10 s (`no_audio`), as when its capture hangs, or it has delivered+ * only digital silence for a while (`silent`), as from a muted device.+ */+export type TranscriptSourceIssue = "not_captured" | "no_audio" | "silent";+/** What {@link ElectronTranscriptionApi} reports to every window. */export interface TranscriptionState {status: TranscriptionStatus;@@ -725,10 +732,10 @@ export interface TranscriptionState {/** The sources heard speaking, or whose speech is still being transcribed. */pendingSources: TranscriptSource[];/**- * The sources that have delivered no audio for 10 s while recording, as when their capture- * hangs; absent when every source delivers. A muted source still delivers silence.+ * While recording, the sources whose audio is not being transcribed, and why; absent when+ * every source delivers sound.*/- stalledSources?: TranscriptSource[];+ sourceIssues?: Partial<Record<TranscriptSource, TranscriptSourceIssue>>;/*** When the recording started, in milliseconds since the epoch: set once it records, kept while* it stops, absent otherwise.