Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

feat(diarization): speaker label propagation and ID format fix

Gabriel Steinef1533a02b46
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 0848556e9..1d9a9201b 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -2982,6 +2982,12 @@ class IPCHandlers {
}
win.webContents.send("meeting-speaker-identified", identification);
+
+ for (const seg of meetingDiarizationSegments) {
+ if (seg.source === "system" && !seg.speaker) {
+ seg.speaker = identification.speakerId;
+ }
+ }
},
{
getSpeakerProfiles: getLiveSpeakerProfiles,
diff --git a/src/helpers/liveSpeakerIdentifier.js b/src/helpers/liveSpeakerIdentifier.js
index 09b3ceedd..bcd79578b 100644
--- a/src/helpers/liveSpeakerIdentifier.js
+++ b/src/helpers/liveSpeakerIdentifier.js
@@ -5,7 +5,7 @@ const { downsample24kTo16k } = require("../utils/audioUtils");
const SAMPLE_RATE = 16000;
const VAD_WINDOW_SIZE = 512;
-const MIN_SEGMENT_SECONDS = 1.5;
+const MIN_SEGMENT_SECONDS = 0.8;
const MIN_SEGMENT_SAMPLES = Math.round(SAMPLE_RATE * MIN_SEGMENT_SECONDS);
const SPEECH_THRESHOLD = 0.15;
const SILENCE_THRESHOLD = 0.08;
@@ -399,8 +399,8 @@ class LiveSpeakerIdentifier {
this.onSpeakerIdentified?.({
speakerId,
displayName: this.transientDisplayNames.get(speakerId) || null,
- startTime: this.segmentStartSample / SAMPLE_RATE,
- endTime: this.segmentEndSample / SAMPLE_RATE,
+ startTime: Math.max(0, this.segmentStartSample / SAMPLE_RATE - 10),
+ endTime: this.segmentEndSample / SAMPLE_RATE + 10,
});
}
@@ -465,7 +465,7 @@ class LiveSpeakerIdentifier {
}
_assignSpeakerId(embedding) {
- const speakerId = `live_${this.nextLiveIndex}`;
+ const speakerId = `speaker_${this.nextLiveIndex}`;
this.nextLiveIndex += 1;
this.transientEmbeddings.set(speakerId, cloneFloat32Array(embedding));
this.transientCounts.set(speakerId, 1);
diff --git a/src/hooks/useMeetingTranscription.ts b/src/hooks/useMeetingTranscription.ts
index 280a3d8db..36125e807 100644
--- a/src/hooks/useMeetingTranscription.ts
+++ b/src/hooks/useMeetingTranscription.ts
@@ -261,20 +261,14 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
Array<{ speakerId: string; displayName?: string; startTime: number; endTime: number }>
>([]);
const meetingStartTimeRef = useRef<number>(0);
+ const lastSpeakerRef = useRef<{ speakerId: string; displayName?: string } | null>(null);
const applySpeakerIdentification = useCallback(
(
segment: TranscriptSegment,
identification: { speakerId: string; displayName?: string; startTime: number; endTime: number }
): TranscriptSegment => {
- if (segment.source !== "system" || segment.timestamp == null) {
- return segment;
- }
-
- const epochStart = meetingStartTimeRef.current + identification.startTime * 1000;
- const epochEnd = meetingStartTimeRef.current + identification.endTime * 1000;
-
- if (segment.timestamp < epochStart - 5000 || segment.timestamp > epochEnd + 5000) {
+ if (segment.source !== "system" || segment.speaker) {
return segment;
}
@@ -392,6 +386,7 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
setSystemPartial("");
setError(null);
speakerIdentificationsRef.current = [];
+ lastSpeakerRef.current = null;
meetingStartTimeRef.current = Date.now();
// Set recording state immediately for instant UI feedback
@@ -482,12 +477,19 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
setPartialForSource(data.text);
setPartialTranscript(data.text);
} else {
- const rawSegment: TranscriptSegment = {
+ let rawSegment: TranscriptSegment = {
id: `seg-${++segmentCounter}`,
text: data.text,
source: data.source,
timestamp: data.timestamp,
};
+ if (rawSegment.source === "system" && !rawSegment.speaker && lastSpeakerRef.current) {
+ rawSegment = {
+ ...rawSegment,
+ speaker: lastSpeakerRef.current.speakerId,
+ speakerName: lastSpeakerRef.current.displayName,
+ };
+ }
const seg = speakerIdentificationsRef.current.reduce(applySpeakerIdentification, rawSegment);
setSegments((prev) => {
// Insert in chronological order — scan from the end since most
@@ -507,15 +509,18 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
if (segmentCleanup) ipcCleanupsRef.current.push(segmentCleanup);
const speakerCleanup = window.electronAPI?.onMeetingSpeakerIdentified?.((data) => {
+ lastSpeakerRef.current = { speakerId: data.speakerId, displayName: data.displayName };
speakerIdentificationsRef.current = [
...speakerIdentificationsRef.current.filter(
- (identification) => identification.endTime >= data.endTime - SPEAKER_IDENTIFICATION_RETENTION_MS
+ (id) => id.endTime >= data.endTime - SPEAKER_IDENTIFICATION_RETENTION_MS
),
data,
];
-
setSegments((prev) =>
- prev.map((segment) => applySpeakerIdentification(segment, data))
+ prev.map((segment) => {
+ if (segment.source !== "system" || segment.speaker) return segment;
+ return { ...segment, speaker: data.speakerId, speakerName: data.displayName ?? segment.speakerName };
+ })
);
});
if (speakerCleanup) ipcCleanupsRef.current.push(speakerCleanup);