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(transcription): preserve prior transcript on diarization merge
Gabriel Stein788fc5c4f25b
diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsxindex 058745fa8..5a07ed1f5 100644--- a/src/components/notes/NoteEditor.tsx+++ b/src/components/notes/NoteEditor.tsx@@ -330,15 +330,20 @@ export default function NoteEditor({useEffect(() => {const expectedSession = diarizationSessionId;- const cleanup = window.electronAPI?.onMeetingDiarizationComplete?.((data) => {+ const cleanup = window.electronAPI?.onMeetingDiarizationComplete?.(async (data) => {if (!expectedSession || data?.sessionId !== expectedSession) return;setIsDiarizing(false);if (!data?.segments?.length) return;+ const persisted = await window.electronAPI?.getNote?.(note.id);+ const existing = persisted?.transcript+ ? parseTranscriptSegments(persisted.transcript)+ : displaySegmentsRef.current;+const enriched = mergeTranscriptSegments(- displaySegmentsRef.current,+ existing,data.segments.map((s: any, i: number) => ({...s,id: s.id || `diarized-${i}`,diff --git a/src/utils/transcriptSpeakerState.ts b/src/utils/transcriptSpeakerState.tsindex a7f886b81..6320f2f55 100644--- a/src/utils/transcriptSpeakerState.ts+++ b/src/utils/transcriptSpeakerState.ts@@ -128,66 +128,63 @@ export const mergeTranscriptSegments = (if (incomingSegments.length === 0) {return normalizeTranscriptSegments(existingSegments);}+ if (existingSegments.length === 0) {+ return incomingSegments.map((segment, index) =>+ normalizeTranscriptSegment({ ...segment, id: segment.id || `merged-${index}` })+ );+ }- const existingById = new Map<string, TranscriptSegment>();- const existingByKey = new Map<string, Array<{ index: number; segment: TranscriptSegment }>>();+ const existingById = new Map<string, number>();+ const existingByKey = new Map<string, number[]>();existingSegments.forEach((segment, index) => {- if (segment.id) {- existingById.set(segment.id, segment);- }-+ if (segment.id) existingById.set(segment.id, index);const key = getSegmentMatchKey(segment);const bucket = existingByKey.get(key);- if (bucket) {- bucket.push({ index, segment });- } else {- existingByKey.set(key, [{ index, segment }]);- }+ if (bucket) bucket.push(index);+ else existingByKey.set(key, [index]);});const usedIndexes = new Set<number>();+ const enrichedByIndex = new Map<number, TranscriptSegment>();+ const unmatchedIncoming: TranscriptSegment[] = [];- return incomingSegments.map((segment, index) => {- const byId = segment.id ? existingById.get(segment.id) : undefined;- if (byId) {- const byIdIndex = existingSegments.findIndex((candidate) => candidate.id === byId.id);- if (byIdIndex >= 0) {- usedIndexes.add(byIdIndex);- }- return mergeSpeakerFields(byId, segment);- }-- const keyMatches = existingByKey.get(getSegmentMatchKey(segment)) || [];- const keyMatch = keyMatches.find(({ index: existingIndex }) => !usedIndexes.has(existingIndex));- if (keyMatch) {- usedIndexes.add(keyMatch.index);- return mergeSpeakerFields(keyMatch.segment, segment);- }+ incomingSegments.forEach((segment, index) => {+ const findUnused = (candidates?: number[]) =>+ candidates?.find((candidateIndex) => !usedIndexes.has(candidateIndex));- const fallbackIndex = existingSegments.findIndex(- (candidate, existingIndex) =>- !usedIndexes.has(existingIndex) &&- candidate.source === segment.source &&- candidate.text === segment.text- );+ let matchIndex = segment.id ? existingById.get(segment.id) : undefined;+ if (matchIndex !== undefined && usedIndexes.has(matchIndex)) matchIndex = undefined;- if (fallbackIndex >= 0) {- usedIndexes.add(fallbackIndex);- return mergeSpeakerFields(existingSegments[fallbackIndex], segment);+ if (matchIndex === undefined) {+ matchIndex = findUnused(existingByKey.get(getSegmentMatchKey(segment)));}- const positionalMatch = existingSegments[index];- if (positionalMatch && !usedIndexes.has(index) && positionalMatch.source === segment.source) {- usedIndexes.add(index);- return mergeSpeakerFields(positionalMatch, segment);+ if (matchIndex === undefined) {+ const fallbackIndex = existingSegments.findIndex(+ (candidate, existingIndex) =>+ !usedIndexes.has(existingIndex) &&+ candidate.source === segment.source &&+ candidate.text === segment.text+ );+ if (fallbackIndex >= 0) matchIndex = fallbackIndex;}- return normalizeTranscriptSegment({- ...segment,- id: segment.id || `merged-${index}`,- });+ if (matchIndex !== undefined) {+ usedIndexes.add(matchIndex);+ enrichedByIndex.set(matchIndex, mergeSpeakerFields(existingSegments[matchIndex], segment));+ } else {+ unmatchedIncoming.push(+ normalizeTranscriptSegment({ ...segment, id: segment.id || `merged-${index}` })+ );+ }});++ const preserved = existingSegments.map(+ (segment, index) => enrichedByIndex.get(index) ?? normalizeTranscriptSegment(segment)+ );++ return [...preserved, ...unmatchedIncoming];};export const serializeTranscriptSegments = (segments: TranscriptSegment[]) =>