Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(notes): persist diarization metadata on upload and URL-ingest notes (#1610)
Joshua8fbff3ed44a5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a00c299d2..226e3a67e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+- **Uploaded and URL-ingested notes remember their speaker detection.** A note created through Upload ran speaker detection but stored none of it — the note now records that diarization ran, the speaker count you chose, and the audio duration, so it behaves like a meeting note when you record into it or resolve participants. An upload with speaker detection off writes nothing, preserving your global speaker setting. Present since upload speaker detection shipped in 1.7.6. (#1610)+## [1.8.3] - 2026-08-12GPU acceleration for local transcription gets an overhaul: the status you see is now the truth, enabling it works without a restart, older NVIDIA cards are routed to a backend that actually works on them, and a GPU failure can never cost you a dictation. LLM routing gains the same fail-closed treatment speech-to-text received in 1.8.2. Launch at login arrives on Linux, and transcription errors stop blaming your microphone.diff --git a/src/components/notes/UploadAudioView.tsx b/src/components/notes/UploadAudioView.tsxindex 894b835d9..212c88eb9 100644--- a/src/components/notes/UploadAudioView.tsx+++ b/src/components/notes/UploadAudioView.tsx@@ -64,6 +64,7 @@ import { isTranscriptionContextAllowed } from "../../stores/policyRules";import { usePolicyStore } from "../../stores/policyStore";import { usePolicySnapshot, useTranscriptionContextAllowed } from "../../hooks/usePolicy";import { resolveTranscriptionRoute } from "../../helpers/transcriptionRoute";+import { buildUploadNoteMetadata } from "../../helpers/uploadNoteMetadata";type UploadState = "idle" | "selected" | "downloading" | "transcribing" | "complete" | "error";@@ -656,14 +657,15 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: Uploa}try {+ const diarization: DiarizationSettings = {+ enabled: diarizationEnabled,+ localModelsReady: !!diarizationModelsReady,+ numSpeakers: diarizationNumSpeakers ? Number(diarizationNumSpeakers) : null,+ };const res: FileTranscriptionResult = await transcribeFileWithSpeakers(currentFile.path,buildTranscriptionConfig(),- {- enabled: diarizationEnabled,- localModelsReady: !!diarizationModelsReady,- numSpeakers: diarizationNumSpeakers ? Number(diarizationNumSpeakers) : null,- },+ diarization,currentFile.durationSeconds,{ requestId }).finally(() => {@@ -700,14 +702,22 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: Uploa}const folderId = selectedFolderId ? Number(selectedFolderId) : null;+ const { audioDurationSeconds, noteUpdates } = buildUploadNoteMetadata(+ diarization,+ res.durationSeconds+ );const noteRes = await window.electronAPI.saveNote(title,res.text,"upload",currentFile.name,- null,+ audioDurationSeconds,folderId);+ if (noteRes.success && noteRes.note && noteUpdates) {+ // Best-effort: a failed metadata write must not error a saved note.+ await window.electronAPI.updateNote(noteRes.note.id, noteUpdates).catch(() => {});+ }if (runId !== runIdRef.current) return;if (noteRes.success && noteRes.note) setNoteId(noteRes.note.id);if (currentTempPath) {diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex fd502e44a..c52e19089 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -3095,7 +3095,9 @@ class IPCHandlers {segments,numSpeakers > 0 ? numSpeakers : MAX_SPEAKER_COUNT);- return { success: true, segments };+ // Callers persist this as audio_duration_seconds: for picked files+ // the renderer has no other duration source.+ return { success: true, segments, durationSeconds };} finally {try {fs.unlinkSync(wavPath);diff --git a/src/helpers/uploadNoteMetadata.js b/src/helpers/uploadNoteMetadata.jsnew file mode 100644index 000000000..2c5445a5e--- /dev/null+++ b/src/helpers/uploadNoteMetadata.js@@ -0,0 +1,33 @@+import { MAX_SPEAKER_COUNT } from "../constants/speakerDetection.json";++// Renderer twin of normalizeStoredSpeakerCount in ./speakerCount.js. That file+// is CommonJS for the main process (database.js, ipcHandlers.js), and renderer+// source cannot load CJS modules under Vite — test/helpers/uploadNoteMetadata+// .test.js holds the two implementations to identical outputs.+function normalizeSpeakerCount(value) {+ const count = Number(value);+ if (!Number.isInteger(count) || count < 1) return null;+ return Math.min(count, MAX_SPEAKER_COUNT);+}++// What the upload and URL-ingest flows persist onto the note row about the+// diarizer invocation, matching the meeting path's write semantics: the columns+// are written only when diarization ran. A null diarization_enabled means "user+// never chose" and consumers fall back to the global speaker setting — writing+// 0 would force diarization off when recording into the note later. The+// expected_speaker_count is only ever a count the diarizer was actually invoked+// with (numSpeakers lingers in localStorage while its input is hidden); auto+// detection stays null so isExplicitSpeakerCount never mistakes it for an+// explicit choice.+export function buildUploadNoteMetadata(diarization, durationSeconds) {+ return {+ audioDurationSeconds:+ Number.isFinite(durationSeconds) && durationSeconds > 0 ? durationSeconds : null,+ noteUpdates: diarization?.enabled+ ? {+ diarization_enabled: 1,+ expected_speaker_count: normalizeSpeakerCount(diarization.numSpeakers),+ }+ : null,+ };+}diff --git a/src/services/fileTranscription.ts b/src/services/fileTranscription.tsindex c172ecb22..8835684be 100644--- a/src/services/fileTranscription.ts+++ b/src/services/fileTranscription.ts@@ -12,6 +12,9 @@ export interface FileTranscriptionResult {// Set alongside `warning` by the chunked cloud path: how much audio was lost.failedChunks?: number;totalChunks?: number;+ // Measured duration of the source audio, for persisting as+ // audio_duration_seconds. Only transcribeFileWithSpeakers sets it.+ durationSeconds?: number | null;}export interface DiarizationSettings {@@ -142,11 +145,16 @@ export async function transcribeFileWithSpeakers(.catch(() => null) ?? Promise.resolve(null)): Promise.resolve(null);- const [result, diar] = await Promise.all([+ const [transcribed, diar] = await Promise.all([transcribeFile(filePath, cfg, byokDiarize, opts),diarizePromise,]);+ // The diarizer measures the converted audio, so it covers picked files whose+ // duration the caller never knew. 0/NaN mean "unknown", hence ||.+ const measuredDuration = durationSeconds || (diar?.success && diar.durationSeconds) || null;+ const result = { ...transcribed, durationSeconds: measuredDuration };+if (!result.success || !result.text || result.diarized) return result;if (!diar?.success || !diar.segments?.length) return result;diff --git a/src/stores/batchQueueStore.ts b/src/stores/batchQueueStore.tsindex 38871dde8..abf81b9c1 100644--- a/src/stores/batchQueueStore.ts+++ b/src/stores/batchQueueStore.ts@@ -2,6 +2,7 @@ import { create } from "zustand";import { transcribeFileWithSpeakers } from "../services/fileTranscription";import type { FileTranscriptionConfig, DiarizationSettings } from "../services/fileTranscription";import { DOWNLOAD_ERROR_KEYS, transcriptionErrorKey } from "../components/notes/shared";+import { buildUploadNoteMetadata } from "../helpers/uploadNoteMetadata";import { getSettings } from "./settingsStore";import { isTranscriptionContextAllowed } from "./policyRules";import { usePolicyStore } from "./policyStore";@@ -229,16 +230,24 @@ export function processBatchQueue(if (run !== runId) return;}+ const { audioDurationSeconds, noteUpdates } = buildUploadNoteMetadata(+ diarization,+ transcriptionResult.durationSeconds+ );const noteRes = await window.electronAPI.saveNote(noteTitle,finalText,"upload",noteName,- null,+ audioDurationSeconds,transcribeOpts.folderId);if (noteRes.success && noteRes.note) {+ if (noteUpdates) {+ // Best-effort: a failed metadata write must not error a saved transcription.+ await window.electronAPI.updateNote(noteRes.note.id, noteUpdates).catch(() => {});+ }updateItem(item.id, {status: "done",progress: 100,diff --git a/src/types/electron.ts b/src/types/electron.tsindex 887815c7a..af97020a5 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -2388,6 +2388,7 @@ declare global {) => Promise<{success: boolean;segments?: Array<{ start: number; end: number; speaker: string }>;+ durationSeconds?: number;error?: string;}>;onDiarizationDownloadProgress?: (callback: (data: any) => void) => () => void;diff --git a/test/helpers/uploadNoteMetadata.test.js b/test/helpers/uploadNoteMetadata.test.jsnew file mode 100644index 000000000..cffc9e947--- /dev/null+++ b/test/helpers/uploadNoteMetadata.test.js@@ -0,0 +1,94 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const load = () => import("../../src/helpers/uploadNoteMetadata.js");+const { MAX_SPEAKER_COUNT } = require("../../src/constants/speakerDetection.json");++test("maps the diarizer invocation onto the note columns", async () => {+ const { buildUploadNoteMetadata } = await load();++ const { audioDurationSeconds, noteUpdates } = buildUploadNoteMetadata(+ { enabled: true, localModelsReady: true, numSpeakers: 2 },+ 4359.87+ );++ assert.equal(audioDurationSeconds, 4359.87);+ assert.deepEqual(noteUpdates, { diarization_enabled: 1, expected_speaker_count: 2 });+});++test("auto speaker detection stores no explicit count", async () => {+ const { buildUploadNoteMetadata } = await load();++ const { noteUpdates } = buildUploadNoteMetadata(+ { enabled: true, localModelsReady: true, numSpeakers: null },+ 60+ );++ // isExplicitSpeakerCount treats any positive integer as the user's own+ // choice, so auto detection must land as null, never a default.+ assert.equal(noteUpdates.expected_speaker_count, null);+ assert.equal(noteUpdates.diarization_enabled, 1);+});++test("disabled diarization writes no columns at all", async () => {+ const { buildUploadNoteMetadata } = await load();++ // A null diarization_enabled defers to the global speaker setting when the+ // user records into the note later (a 0 would force it off), and writing no+ // count keeps the numSpeakers value lingering in localStorage while its+ // input is hidden from being stamped onto the note as an explicit choice.+ const { audioDurationSeconds, noteUpdates } = buildUploadNoteMetadata(+ { enabled: false, localModelsReady: false, numSpeakers: 3 },+ 120+ );++ assert.equal(noteUpdates, null);+ assert.equal(audioDurationSeconds, 120);+});++test("speaker counts reuse the stored-count clamp", async () => {+ const { buildUploadNoteMetadata } = await load();++ const above = buildUploadNoteMetadata(+ { enabled: true, localModelsReady: true, numSpeakers: MAX_SPEAKER_COUNT + 5 },+ null+ );+ assert.equal(above.noteUpdates.expected_speaker_count, MAX_SPEAKER_COUNT);++ const unusable = buildUploadNoteMetadata(+ { enabled: true, localModelsReady: true, numSpeakers: 0 },+ null+ );+ assert.equal(unusable.noteUpdates.expected_speaker_count, null);+});++test("unusable durations degrade to null", async () => {+ const { buildUploadNoteMetadata } = await load();+ const diarization = { enabled: true, localModelsReady: true, numSpeakers: 2 };++ for (const value of [null, undefined, 0, -1, NaN, Infinity]) {+ assert.equal(+ buildUploadNoteMetadata(diarization, value).audioDurationSeconds,+ null,+ `expected ${value} to degrade to null`+ );+ }+});++// uploadNoteMetadata.js carries a renderer twin of the main-process+// normalizeStoredSpeakerCount (CJS, unloadable from renderer source). Hold the+// two implementations to identical outputs so they cannot drift apart.+test("speaker-count normalization matches the main-process implementation", async () => {+ const { buildUploadNoteMetadata } = await load();+ const { normalizeStoredSpeakerCount } = require("../../src/helpers/speakerCount");++ const inputs = [1, 2, 3, MAX_SPEAKER_COUNT, MAX_SPEAKER_COUNT + 1, MAX_SPEAKER_COUNT + 5];+ for (const value of [...inputs, 0, -1, 1.5, NaN, Infinity, -Infinity, null, undefined, "", {}]) {+ assert.equal(+ buildUploadNoteMetadata({ enabled: true, numSpeakers: value }).noteUpdates+ .expected_speaker_count,+ normalizeStoredSpeakerCount(value),+ `diverged from normalizeStoredSpeakerCount for ${JSON.stringify(value)}`+ );+ }+});diff --git a/test/services/uploadDiarizationPersistence.test.js b/test/services/uploadDiarizationPersistence.test.jsnew file mode 100644index 000000000..41e6641e8--- /dev/null+++ b/test/services/uploadDiarizationPersistence.test.js@@ -0,0 +1,173 @@+const test = require("node:test");+const assert = require("node:assert/strict");+const { createRendererServer, installBrowserGlobals } = require("../lib/rendererTestHarness");++// Regression for the upload/URL-ingest path dropping diarization metadata: the+// batch queue ran the diarizer but persisted none of diarization_enabled,+// expected_speaker_count, or audio_duration_seconds, so an uploaded note that+// WAS diarized presented to the app as though it was not (the meeting path+// persists all of them).++const transcription = {+ useLocalWhisper: true,+ localTranscriptionProvider: "whisper",+ whisperModel: "base",+ parakeetModel: "parakeet-tdt-0.6b-v3",+ isOpenWhisprCloud: false,+ getApiKey: () => "",+ cloudTranscriptionProvider: "openai",+ cloudTranscriptionBaseUrl: "",+ cloudTranscriptionModel: "whisper-1",+ language: "en",+};++const diarization = { enabled: true, localModelsReady: true, numSpeakers: 2 };++const gateMocks = {+ "/lib/auth": "export const withSessionRefresh = (fn) => fn();",+ "./settingsStore": "export const getSettings = () => ({});",+ "./policyStore": "export const usePolicyStore = { getState: () => ({}) };",+ "./policyRules": "export const isTranscriptionContextAllowed = () => true;",+};++async function waitForQueueSettled(store, timeoutMs = 5000) {+ const deadline = Date.now() + timeoutMs;+ for (;;) {+ const { queue, isProcessing } = store.getState();+ if (!isProcessing && queue.every((i) => i.status === "done" || i.status === "error")) {+ return queue;+ }+ if (Date.now() > deadline) {+ throw new Error(`queue never settled: ${JSON.stringify(store.getState().queue)}`);+ }+ await new Promise((resolve) => setTimeout(resolve, 10));+ }+}++function installUploadElectronAPI(window, { diarizedDurationSeconds }) {+ const calls = { saveNote: [], updateNote: [], diarize: [], deletedTempFiles: [] };+ Object.assign(window.electronAPI, {+ transcribeAudioFile: async () => ({ success: true, text: "hello from the recording" }),+ diarizeAudioFile: async (_filePath, options) => {+ calls.diarize.push(options);+ return {+ success: true,+ segments: [+ { start: 0, end: 30, speaker: "Speaker 1" },+ { start: 30, end: 60, speaker: "Speaker 2" },+ ],+ durationSeconds: diarizedDurationSeconds,+ };+ },+ mergeSpeakerText: async () => ({ success: true, text: "[Speaker 1] hello [Speaker 2] hi" }),+ saveNote: async (...args) => {+ calls.saveNote.push(args);+ return { success: true, note: { id: 7 } };+ },+ updateNote: async (id, updates) => {+ calls.updateNote.push([id, updates]);+ return { success: true, note: { id } };+ },+ deleteTempFile: (path) => calls.deletedTempFiles.push(path),+ cancelUrlDownload: () => {},+ });+ return calls;+}++test("a diarized file upload persists the diarization metadata", async (t) => {+ const { window } = installBrowserGlobals(t);+ const vite = await createRendererServer(t, {+ cachePrefix: "openwhispr-upload-diarization-file-test-",+ mockModules: gateMocks,+ });+ // The renderer never knows a picked file's duration up front; the diarizer's+ // measured duration is the only source, so it must land on the note row.+ const calls = installUploadElectronAPI(window, { diarizedDurationSeconds: 4359.87 });++ const store = await vite.ssrLoadModule("/stores/batchQueueStore.ts");+ store.addFiles([{ name: "board-meeting.m4a", path: "/tmp/board-meeting.m4a", sizeBytes: 2048 }]);+ store.processBatchQueue({ transcription, folderId: null }, diarization);++ const queue = await waitForQueueSettled(store.useBatchQueueStore);+ assert.equal(queue[0].status, "done");+ assert.equal(queue[0].noteId, 7);++ assert.equal(calls.saveNote.length, 1);+ const [, content, noteType, sourceFile, audioDuration] = calls.saveNote[0];+ assert.equal(content, "[Speaker 1] hello [Speaker 2] hi");+ assert.equal(noteType, "upload");+ assert.equal(sourceFile, "board-meeting.m4a");+ assert.equal(audioDuration, 4359.87);++ // The persisted count is the same one the diarizer was invoked with.+ assert.deepEqual(calls.diarize, [{ numSpeakers: 2 }]);+ assert.deepEqual(calls.updateNote, [+ [7, { diarization_enabled: 1, expected_speaker_count: 2 }],+ ]);+});++test("a diarized URL ingest persists the diarization metadata", async (t) => {+ const { window } = installBrowserGlobals(t);+ const vite = await createRendererServer(t, {+ cachePrefix: "openwhispr-upload-diarization-url-test-",+ mockModules: gateMocks,+ });+ // The download's known duration beats the diarizer's measurement.+ const calls = installUploadElectronAPI(window, { diarizedDurationSeconds: 9999 });+ Object.assign(window.electronAPI, {+ onUrlDownloadProgress: () => () => {},+ downloadUrlAudio: async () => ({+ success: true,+ tempPath: "/tmp/ow-url-download.m4a",+ title: "Board Meeting Recording",+ sizeBytes: 4096,+ durationSeconds: 4359.87,+ }),+ });++ const store = await vite.ssrLoadModule("/stores/batchQueueStore.ts");+ store.addUrls(["https://www.youtube.com/watch?v=abc123"]);+ store.processBatchQueue({ transcription, folderId: null }, diarization);++ const queue = await waitForQueueSettled(store.useBatchQueueStore);+ assert.equal(queue[0].status, "done");++ assert.equal(calls.saveNote.length, 1);+ const [title, , noteType, sourceFile, audioDuration] = calls.saveNote[0];+ assert.equal(title, "Board Meeting Recording");+ assert.equal(noteType, "upload");+ assert.equal(sourceFile, "Board Meeting Recording");+ assert.equal(audioDuration, 4359.87);++ assert.deepEqual(calls.updateNote, [+ [7, { diarization_enabled: 1, expected_speaker_count: 2 }],+ ]);+ assert.deepEqual(calls.deletedTempFiles, ["/tmp/ow-url-download.m4a"]);+});++test("an upload without diarization leaves the note columns untouched", async (t) => {+ const { window } = installBrowserGlobals(t);+ const vite = await createRendererServer(t, {+ cachePrefix: "openwhispr-upload-diarization-off-test-",+ mockModules: gateMocks,+ });+ const calls = installUploadElectronAPI(window, { diarizedDurationSeconds: 4359.87 });++ const store = await vite.ssrLoadModule("/stores/batchQueueStore.ts");+ store.addFiles([{ name: "memo.m4a", path: "/tmp/memo.m4a", sizeBytes: 2048 }]);+ store.processBatchQueue(+ { transcription, folderId: null },+ { enabled: false, localModelsReady: true, numSpeakers: 2 }+ );++ const queue = await waitForQueueSettled(store.useBatchQueueStore);+ assert.equal(queue[0].status, "done");++ // diarization_enabled must stay null: consumers treat null as "use the+ // global speaker setting" when recording into the note later, and a stored 0+ // would force it off.+ assert.equal(calls.diarize.length, 0);+ assert.equal(calls.updateNote.length, 0);+ assert.equal(calls.saveNote.length, 1);+ assert.equal(calls.saveNote[0][4], null);+});