Skip to content

Build your personal knowledge base with Trilium Notes

feat(transcription): keep recordings for troubleshooting behind a switch

Elian Doranc904acd9d79c
diff --git a/.claude/skills/working-with-transcription/SKILL.md b/.claude/skills/working-with-transcription/SKILL.md
index 5cdfe09876..5c91479140 100644
--- a/.claude/skills/working-with-transcription/SKILL.md
+++ b/.claude/skills/working-with-transcription/SKILL.md
@@ -5,7 +5,7 @@ description: Use when working on Trilium's meeting transcription — the desktop
# Working with transcription
-Desktop transcribes a meeting on the user's machine: no audio leaves it, and outside development builds none is kept. Standalone has only a prototype (`apps/standalone/transcription-poc/`, see its README).
+Desktop transcribes a meeting on the user's machine: no audio leaves it, and none is kept unless the user turns on "Keep recordings for troubleshooting". Standalone has only a prototype (`apps/standalone/transcription-poc/`, see its README).
## The pipeline
@@ -44,7 +44,7 @@ The main process opens the capture window, starts the transcription process and
| `…/transcription_worker.ts` | The transcription process's entry (bundled as `transcription_worker.cjs`): `PortCapture`, the session, the dev sinks and taps |
| `…/engine.ts` | Transcription process: `loadSherpaEngine(models)`: recognizer and VAD settings (`RECOGNIZER_SETTINGS`, `DECODING_SETTINGS`, `VAD_SETTINGS`), reported as `settings` |
| `…/session.ts` | Transcription process: `RecordingSession`: per-source segmentation, the decode queue, sinks, taps, pending sources |
-| `…/audio_recorder.ts` | Transcription process: development recordings, `WavRecorder` and `TranscriptFileSink` |
+| `…/audio_recorder.ts` | Transcription process: recordings for troubleshooting, `WavRecorder` and `TranscriptFileSink` |
Nothing 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 |
@@ -74,9 +74,9 @@ curl -fL -o speaker/nemo_en_titanet_small.onnx "$R/speaker-recongition-models/ne
Without either directory, starting fails with `transcription.model-not-downloaded`. `replay.mjs` takes the precision `recording.json` names (int8 for recordings made before it was recorded) and falls back to the other.
-## Development recordings
+## Recordings for troubleshooting
-`pnpm desktop:start` (where `isDev()` holds) keeps every transcription in `apps/desktop/data/transcription-recordings/<created>_<noteId>/`:
+While the non-synced option `transcriptionKeepRecordings` is on (Options → Transcription → "Keep recordings for troubleshooting", off by default, its switch tinted red), every transcription is kept in `<data dir>/transcription-recordings/<created>_<noteId>/`; for `pnpm desktop:start` that is `apps/desktop/data/transcription-recordings/`, so turn the switch on there once to get recordings for the scripts below. Development builds follow the switch like any other. The settings link to the folder through `electronApi.transcription.getRecordingsDirectory()`, which creates it.
| File | Holds |
|---|---|
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index fe0c0a394f..697bc8a79d 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4631,6 +4631,19 @@
"model_standard": "Standard",
"model_high_accuracy": "High accuracy",
"identify_speakers": "Identify speakers",
- "identify_speakers_description": "Tells the other participants apart and labels each of their utterances with its speaker; what you say into your microphone is always yours. Turn it off if it mixes up voices, or to save the processing it takes during a recording. It applies from the next recording."
+ "identify_speakers_description": "Tells the other participants apart and labels each of their utterances with its speaker; what you say into your microphone is always yours. Turn it off if it mixes up voices, or to save the processing it takes during a recording. It applies from the next recording.",
+ "troubleshooting_title": "Troubleshooting",
+ "keep_recordings": "Keep recordings for troubleshooting",
+ "keep_recordings_description": "Keeps the audio of everyone in the meeting, with the settings used and the transcript as it was produced, so that a problem with a recording can be reported and reproduced. It takes about 230 MB per hour of meeting, is never deleted automatically and is not encrypted, even for protected notes. Recording other participants can require their consent where you or they are.",
+ "saved_in": "Saved in"
+ },
+ "resources_options": {
+ "list_title": "Resources",
+ "list_description": "Large files that features download when they are first needed, such as the speech recognition models. They are stored on this device and are not synced, so each device downloads its own copy.",
+ "installed": "Installed",
+ "not_downloaded": "Not downloaded",
+ "partially_downloaded": "{{downloaded}} of {{size}} downloaded",
+ "space_used": "Space used",
+ "no_resources": "No feature on this device uses downloadable resources."
}
}
diff --git a/apps/client/src/widgets/react/DirectoryLink.css b/apps/client/src/widgets/react/DirectoryLink.css
new file mode 100644
index 0000000000..2c4b2a3be3
--- /dev/null
+++ b/apps/client/src/widgets/react/DirectoryLink.css
@@ -0,0 +1,46 @@
+.tn-card-section.directory-location {
+ display: grid;
+ grid-template-columns: auto 1fr auto;
+ grid-template-rows: auto auto;
+ align-items: center;
+ column-gap: 16px;
+
+ .directory-location-icon {
+ grid-row: 1 / span 2;
+ font-size: 2.2em;
+ opacity: .6;
+ }
+
+ .directory-location-label {
+ grid-column: 2;
+ font-size: .85em;
+ opacity: .7;
+ }
+
+ .directory-location-path {
+ grid-column: 2;
+ overflow-wrap: anywhere;
+ }
+
+ .directory-location-actions {
+ display: flex;
+ grid-column: 3;
+ grid-row: 1 / span 2;
+ gap: 8px;
+
+ .btn {
+ white-space: nowrap;
+ }
+ }
+}
+
+body.mobile .tn-card-section.directory-location {
+ grid-template-columns: auto 1fr;
+
+ .directory-location-actions {
+ grid-column: 2;
+ grid-row: auto;
+ flex-wrap: wrap;
+ margin-top: 8px;
+ }
+}
diff --git a/apps/client/src/widgets/react/DirectoryLink.tsx b/apps/client/src/widgets/react/DirectoryLink.tsx
index 9f2d22521f..bef5ad6b76 100644
--- a/apps/client/src/widgets/react/DirectoryLink.tsx
+++ b/apps/client/src/widgets/react/DirectoryLink.tsx
@@ -1,5 +1,11 @@
+import "./DirectoryLink.css";
+
+import type { ComponentChildren } from "preact";
+
import openService from "../../services/open.js";
import { isElectron } from "../../services/utils.js";
+import { CardSection } from "./Card.js";
+import Icon from "./Icon.js";
/**
* A filesystem location, handed to the OS file manager on click. Only the desktop application can
@@ -23,6 +29,25 @@ export default function DirectoryLink({ directory }: { directory: string }) {
return <ShellLink path={directory} onOpen={() => openService.openDirectory(directory)} />;
}
+/**
+ * A card section that says where something is kept: a folder icon beside `label` and the
+ * `directory` as a {@link DirectoryLink}, with any `actions` on the trailing edge.
+ */
+export function DirectoryLocation({ label, directory, actions }: {
+ label: string;
+ directory: string;
+ actions?: ComponentChildren;
+}) {
+ return (
+ <CardSection className="directory-location">
+ <Icon icon="bx bx-folder" className="directory-location-icon" />
+ <div className="directory-location-label">{label}</div>
+ <div className="directory-location-path"><DirectoryLink directory={directory} /></div>
+ {actions && <div className="directory-location-actions">{actions}</div>}
+ </CardSection>
+ );
+}
+
/**
* A file, revealed in the file manager: the folder holding it opens with the file itself selected.
* For a file the user is meant to find rather than to open, the database being the one Trilium
diff --git a/apps/client/src/widgets/type_widgets/options/backup.css b/apps/client/src/widgets/type_widgets/options/backup.css
index 1f1f427106..a328b91c66 100644
--- a/apps/client/src/widgets/type_widgets/options/backup.css
+++ b/apps/client/src/widgets/type_widgets/options/backup.css
@@ -61,52 +61,3 @@
}
}
-.backup-location .tn-card-section {
- display: grid;
- grid-template-columns: auto 1fr auto;
- grid-template-rows: auto auto;
- align-items: center;
- column-gap: 16px;
-
- .backup-location-icon {
- grid-row: 1 / span 2;
- font-size: 2.2em;
- opacity: .6;
- }
-
- .backup-location-label {
- grid-column: 2;
- font-size: .85em;
- opacity: .7;
- }
-
- .backup-location-path {
- grid-column: 2;
- overflow-wrap: anywhere;
- }
-
- .backup-location-actions {
- display: flex;
- grid-column: 3;
- grid-row: 1 / span 2;
- gap: 8px;
-
- .btn {
- white-space: nowrap;
- }
- }
-}
-
-/* On a phone the buttons drop below the path rather than standing beside it: their labels do not
- wrap, so the third column took 143px of 325px and left the path spelling itself down a column
- 81px wide. They keep the text's indent, and wrap between themselves once there are two. */
-body.mobile .backup-location .tn-card-section {
- grid-template-columns: auto 1fr;
-
- .backup-location-actions {
- grid-column: 2;
- grid-row: auto;
- flex-wrap: wrap;
- margin-top: 8px;
- }
-}
diff --git a/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsx b/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsx
index 098c96c846..660598058b 100644
--- a/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsx
@@ -81,16 +81,16 @@ afterEach(cleanup);
describe("BackupLocation", () => {
it("shows the effective location, offering a reset only once a custom one is in use", () => {
renderLocation();
- expect(container?.querySelector(".backup-location-path")?.textContent).toBe(DEFAULT_DIR);
+ expect(container?.querySelector(".directory-location-path")?.textContent).toBe(DEFAULT_DIR);
// On the desktop the location opens in the OS file manager, as in the About dialog.
- expect(container?.querySelector(".backup-location-path a.tn-link")).not.toBeNull();
+ expect(container?.querySelector(".directory-location-path a.tn-link")).not.toBeNull();
expect(button("select-backup-location-button")?.disabled).toBe(false);
expect(button("reset-backup-location-button")).toBeNull();
cleanup();
mocks.customDir = CUSTOM_DIR;
renderLocation(CUSTOM_DIR);
- expect(container?.querySelector(".backup-location-path")?.textContent).toBe(CUSTOM_DIR);
+ expect(container?.querySelector(".directory-location-path")?.textContent).toBe(CUSTOM_DIR);
expect(button("reset-backup-location-button")).not.toBeNull();
});
@@ -103,8 +103,8 @@ describe("BackupLocation", () => {
// The explanation hangs off a wrapper, since a disabled button emits no pointer events.
expect(container?.querySelector(".tn-disabled-reason button")).not.toBeNull();
// Nothing can open a file manager here, so the location stays plain text.
- expect(container?.querySelector(".backup-location-path a")).toBeNull();
- expect(container?.querySelector(".backup-location-path")?.textContent).toBe(DEFAULT_DIR);
+ expect(container?.querySelector(".directory-location-path a")).toBeNull();
+ expect(container?.querySelector(".directory-location-path")?.textContent).toBe(DEFAULT_DIR);
});
it("stores the chosen directory and refreshes, opening the picker at the current location", async () => {
diff --git a/apps/client/src/widgets/type_widgets/options/backup.tsx b/apps/client/src/widgets/type_widgets/options/backup.tsx
index d611d7362b..75c8d693fe 100644
--- a/apps/client/src/widgets/type_widgets/options/backup.tsx
+++ b/apps/client/src/widgets/type_widgets/options/backup.tsx
@@ -18,13 +18,12 @@ import { bootToSetup, canBootToSetup } from "../../../services/setup_mode";
import toast from "../../../services/toast";
import { isElectron } from "../../../services/utils";
import Button from "../../react/Button";
-import { Card, CardSection, OptionCardSection } from "../../react/Card";
-import DirectoryLink from "../../react/DirectoryLink";
+import { Card, OptionCardSection } from "../../react/Card";
+import { DirectoryLocation } from "../../react/DirectoryLink";
import FormPasswordWithConfirmation from "../../react/FormPasswordWithConfirmation";
import FormText from "../../react/FormText";
import FormToggle from "../../react/FormToggle";
import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
-import Icon from "../../react/Icon";
import Modal from "../../react/Modal";
import SetupForm from "../helpers/SetupForm";
import DatabaseFileList from "./components/DatabaseFileList";
@@ -309,13 +308,10 @@ export function BackupLocation({ backupFolderPath, refreshCallback }: { backupFo
return (
<Card className="backup-location" heading={t("backup.location_title")}>
- <CardSection>
- <Icon icon="bx bx-folder" className="backup-location-icon" />
-
- <div className="backup-location-label">{t("backup.saved_in")}</div>
- <div className="backup-location-path"><DirectoryLink directory={backupFolderPath} /></div>
-
- <div className="backup-location-actions">
+ <DirectoryLocation
+ label={t("backup.saved_in")}
+ directory={backupFolderPath}
+ actions={<>
<Button
name="select-backup-location-button"
text={t("backup.select_location")}
@@ -333,8 +329,8 @@ export function BackupLocation({ backupFolderPath, refreshCallback }: { backupFo
onClick={resetToDefault}
/>
)}
- </div>
- </CardSection>
+ </>}
+ />
</Card>
);
}
diff --git a/apps/client/src/widgets/type_widgets/options/transcription.css b/apps/client/src/widgets/type_widgets/options/transcription.css
new file mode 100644
index 0000000000..b1699f0f1f
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/transcription.css
@@ -0,0 +1,3 @@
+.transcription-keep-recordings .switch-widget {
+ --switch-on-track-background: var(--dropdown-item-icon-destructive-color);
+}
diff --git a/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx b/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx
index 869c2fbe2c..5bc69fef25 100644
--- a/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx
@@ -6,8 +6,8 @@ const mocks = vi.hoisted(() => ({
electron: true,
stored: "" as string,
saved: [] as string[],
- speakersEnabled: true,
- savedSpeakers: [] as boolean[]
+ bools: {} as Record<string, boolean>,
+ savedBools: [] as [ string, boolean ][]
}));
vi.mock("../../../services/utils", async (importOriginal) => ({
@@ -24,11 +24,12 @@ vi.mock("../../react/hooks", async (importOriginal) => ({
(value: string) => void mocks.saved.push(value)
],
useTriliumOptionBool: (name: string) => [
- name === "transcriptionSpeakersEnabled" && mocks.speakersEnabled,
- (value: boolean) => void mocks.savedSpeakers.push(value)
+ mocks.bools[name] ?? false,
+ (value: boolean) => void mocks.savedBools.push([ name, value ])
]
}));
+
vi.mock("./components/OptionsPageHeader", () => ({ default: () => <div className="header-stub" /> }));
import TranscriptionSettings from "./transcription";
@@ -39,13 +40,17 @@ beforeEach(() => {
mocks.electron = true;
mocks.stored = "parakeet-fp32";
mocks.saved = [];
- mocks.speakersEnabled = true;
- mocks.savedSpeakers = [];
+ mocks.bools = { transcriptionSpeakersEnabled: true, transcriptionKeepRecordings: false };
+ mocks.savedBools = [];
+ window.electronApi = {
+ transcription: { getRecordingsDirectory: async () => "/data/transcription-recordings" }
+ } as unknown as typeof window.electronApi;
host = document.body.appendChild(document.createElement("div"));
});
afterEach(() => {
render(null, host);
+ window.electronApi = undefined;
document.body.innerHTML = "";
});
@@ -77,17 +82,30 @@ describe("TranscriptionSettings", () => {
it("turns speaker identification off", () => {
open();
- const toggle = host.querySelector<HTMLInputElement>("input.switch-toggle[id^='identify-speakers-']");
- if (!toggle) {
- throw new Error("The speaker switch is missing.");
- }
+ const toggle = findToggle("identify-speakers");
expect(toggle.checked).toBe(true);
act(() => {
toggle.checked = false;
toggle.dispatchEvent(new Event("input", { bubbles: true }));
});
- expect(mocks.savedSpeakers).toEqual([ false ]);
+ expect(mocks.savedBools).toEqual([ [ "transcriptionSpeakersEnabled", false ] ]);
+ });
+
+ it("keeps recordings for troubleshooting on request, on a switch tinted as a warning", async () => {
+ open();
+ const toggle = findToggle("keep-recordings");
+ expect(toggle.checked).toBe(false);
+ expect(toggle.closest(".transcription-keep-recordings")).not.toBeNull();
+
+ await act(async () => {});
+ expect(host.querySelector(".directory-location-path")?.textContent).toBe("/data/transcription-recordings");
+
+ act(() => {
+ toggle.checked = true;
+ toggle.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+ expect(mocks.savedBools).toEqual([ [ "transcriptionKeepRecordings", true ] ]);
});
it("shows the default model for a value it does not know", () => {
@@ -101,3 +119,12 @@ describe("TranscriptionSettings", () => {
expect(host.textContent).toContain("desktop.web_placeholder");
});
});
+
+/** The switch of the section `name`, whose id is `<name>-<random>`. */
+function findToggle(name: string) {
+ const toggle = host.querySelector<HTMLInputElement>(`input.switch-toggle[id^='${name}-']`);
+ if (!toggle) {
+ throw new Error(`The ${name} switch is missing.`);
+ }
+ return toggle;
+}
diff --git a/apps/client/src/widgets/type_widgets/options/transcription.tsx b/apps/client/src/widgets/type_widgets/options/transcription.tsx
index d25243e3b2..fea517558e 100644
--- a/apps/client/src/widgets/type_widgets/options/transcription.tsx
+++ b/apps/client/src/widgets/type_widgets/options/transcription.tsx
@@ -1,8 +1,12 @@
+import "./transcription.css";
+
import { getTranscriptionModel, TRANSCRIPTION_MODELS, type TranscriptionModelId } from "@triliumnext/commons";
+import { useEffect, useState } from "preact/hooks";
import { t } from "../../../services/i18n";
import { isElectron } from "../../../services/utils";
import { Card, OptionCardSection } from "../../react/Card";
+import { DirectoryLocation } from "../../react/DirectoryLink";
import FormSelect from "../../react/FormSelect";
import FormToggle from "../../react/FormToggle";
import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
@@ -23,6 +27,7 @@ export default function TranscriptionSettings() {
<>
<OptionsPageHeader />
<RecognitionSettings />
+ <TroubleshootingSettings />
</>
);
}
@@ -62,3 +67,37 @@ function RecognitionSettings() {
</Card>
);
}
+
+function TroubleshootingSettings() {
+ const [ keepRecordings, setKeepRecordings ] = useTriliumOptionBool("transcriptionKeepRecordings");
+ const [ directory, setDirectory ] = useState<string>();
+
+ useEffect(() => {
+ let isCurrent = true;
+ void window.electronApi?.transcription.getRecordingsDirectory().then((result) => {
+ if (isCurrent) {
+ setDirectory(result);
+ }
+ });
+ return () => {
+ isCurrent = false;
+ };
+ }, []);
+
+ return (
+ <Card heading={t("transcription_options.troubleshooting_title")}>
+ <OptionCardSection
+ name="keep-recordings"
+ className="transcription-keep-recordings"
+ label={t("transcription_options.keep_recordings")}
+ description={t("transcription_options.keep_recordings_description")}
+ >
+ <FormToggle currentValue={keepRecordings} onChange={setKeepRecordings} />
+ </OptionCardSection>
+
+ {directory && (
+ <DirectoryLocation label={t("transcription_options.saved_in")} directory={directory} />
+ )}
+ </Card>
+ );
+}
diff --git a/apps/desktop/src/preload.spec.ts b/apps/desktop/src/preload.spec.ts
index b728f122e4..193e0ca7e5 100644
--- a/apps/desktop/src/preload.spec.ts
+++ b/apps/desktop/src/preload.spec.ts
@@ -724,11 +724,12 @@ describe("preload script", () => {
describe("transcription", () => {
const transcription = () => getGroup("transcription");
- it("start, stop, getState and renameSpeaker invoke their IPC channels", async () => {
+ it("start, stop, getState, renameSpeaker and getRecordingsDirectory invoke their IPC channels", async () => {
await transcription().start("meeting");
await transcription().stop();
await transcription().getState();
await transcription().renameSpeaker("transcript1", "system:1", "Alexandra");
+ await transcription().getRecordingsDirectory();
expect(ipcRendererInvoked).toEqual([
{ channel: "transcription-start", args: [ "meeting" ] },
{ channel: "transcription-stop", args: [] },
@@ -736,7 +737,8 @@ describe("preload script", () => {
{
channel: "transcription-rename-speaker",
args: [ "transcript1", "system:1", "Alexandra" ]
- }
+ },
+ { channel: "transcription-get-recordings-directory", args: [] }
]);
});
diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts
index f1c67665a4..39910e06e0 100644
--- a/apps/desktop/src/preload.ts
+++ b/apps/desktop/src/preload.ts
@@ -267,6 +267,9 @@ contextBridge.exposeInMainWorld("electronApi", {
renameSpeaker(attachmentId: string, key: string, name: string) {
return ipcRenderer.invoke("transcription-rename-speaker", attachmentId, key, name);
},
+ getRecordingsDirectory() {
+ return ipcRenderer.invoke("transcription-get-recordings-directory");
+ },
onStateChanged(callback: (state: TranscriptionState) => void) {
const listener = (_event: unknown, state: TranscriptionState) => callback(state);
ipcRenderer.on("transcription-state", listener);
diff --git a/apps/desktop/src/services/transcription/index.spec.ts b/apps/desktop/src/services/transcription/index.spec.ts
index 2c9ca98d39..25a8595a5f 100644
--- a/apps/desktop/src/services/transcription/index.spec.ts
+++ b/apps/desktop/src/services/transcription/index.spec.ts
@@ -14,7 +14,8 @@ const h = vi.hoisted(() => ({
isProtected: false,
isProtectedSessionAvailable: false,
coreListeners: new Map<string, () => void>(),
- isDev: false,
+ keepRecordings: false,
+ mkdirSync: vi.fn(),
installedResources: [] as string[],
transcriptionModel: null as string | null,
speakersEnabled: true,
@@ -65,16 +66,21 @@ vi.mock("@triliumnext/core", () => ({
getLog: () => h.log,
options: {
getOptionOrNull: (name: string) => name === "transcriptionModel" ? h.transcriptionModel : null,
- getOptionBool: (name: string) => name === "transcriptionSpeakersEnabled" && h.speakersEnabled
+ getOptionBool: (name: string) =>
+ (name === "transcriptionSpeakersEnabled" && h.speakersEnabled)
+ || (name === "transcriptionKeepRecordings" && h.keepRecordings)
},
protected_session: { isProtectedSessionAvailable: () => h.isProtectedSessionAvailable },
- utils: { isDev: () => h.isDev }
}));
+vi.mock("fs", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("fs")>();
+ return { default: { ...actual, mkdirSync: h.mkdirSync } };
+});
vi.mock("i18next", () => ({
t: (key: string, options?: object) => options ? `${key} ${JSON.stringify(options)}` : key
}));
vi.mock("@triliumnext/server/src/services/data_dir.js", () => ({
- default: { TRILIUM_DATA_DIR: "/data" }
+ default: { TRILIUM_DATA_DIR: "data" }
}));
vi.mock("@triliumnext/server/src/services/resources.js", () => ({
default: {
@@ -134,7 +140,7 @@ beforeEach(() => {
h.isProtected = false;
h.isProtectedSessionAvailable = false;
h.broadcast.length = 0;
- h.isDev = false;
+ h.keepRecordings = false;
h.transcriptionModel = null;
h.speakersEnabled = true;
h.installedResources = [
@@ -316,7 +322,7 @@ describe("transcription IPC", () => {
expect(h.sink.renameSpeaker).toHaveBeenCalledTimes(2);
});
- it("keeps the audio and the transcript as produced only in development builds", async () => {
+ it("keeps the audio and the transcript as produced only while the option is on", async () => {
vi.useFakeTimers({ now: STARTED_AT, toFake: [ "Date" ] });
const invoke = await loadService();
@@ -324,13 +330,21 @@ describe("transcription IPC", () => {
expect(h.worker.start.mock.calls[0][0].recordingDirectory).toBeNull();
await invoke("transcription-stop");
- h.isDev = true;
+ h.keepRecordings = true;
await invoke("transcription-start", "meeting");
expect(h.worker.start.mock.calls[1][0].recordingDirectory)
- .toBe("/data/transcription-recordings/2026-10-14T09-30-00-000Z_meeting");
+ .toBe(path.resolve("data", "transcription-recordings", "2026-10-14T09-30-00-000Z_meeting"));
vi.useRealTimers();
});
+ it("tells where the recordings are kept, as an absolute path, creating the directory", async () => {
+ const invoke = await loadService();
+ const directory = path.resolve("data", "transcription-recordings");
+ expect(await invoke("transcription-get-recordings-directory")).toBe(directory);
+ expect(path.isAbsolute(directory)).toBe(true);
+ expect(h.mkdirSync).toHaveBeenCalledExactlyOnceWith(directory, { recursive: true });
+ });
+
it("refuses a missing note or model, without changing state", async () => {
const invoke = await loadService();
diff --git a/apps/desktop/src/services/transcription/index.ts b/apps/desktop/src/services/transcription/index.ts
index 5b04aa81ed..5f0b1faba5 100644
--- a/apps/desktop/src/services/transcription/index.ts
+++ b/apps/desktop/src/services/transcription/index.ts
@@ -1,8 +1,9 @@
import type { TranscriptionState, TranscriptUtterance } from "@triliumnext/commons";
-import { becca, events, getLog, options, protected_session, utils as coreUtils } from "@triliumnext/core";
+import { becca, events, getLog, options, protected_session } from "@triliumnext/core";
import dataDirs from "@triliumnext/server/src/services/data_dir.js";
import resources from "@triliumnext/server/src/services/resources.js";
import { app, BrowserWindow, ipcMain, MessageChannelMain } from "electron";
+import fs from "fs";
import { t } from "i18next";
import path from "path";
@@ -11,8 +12,11 @@ import { CaptureWindow } from "./capture";
import { getModelPaths, TRANSCRIPTION_MODELS } from "./model";
import { TranscriptionWorker } from "./worker_client";
-/** Where development builds keep the audio of each recording, one directory per recording. */
-export const RECORDINGS_DIR = path.join(dataDirs.TRILIUM_DATA_DIR, "transcription-recordings");
+/**
+ * Where the audio and the transcript as produced of each recording are kept, one directory per
+ * recording, while `transcriptionKeepRecordings` is on.
+ */
+export const RECORDINGS_DIR = path.resolve(dataDirs.TRILIUM_DATA_DIR, "transcription-recordings");
const IDLE: TranscriptionState = { status: "idle", noteId: null, pendingSources: [] };
@@ -43,6 +47,7 @@ export function setupTranscriptionHandlers() {
ipcMain.handle("transcription-start", (_event, noteId: unknown) => startRecording(noteId));
ipcMain.handle("transcription-stop", () => stopRecording());
ipcMain.handle("transcription-get-state", () => getState());
+ ipcMain.handle("transcription-get-recordings-directory", () => getRecordingsDirectory());
ipcMain.handle("transcription-rename-speaker", (_event, attachmentId: unknown, key: unknown,
name: unknown) => renameSpeaker(attachmentId, key, name));
app.on("before-quit", (event) => finishBeforeQuit(event));
@@ -88,7 +93,9 @@ export async function startRecording(noteId: unknown): Promise<string> {
const { startedAt } = await recording.worker.start({
noteId,
models,
- recordingDirectory: coreUtils.isDev() ? getRecordingDirectory(Date.now(), noteId) : null
+ recordingDirectory: options.getOptionBool("transcriptionKeepRecordings")
+ ? getRecordingDirectory(Date.now(), noteId)
+ : null
});
sink.open(startedAt);
writer = sink;
@@ -153,6 +160,12 @@ export function renameSpeaker(attachmentId: unknown, key: unknown, name: unknown
return true;
}
+/** Returns {@link RECORDINGS_DIR}, creating it so that the settings can open it before any recording. */
+function getRecordingsDirectory() {
+ fs.mkdirSync(RECORDINGS_DIR, { recursive: true });
+ return RECORDINGS_DIR;
+}
+
/** The directory under {@link RECORDINGS_DIR} for a recording of `noteId` begun at `createdAt`. */
export function getRecordingDirectory(createdAt: number, noteId: string) {
const timestamp = new Date(createdAt).toISOString().replace(/[:.]/g, "-");
diff --git a/apps/desktop/src/services/transcription/protocol.ts b/apps/desktop/src/services/transcription/protocol.ts
index ffcc7e108e..abfa8ce24b 100644
--- a/apps/desktop/src/services/transcription/protocol.ts
+++ b/apps/desktop/src/services/transcription/protocol.ts
@@ -25,7 +25,7 @@ export type WorkerRequest =
type: "start";
noteId: string;
models: ModelPaths;
- /** Where development builds keep the audio and the transcript as produced, else `null`. */
+ /** Where to keep the audio and the transcript as produced, or `null` to keep neither. */
recordingDirectory: string | null;
}
/** Sent once the recording runs, with the port the capture page posts its samples to. */
diff --git a/packages/commons/src/lib/electron_api_interface.ts b/packages/commons/src/lib/electron_api_interface.ts
index 3cc90cfba3..3e455d31bd 100644
--- a/packages/commons/src/lib/electron_api_interface.ts
+++ b/packages/commons/src/lib/electron_api_interface.ts
@@ -757,6 +757,12 @@ export interface ElectronTranscriptionApi {
*/
renameSpeaker(attachmentId: string, key: string, name: string): Promise<boolean>;
+ /**
+ * Returns the directory that keeps the audio and the transcript as produced of each recording
+ * while `transcriptionKeepRecordings` is on, creating it if needed.
+ */
+ getRecordingsDirectory(): Promise<string>;
+
/**
* Calls `callback` every time the state changes, in any window.
*
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 1cd07e700e..e2405e99e1 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -211,6 +211,11 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
transcriptionModel: string;
/** Whether a recording tells the other participants apart, labeling each utterance with its speaker. */
transcriptionSpeakersEnabled: boolean;
+ /**
+ * Whether a recording keeps its audio and the transcript as produced in the data directory, for
+ * troubleshooting. Not synced: the files stay on the device that recorded.
+ */
+ transcriptionKeepRecordings: boolean;
leftPaneVisible: boolean;
rightPaneVisible: boolean;
nativeTitleBarVisible: boolean;
diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.ts
index 99a19b3aab..c8d4918b67 100644
--- a/packages/trilium-core/src/routes/api/options.ts
+++ b/packages/trilium-core/src/routes/api/options.ts
@@ -66,6 +66,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"transcriptCleanupEnabled",
"transcriptionModel",
"transcriptionSpeakersEnabled",
+ "transcriptionKeepRecordings",
"codeNotesMimeTypes",
"contentManagerSortOrder",
"contentManagerViewMode",
diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.ts
index 0bcaebce7b..99852bf43b 100644
--- a/packages/trilium-core/src/services/options_init.ts
+++ b/packages/trilium-core/src/services/options_init.ts
@@ -186,6 +186,7 @@ const defaultOptions: DefaultOption[] = [
{ name: "transcriptCleanupEnabled", value: "true", isSynced: true },
{ name: "transcriptionModel", value: DEFAULT_TRANSCRIPTION_MODEL, isSynced: false },
{ name: "transcriptionSpeakersEnabled", value: "true", isSynced: true },
+ { name: "transcriptionKeepRecordings", value: "false", isSynced: false },
{ name: "codeNoteTabWidth", value: "4", isSynced: true },
{ name: "codeNoteIndentWithTabs", value: "false", isSynced: true },
{