Skip to content

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

feat(meeting): background recording with floating pill and responsive layout (#709)

Gabriel Stein11ae356cd39c
diff --git a/preload.js b/preload.js
index 30018e574..dad763bf3 100644
--- a/preload.js
+++ b/preload.js
@@ -280,6 +280,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
windowMaximize: () => ipcRenderer.invoke("window-maximize"),
windowClose: () => ipcRenderer.invoke("window-close"),
windowIsMaximized: () => ipcRenderer.invoke("window-is-maximized"),
+ snapToMeetingMode: () => ipcRenderer.invoke("snap-to-meeting-mode"),
restoreFromMeetingMode: () => ipcRenderer.invoke("restore-from-meeting-mode"),
getPlatform: () => process.platform,
appQuit: () => ipcRenderer.invoke("app-quit"),
diff --git a/src/components/ControlPanel.tsx b/src/components/ControlPanel.tsx
index dd2dbb3f5..c405bf216 100644
--- a/src/components/ControlPanel.tsx
+++ b/src/components/ControlPanel.tsx
@@ -20,12 +20,24 @@ import {
clearTranscriptions as clearStore,
} from "../stores/transcriptionStore";
import { useSettingsStore } from "../stores/settingsStore";
+import {
+ useIsMeetingMode,
+ useIsNarrowWindow,
+ useMeetingRecordingStore,
+} from "../stores/meetingRecordingStore";
import ControlPanelSidebar, { type ControlPanelView } from "./ControlPanelSidebar";
+import MeetingRecordingMount from "./MeetingRecordingMount";
+import MeetingRecordingPill from "./notes/MeetingRecordingPill";
import WindowControls from "./WindowControls";
import { getCachedPlatform } from "../utils/platform";
import { isAccessibilitySkipped } from "../utils/permissions";
-import { setActiveNoteId, setActiveFolderId, initializeNotes } from "../stores/noteStore";
+import {
+ setActiveNoteId,
+ setActiveFolderId,
+ useActiveNoteId,
+ initializeNotes,
+} from "../stores/noteStore";
import { fetchProviders as fetchStreamingProviders } from "../stores/streamingProvidersStore";
import HistoryView from "./HistoryView";
import { syncService } from "../services/SyncService.js";
@@ -58,7 +70,11 @@ export default function ControlPanel() {
const [showSearch, setShowSearch] = useState(false);
const [showCloudMigrationBanner, setShowCloudMigrationBanner] = useState(false);
const [activeView, setActiveView] = useState<ControlPanelView>("home");
- const [isMeetingMode, setIsMeetingMode] = useState(false);
+ const isMeetingMode = useIsMeetingMode();
+ const isNarrowWindow = useIsNarrowWindow();
+ const activeNoteId = useActiveNoteId();
+ const recordingNoteId = useMeetingRecordingStore((s) => s.recordingNoteId);
+ const recordingFolderId = useMeetingRecordingStore((s) => s.recordingFolderId);
const [meetingRecordingRequest, setMeetingRecordingRequest] = useState<{
noteId: number;
folderId: number;
@@ -261,9 +277,18 @@ export default function ControlPanel() {
setActiveFolderId(data.folderId);
setActiveNoteId(data.noteId);
setActiveView("personal-notes");
- setIsMeetingMode(true);
- setMeetingRecordingRequest(data);
+ setMeetingRecordingRequest({
+ noteId: data.noteId,
+ folderId: data.folderId,
+ event: data.event,
+ });
initializeNotes(null, 50, data.folderId);
+ if (
+ data.trigger === "hotkey" &&
+ useSettingsStore.getState().meetingHotkeyLayoutMode === "side-panel"
+ ) {
+ window.electronAPI?.snapToMeetingMode?.();
+ }
});
return () => cleanup?.();
}, []);
@@ -318,7 +343,6 @@ export default function ControlPanel() {
);
const handleExitMeetingMode = useCallback(() => {
- setIsMeetingMode(false);
window.electronAPI?.restoreFromMeetingMode?.();
}, []);
@@ -566,6 +590,16 @@ export default function ControlPanel() {
return (
<div className="h-screen bg-background flex flex-col">
+ <MeetingRecordingMount />
+ <MeetingRecordingPill
+ activeView={activeView}
+ activeNoteId={activeNoteId}
+ onReturnToNote={() => {
+ setActiveView("personal-notes");
+ setActiveFolderId(recordingFolderId);
+ setActiveNoteId(recordingNoteId);
+ }}
+ />
<ConfirmDialog
open={confirmDialog.open}
onOpenChange={hideConfirmDialog}
@@ -683,7 +717,7 @@ export default function ControlPanel() {
className="flex items-center justify-between w-full h-10 shrink-0"
style={{ WebkitAppRegion: "drag" } as React.CSSProperties}
>
- {isMeetingMode && (
+ {isNarrowWindow && (
<div
className={platform === "darwin" ? "ml-[84px] mt-[16px]" : "ml-2"}
style={{ WebkitAppRegion: "no-drag" } as React.CSSProperties}
@@ -820,7 +854,6 @@ export default function ControlPanel() {
onOpenSearch={() => setShowSearch(true)}
meetingRecordingRequest={meetingRecordingRequest}
onMeetingRecordingRequestHandled={handleMeetingRecordingRequestHandled}
- isMeetingMode={isMeetingMode}
/>
</Suspense>
)}
diff --git a/src/components/MeetingRecordingMount.tsx b/src/components/MeetingRecordingMount.tsx
new file mode 100644
index 000000000..46a809d6d
--- /dev/null
+++ b/src/components/MeetingRecordingMount.tsx
@@ -0,0 +1,56 @@
+import { useEffect } from "react";
+import {
+ getMicAnalyser,
+ primeMeetingWorklet,
+ useMeetingRecordingStore,
+} from "../stores/meetingRecordingStore";
+
+// EMA factor 0.7 prefers the previous level so visual bars don't twitch on
+// noisy sub-frame samples. The 0.3 weight on the new RMS is enough to track
+// fast onsets (vowels, plosives) without lag.
+const EMA_PREV = 0.7;
+const EMA_NEXT = 0.3;
+
+export default function MeetingRecordingMount(): null {
+ const isRecording = useMeetingRecordingStore((s) => s.isRecording);
+
+ useEffect(() => {
+ primeMeetingWorklet();
+ }, []);
+
+ useEffect(() => {
+ if (!isRecording) return;
+
+ let rafId = 0;
+ let smoothed = 0;
+ const buf = new Float32Array(128);
+
+ const tick = () => {
+ const analyser = getMicAnalyser();
+ if (analyser) {
+ const len = Math.min(buf.length, analyser.fftSize);
+ const view = len === buf.length ? buf : buf.subarray(0, len);
+ analyser.getFloatTimeDomainData(view);
+ let sumSquares = 0;
+ for (let i = 0; i < len; i++) {
+ const v = view[i];
+ sumSquares += v * v;
+ }
+ const rms = Math.sqrt(sumSquares / len);
+ smoothed = EMA_PREV * smoothed + EMA_NEXT * rms;
+ const clamped = smoothed < 0 ? 0 : smoothed > 1 ? 1 : smoothed;
+ useMeetingRecordingStore.setState({ currentMicLevel: clamped });
+ }
+ rafId = requestAnimationFrame(tick);
+ };
+
+ rafId = requestAnimationFrame(tick);
+
+ return () => {
+ cancelAnimationFrame(rafId);
+ useMeetingRecordingStore.setState({ currentMicLevel: 0 });
+ };
+ }, [isRecording]);
+
+ return null;
+}
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 0d1d77529..b45556e24 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -70,6 +70,7 @@ import { validateHotkeyForSlot } from "../utils/hotkeyValidation";
import { getPlatform, getCachedPlatform } from "../utils/platform";
import { formatHotkeyLabel } from "../utils/hotkeys";
import { ActivationModeSelector } from "./ui/ActivationModeSelector";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
import LinuxPttSetupInfo from "./ui/LinuxPttSetupInfo";
import { Toggle } from "./ui/toggle";
import DeveloperSection from "./DeveloperSection";
@@ -642,6 +643,8 @@ export default function SettingsPage({
setDictationKey,
meetingKey,
setMeetingKey,
+ meetingHotkeyLayoutMode,
+ setMeetingHotkeyLayoutMode,
autoLearnCorrections,
setAutoLearnCorrections,
updateTranscriptionSettings,
@@ -2973,6 +2976,35 @@ EOF`,
</button>
)}
</SettingsPanelRow>
+ <SettingsPanelRow className="flex items-center justify-between gap-3 border-t border-border/40 dark:border-white/5">
+ <span className="text-xs text-muted-foreground/80">
+ {t("settingsPage.general.meetingHotkey.layoutLabel")}
+ </span>
+ <Select
+ value={meetingHotkeyLayoutMode}
+ onValueChange={(value) =>
+ setMeetingHotkeyLayoutMode(value as "side-panel" | "full-width")
+ }
+ >
+ <SelectTrigger className="h-7 w-36 text-xs rounded-lg px-2.5 [&>svg]:h-3 [&>svg]:w-3">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem
+ value="full-width"
+ className="text-xs py-1.5 pl-2.5 pr-7 rounded-md"
+ >
+ {t("settingsPage.general.meetingHotkey.layoutFullWidth")}
+ </SelectItem>
+ <SelectItem
+ value="side-panel"
+ className="text-xs py-1.5 pl-2.5 pr-7 rounded-md"
+ >
+ {t("settingsPage.general.meetingHotkey.layoutSidePanel")}
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ </SettingsPanelRow>
</SettingsPanel>
</div>
diff --git a/src/components/notes/MeetingRecordingPill.tsx b/src/components/notes/MeetingRecordingPill.tsx
new file mode 100644
index 000000000..5b6946c9f
--- /dev/null
+++ b/src/components/notes/MeetingRecordingPill.tsx
@@ -0,0 +1,132 @@
+import { useState } from "react";
+import { createPortal } from "react-dom";
+import { useTranslation } from "react-i18next";
+import { Square } from "lucide-react";
+import { stopRecording, useMeetingRecordingStore } from "../../stores/meetingRecordingStore";
+import { cn } from "../lib/utils";
+
+interface MeetingRecordingPillProps {
+ activeView: string;
+ activeNoteId: number | null;
+ onReturnToNote: () => void;
+}
+
+const BAR_COUNT = 4;
+const BAR_FLOOR = 20;
+
+const isControlPanelWindow = () => {
+ if (typeof window === "undefined") return false;
+ const { search, pathname } = window.location;
+ return pathname.includes("control") || search.includes("panel=true");
+};
+
+const truncateTitle = (title: string) =>
+ title.length > 20 ? `${title.slice(0, 19).trimEnd()}…` : title;
+
+const computeBarHeight = (level: number, index: number) => {
+ // Per-bar phase keeps the stack from moving in lockstep at sustained levels.
+ const phase = 0.7 + 0.3 * Math.sin(index * 1.7);
+ const scaled = level * 100 * phase;
+ return `${Math.max(BAR_FLOOR, Math.min(100, scaled))}%`;
+};
+
+export default function MeetingRecordingPill({
+ activeView,
+ activeNoteId,
+ onReturnToNote,
+}: MeetingRecordingPillProps) {
+ const { t } = useTranslation();
+ const isRecording = useMeetingRecordingStore((s) => s.isRecording);
+ const recordingNoteId = useMeetingRecordingStore((s) => s.recordingNoteId);
+ const recordingNoteTitle = useMeetingRecordingStore((s) => s.recordingNoteTitle);
+ const micLevel = useMeetingRecordingStore((s) => s.currentMicLevel);
+ const [isStopping, setIsStopping] = useState(false);
+
+ const isViewingRecordingNote =
+ activeView === "personal-notes" && activeNoteId === recordingNoteId;
+
+ if (!isRecording || isViewingRecordingNote || !isControlPanelWindow()) {
+ return null;
+ }
+
+ const handleStop = async () => {
+ if (isStopping) return;
+ setIsStopping(true);
+ try {
+ await stopRecording();
+ } finally {
+ setIsStopping(false);
+ }
+ };
+
+ const title = truncateTitle(recordingNoteTitle ?? "");
+ const returnLabel = t("notes.meetingPill.returnToNote");
+ const stopLabel = t("notes.editor.stop");
+
+ return createPortal(
+ <div
+ className="fixed top-12 left-1/2 -translate-x-1/2 z-20"
+ style={
+ {
+ WebkitAppRegion: "no-drag",
+ animation: "grow-to-bar 0.45s cubic-bezier(0.22, 1, 0.36, 1) both",
+ } as React.CSSProperties
+ }
+ >
+ <div
+ className={cn(
+ "flex items-center gap-2 h-9 px-3 rounded-xl",
+ "bg-primary/6 dark:bg-primary/10",
+ "backdrop-blur-xl",
+ "border border-primary/20 dark:border-primary/25",
+ "shadow-elevated"
+ )}
+ >
+ <button
+ type="button"
+ onClick={onReturnToNote}
+ aria-label={returnLabel}
+ title={returnLabel}
+ className={cn(
+ "flex items-center gap-3 px-1 -mx-1 rounded-md",
+ "transition-colors",
+ "hover:bg-primary/8 active:bg-primary/14",
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring/30"
+ )}
+ >
+ <div className="flex items-end gap-0.75 h-4">
+ {Array.from({ length: BAR_COUNT }, (_, i) => (
+ <div
+ key={i}
+ className="w-0.75 rounded-full bg-primary/60 dark:bg-primary/70 origin-bottom"
+ style={{ height: computeBarHeight(micLevel, i) }}
+ />
+ ))}
+ </div>
+ <span className="text-xs font-medium text-foreground/80 truncate max-w-[12rem]">
+ {title}
+ </span>
+ </button>
+
+ <button
+ type="button"
+ onClick={handleStop}
+ disabled={isStopping}
+ aria-label={stopLabel}
+ title={stopLabel}
+ className={cn(
+ "flex items-center justify-center w-7 h-7 rounded-lg",
+ "transition-colors duration-150",
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring/30",
+ isStopping
+ ? "bg-primary/6 text-primary/40 cursor-not-allowed"
+ : "bg-primary/10 hover:bg-primary/18 active:bg-primary/25 text-primary"
+ )}
+ >
+ <Square size={12} fill="currentColor" />
+ </button>
+ </div>
+ </div>,
+ document.body
+ );
+}
diff --git a/src/components/notes/MeetingTranscriptChat.tsx b/src/components/notes/MeetingTranscriptChat.tsx
index e9fb036e7..a8a3443d8 100644
--- a/src/components/notes/MeetingTranscriptChat.tsx
+++ b/src/components/notes/MeetingTranscriptChat.tsx
@@ -5,7 +5,7 @@ import { Popover, PopoverTrigger, PopoverContent } from "../ui/popover";
import { Toggle } from "../ui/toggle";
import { cn } from "../lib/utils";
import { MAX_SPEAKER_COUNT } from "../../constants/speakerDetection.json";
-import type { TranscriptSegment } from "../../hooks/useMeetingTranscription";
+import type { TranscriptSegment } from "../../stores/meetingRecordingStore";
import {
isTranscriptSpeakerLocked,
type TranscriptSpeakerStatus,
diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsx
index 34cbd8df7..17e847b26 100644
--- a/src/components/notes/NoteEditor.tsx
+++ b/src/components/notes/NoteEditor.tsx
@@ -17,7 +17,7 @@ import {
import { RichTextEditor } from "../ui/RichTextEditor";
import type { Editor } from "@tiptap/react";
import { MeetingTranscriptChat, SelectionBar } from "./MeetingTranscriptChat";
-import type { TranscriptSegment } from "../../hooks/useMeetingTranscription";
+import type { TranscriptSegment } from "../../stores/meetingRecordingStore";
import {
DropdownMenu,
DropdownMenuTrigger,
diff --git a/src/components/notes/PersonalNotesView.tsx b/src/components/notes/PersonalNotesView.tsx
index 25a973e44..c049859cd 100644
--- a/src/components/notes/PersonalNotesView.tsx
+++ b/src/components/notes/PersonalNotesView.tsx
@@ -63,7 +63,15 @@ import {
setActiveFolderId,
removeNote,
} from "../../stores/noteStore";
-import { useMeetingTranscription } from "../../hooks/useMeetingTranscription";
+import {
+ useMeetingRecordingStore,
+ useIsMeetingMode,
+ startRecording as storeStartRecording,
+ stopRecording as storeStopRecording,
+ lockSpeaker,
+ setSessionDiarizationEnabled,
+ setSessionExpectedCount,
+} from "../../stores/meetingRecordingStore";
import { useNotesOnboarding } from "../../hooks/useNotesOnboarding";
import NotesOnboarding from "./NotesOnboarding";
@@ -77,9 +85,12 @@ function makeContentHash(content: string): string {
interface PersonalNotesViewProps {
onOpenSettings?: (section: string) => void;
onOpenSearch?: () => void;
- meetingRecordingRequest?: { noteId: number; folderId: number; event: any } | null;
+ meetingRecordingRequest?: {
+ noteId: number;
+ folderId: number;
+ event: any;
+ } | null;
onMeetingRecordingRequestHandled?: () => void;
- isMeetingMode?: boolean;
}
export default function PersonalNotesView({
@@ -87,8 +98,8 @@ export default function PersonalNotesView({
onOpenSearch,
meetingRecordingRequest,
onMeetingRecordingRequestHandled,
- isMeetingMode,
}: PersonalNotesViewProps) {
+ const isMeetingMode = useIsMeetingMode();
const { t } = useTranslation();
const notes = useNotes();
const activeNoteId = useActiveNoteId();
@@ -127,31 +138,18 @@ export default function PersonalNotesView({
: "Files";
const { isComplete: isOnboardingComplete, complete: completeOnboarding } = useNotesOnboarding();
- const {
- isRecording: isTranscribing,
- transcript: realtimeTranscript,
- segments: realtimeSegments,
- micPartial,
- systemPartial,
- systemPartialSpeakerId,
- systemPartialSpeakerName,
- diarizationSessionId,
- prepareTranscription,
- startTranscription,
- stopTranscription,
- lockSpeaker,
- sessionDiarizationEnabled,
- sessionExpectedCount,
- userTouchedStepper,
- setSessionDiarizationEnabled,
- setSessionExpectedCount,
- } = useMeetingTranscription();
- const recordingNoteIdRef = useRef<number | null>(null);
- const [recordingNoteId, setRecordingNoteId] = useState<number | null>(null);
- const setActiveRecordingNoteId = (id: number | null) => {
- recordingNoteIdRef.current = id;
- setRecordingNoteId(id);
- };
+ const isTranscribing = useMeetingRecordingStore((s) => s.isRecording);
+ const realtimeTranscript = useMeetingRecordingStore((s) => s.transcript);
+ const realtimeSegments = useMeetingRecordingStore((s) => s.segments);
+ const micPartial = useMeetingRecordingStore((s) => s.micPartial);
+ const systemPartial = useMeetingRecordingStore((s) => s.systemPartial);
+ const systemPartialSpeakerId = useMeetingRecordingStore((s) => s.systemPartialSpeakerId);
+ const systemPartialSpeakerName = useMeetingRecordingStore((s) => s.systemPartialSpeakerName);
+ const diarizationSessionId = useMeetingRecordingStore((s) => s.diarizationSessionId);
+ const sessionDiarizationEnabled = useMeetingRecordingStore((s) => s.sessionDiarizationEnabled);
+ const sessionExpectedCount = useMeetingRecordingStore((s) => s.sessionExpectedCount);
+ const userTouchedStepper = useMeetingRecordingStore((s) => s.userTouchedStepper);
+ const recordingNoteId = useMeetingRecordingStore((s) => s.recordingNoteId);
const {
folders,
@@ -214,15 +212,22 @@ export default function PersonalNotesView({
}, [activeNote?.calendar_event_id]);
const startRecording = useCallback(async () => {
- setActiveRecordingNoteId(activeNoteRef.current);
- const note = notes.find((n) => n.id === activeNoteRef.current);
+ const noteId = activeNoteRef.current;
+ const note = notes.find((n) => n.id === noteId);
const seedSegments = note?.transcript ? parseTranscriptSegments(note.transcript) : [];
- await startTranscription({ seedSegments, noteId: activeNoteRef.current });
- }, [notes, startTranscription]);
+ await storeStartRecording({
+ noteId,
+ noteTitle: note?.title ?? null,
+ folderId: note?.folder_id ?? null,
+ seedSegments,
+ diarizationEnabled: note?.diarization_enabled == null ? null : note.diarization_enabled === 1,
+ expectedCount: note?.expected_speaker_count ?? null,
+ });
+ }, [notes]);
const stopRecording = useCallback(async () => {
- await stopTranscription();
- }, [stopTranscription]);
+ await storeStopRecording();
+ }, []);
useEffect(() => {
const syncNote = async () => {
@@ -514,29 +519,20 @@ export default function PersonalNotesView({
[activeNoteId]
);
- // Pre-warm WebSocket when entering meeting mode (before user hits record)
- useEffect(() => {
- if (!isMeetingMode) return;
- prepareTranscription();
- return () => {
- window.electronAPI?.meetingTranscriptionCancel?.();
- };
- }, [isMeetingMode, activeNoteId, prepareTranscription]);
-
useEffect(() => {
if (!meetingRecordingRequest || activeNoteId !== meetingRecordingRequest.noteId) return;
- setActiveRecordingNoteId(meetingRecordingRequest.noteId);
const note = notes.find((n) => n.id === meetingRecordingRequest.noteId);
const seedSegments = note?.transcript ? parseTranscriptSegments(note.transcript) : [];
- startTranscription({ seedSegments, noteId: meetingRecordingRequest.noteId });
+ storeStartRecording({
+ noteId: meetingRecordingRequest.noteId,
+ noteTitle: note?.title ?? null,
+ folderId: note?.folder_id ?? meetingRecordingRequest.folderId ?? null,
+ seedSegments,
+ diarizationEnabled: note?.diarization_enabled == null ? null : note.diarization_enabled === 1,
+ expectedCount: note?.expected_speaker_count ?? null,
+ });
onMeetingRecordingRequestHandled?.();
- }, [
- meetingRecordingRequest,
- activeNoteId,
- notes,
- startTranscription,
- onMeetingRecordingRequestHandled,
- ]);
+ }, [meetingRecordingRequest, activeNoteId, notes, onMeetingRecordingRequestHandled]);
const prevTranscribingRef = useRef(false);
@@ -551,28 +547,25 @@ export default function PersonalNotesView({
? serializeTranscriptSegments(realtimeSegments)
: realtimeTranscript;
- const noteId = recordingNoteIdRef.current;
- if (noteId && transcript) {
- window.electronAPI.updateNote(noteId, { transcript });
+ if (recordingNoteId && transcript) {
+ window.electronAPI.updateNote(recordingNoteId, { transcript });
}
- setActiveRecordingNoteId(null);
}
prevTranscribingRef.current = isTranscribing;
- }, [isTranscribing, realtimeTranscript, realtimeSegments]);
+ }, [isTranscribing, realtimeTranscript, realtimeSegments, recordingNoteId]);
useEffect(() => {
if (!isTranscribing) return;
const interval = setInterval(() => {
- const noteId = recordingNoteIdRef.current;
- if (!noteId || realtimeSegments.length === 0) return;
- window.electronAPI.updateNote(noteId, {
+ if (!recordingNoteId || realtimeSegments.length === 0) return;
+ window.electronAPI.updateNote(recordingNoteId, {
transcript: serializeTranscriptSegments(realtimeSegments),
});
}, 30_000);
return () => clearInterval(interval);
- }, [isTranscribing, realtimeSegments]);
+ }, [isTranscribing, realtimeSegments, recordingNoteId]);
const isLocalSynced = syncedNoteId === activeNote?.id;
const isActiveNoteRecording = isTranscribing && recordingNoteId === activeNote?.id;
@@ -592,7 +585,7 @@ export default function PersonalNotesView({
<div className="flex h-full">
<div
className="shrink-0 overflow-hidden transition-[width] duration-300 ease-out"
- style={{ width: isMeetingMode || isActiveNoteRecording ? 0 : "13rem" }}
+ style={{ width: isMeetingMode ? 0 : "13rem" }}
>
<div className="w-52 shrink-0 border-r border-border/15 dark:border-white/4 flex flex-col h-full">
<div className="px-2 pt-2 pb-1 shrink-0 space-y-0.5">
diff --git a/src/helpers/database.js b/src/helpers/database.js
index e22b526fd..46997ed12 100644
--- a/src/helpers/database.js
+++ b/src/helpers/database.js
@@ -380,6 +380,16 @@ class DatabaseManager {
} catch (err) {
if (!err.message.includes("duplicate column")) throw err;
}
+ try {
+ this.db.exec("ALTER TABLE notes ADD COLUMN diarization_enabled INTEGER");
+ } catch (err) {
+ if (!err.message.includes("duplicate column")) throw err;
+ }
+ try {
+ this.db.exec("ALTER TABLE notes ADD COLUMN expected_speaker_count INTEGER");
+ } catch (err) {
+ if (!err.message.includes("duplicate column")) throw err;
+ }
this.db.exec(`
CREATE TABLE IF NOT EXISTS contacts (
@@ -842,6 +852,8 @@ class DatabaseManager {
"transcript",
"calendar_event_id",
"participants",
+ "diarization_enabled",
+ "expected_speaker_count",
"sync_status",
"deleted_at",
"client_note_id",
@@ -2002,8 +2014,9 @@ class DatabaseManager {
const stmt = this.db.prepare(`
INSERT INTO notes (client_note_id, cloud_id, title, content, enhanced_content,
enhancement_prompt, enhanced_at_content_hash, note_type, source_file,
- audio_duration_seconds, transcript, folder_id, sync_status, created_at, updated_at)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'synced', ?, ?)
+ audio_duration_seconds, transcript, folder_id, participants, calendar_event_id,
+ diarization_enabled, expected_speaker_count, sync_status, created_at, updated_at)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'synced', ?, ?)
ON CONFLICT(client_note_id) DO UPDATE SET
cloud_id = excluded.cloud_id,
title = excluded.title,
@@ -2013,6 +2026,10 @@ class DatabaseManager {
enhanced_at_content_hash = excluded.enhanced_at_content_hash,
transcript = excluded.transcript,
folder_id = excluded.folder_id,
+ participants = excluded.participants,
+ calendar_event_id = excluded.calendar_event_id,
+ diarization_enabled = excluded.diarization_enabled,
+ expected_speaker_count = excluded.expected_speaker_count,
sync_status = 'synced',
updated_at = excluded.updated_at
`);
@@ -2029,6 +2046,10 @@ class DatabaseManager {
cloudNote.audio_duration_seconds || null,
cloudNote.transcript || null,
localFolderId,
+ cloudNote.participants || null,
+ cloudNote.calendar_event_id || null,
+ cloudNote.diarization_enabled ?? null,
+ cloudNote.expected_speaker_count ?? null,
cloudNote.created_at,
cloudNote.updated_at
);
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index fb5a931b2..8f8922f06 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -658,6 +658,10 @@ class IPCHandlers {
return false;
});
+ ipcMain.handle("snap-to-meeting-mode", () => {
+ this.windowManager.snapControlPanelToMeetingMode();
+ });
+
ipcMain.handle("restore-from-meeting-mode", () => {
this.windowManager.restoreControlPanelFromMeetingMode();
this.meetingDetectionEngine?.setMeetingModeActive(false);
diff --git a/src/helpers/meetingDetectionEngine.js b/src/helpers/meetingDetectionEngine.js
index 288c11b11..0b78f925c 100644
--- a/src/helpers/meetingDetectionEngine.js
+++ b/src/helpers/meetingDetectionEngine.js
@@ -201,11 +201,11 @@ class MeetingDetectionEngine {
}
await this.windowManager.createControlPanelWindow();
- this.windowManager.snapControlPanelToMeetingMode();
this.windowManager.sendToControlPanel("navigate-to-meeting-note", {
noteId: noteResult.note.id,
folderId: meetingsFolder.id,
event: detection.event,
+ trigger: "calendar-join",
});
this.audioActivityDetector.resetPrompt();
@@ -234,7 +234,7 @@ class MeetingDetectionEngine {
const activeEvents = this.databaseManager.getActiveEvents();
if (activeEvents?.length > 0) {
- return this.joinCalendarMeeting(activeEvents[0].id);
+ return this.joinCalendarMeeting(activeEvents[0].id, "hotkey");
}
this._meetingModeActive = true;
@@ -270,17 +270,17 @@ class MeetingDetectionEngine {
await this.windowManager.createControlPanelWindow();
await new Promise((resolve) => setTimeout(resolve, 50));
- this.windowManager.snapControlPanelToMeetingMode();
this.windowManager.sendToControlPanel("navigate-to-meeting-note", {
noteId: noteResult.note.id,
folderId: meetingsFolder.id,
event,
+ trigger: "hotkey",
});
}
- async joinCalendarMeeting(eventId) {
+ async joinCalendarMeeting(eventId, trigger = "calendar-join") {
this._meetingModeActive = true;
- debugLogger.info("Joining calendar meeting", { eventId }, "meeting");
+ debugLogger.info("Joining calendar meeting", { eventId, trigger }, "meeting");
const calEvent = this.databaseManager.getCalendarEventById(eventId);
if (!calEvent) {
@@ -312,11 +312,11 @@ class MeetingDetectionEngine {
await this.windowManager.createControlPanelWindow();
await new Promise((resolve) => setTimeout(resolve, 50));
- this.windowManager.snapControlPanelToMeetingMode();
this.windowManager.sendToControlPanel("navigate-to-meeting-note", {
noteId: noteResult.note.id,
folderId: meetingsFolder.id,
event: calEvent,
+ trigger,
});
}
diff --git a/src/hooks/useMeetingTranscription.ts b/src/hooks/useMeetingTranscription.ts
deleted file mode 100644
index 1865e3436..000000000
--- a/src/hooks/useMeetingTranscription.ts
+++ /dev/null
@@ -1,1242 +0,0 @@
-import { useState, useEffect, useRef, useCallback } from "react";
-import { getSettings, selectResolvedMeetingTranscription } from "../stores/settingsStore";
-import { useStreamingProvidersStore } from "../stores/streamingProvidersStore";
-import { isBuiltInMicrophone } from "../utils/audioDeviceUtils";
-import type { SystemAudioAccessResult, SystemAudioStrategy } from "../types/electron";
-import {
- DEFAULT_SYSTEM_AUDIO_ACCESS,
- getDisplayCaptureModeForStrategy,
- getFallbackSystemAudioAccess,
- isRendererSystemAudioStrategy,
-} from "../utils/systemAudioAccess";
-import {
- DEFAULT_EXPECTED_SPEAKER_COUNT,
- MAX_SPEAKER_COUNT,
-} from "../constants/speakerDetection.json";
-import logger from "../utils/logger";
-import {
- lockTranscriptSpeaker,
- normalizeTranscriptSegment,
- type TranscriptSpeakerLockSource,
- type TranscriptSpeakerStatus,
-} from "../utils/transcriptSpeakerState";
-
-export interface TranscriptSegment {
- id: string;
- text: string;
- source: "mic" | "system";
- timestamp?: number;
- speaker?: string;
- speakerName?: string;
- speakerIsPlaceholder?: boolean;
- suggestedName?: string;
- suggestedProfileId?: number;
- speakerStatus?: TranscriptSpeakerStatus;
- speakerLocked?: boolean;
- speakerLockSource?: TranscriptSpeakerLockSource;
-}
-
-interface SpeakerIdentification {
- speakerId: string;
- displayName?: string | null;
- startTime: number;
- endTime: number;
-}
-
-interface RecentSystemSpeaker {
- speakerId: string;
- speakerName: string | null;
- speakerIsPlaceholder: boolean;
- updatedAt: number;
-}
-
-interface UseMeetingTranscriptionReturn {
- isRecording: boolean;
- transcript: string;
- partialTranscript: string;
- segments: TranscriptSegment[];
- micPartial: string;
- systemPartial: string;
- systemPartialSpeakerId: string | null;
- systemPartialSpeakerName: string | null;
- error: string | null;
- diarizationSessionId: string | null;
- sessionDiarizationEnabled: boolean;
- sessionExpectedCount: number;
- userTouchedStepper: boolean;
- setSessionDiarizationEnabled: (enabled: boolean) => void;
- setSessionExpectedCount: (count: number) => void;
- prepareTranscription: () => Promise<void>;
- startTranscription: (_options?: {
- seedSegments?: TranscriptSegment[];
- noteId?: number | null;
- expectedCount?: number;
- }) => Promise<void>;
- stopTranscription: () => Promise<void>;
- lockSpeaker: (speakerId: string, displayName: string) => void;
-}
-
-const MEETING_AUDIO_BUFFER_SIZE = 800;
-const MEETING_STOP_FLUSH_TIMEOUT_MS = 50;
-const MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS = {
- echoCancellation: false,
- noiseSuppression: false,
- autoGainControl: false,
-} as const;
-
-const SPEAKER_IDENTIFICATION_RETENTION_MS = 30_000;
-const SYSTEM_SPEAKER_CARRY_FORWARD_MS = 8_000;
-const buildTranscriptText = (segments: TranscriptSegment[]) =>
- segments
- .map((segment) => segment.text)
- .join(" ")
- .trim();
-
-const getSpeakerNumericIndex = (speakerId?: string): number | null => {
- if (!speakerId) {
- return null;
- }
-
- const match = speakerId.match(/speaker_(\d+)/);
- return match ? Number(match[1]) : null;
-};
-
-const isSegmentWithinIdentificationWindow = (
- segment: TranscriptSegment,
- identification: SpeakerIdentification
-) => {
- if (segment.source !== "system" || segment.timestamp == null) {
- return false;
- }
-
- return (
- segment.timestamp >= identification.startTime && segment.timestamp <= identification.endTime
- );
-};
-
-const getMeetingTranscriptionOptions = () => {
- const state = getSettings();
- const resolved = selectResolvedMeetingTranscription(state);
-
- if (resolved.useLocalWhisper) {
- return {
- provider: "local" as const,
- localProvider: resolved.localTranscriptionProvider,
- localModel:
- resolved.localTranscriptionProvider === "nvidia"
- ? resolved.parakeetModel || "parakeet-tdt-0.6b-v3"
- : resolved.whisperModel || "base",
- };
- }
-
- const catalog = useStreamingProvidersStore.getState().providers;
- const provider =
- catalog?.find((p) => p.id === resolved.cloudTranscriptionProvider) ?? catalog?.[0];
- const byokKeyAvailable = provider?.id === "openai" ? !!state.openaiApiKey : true;
- const mode =
- resolved.cloudTranscriptionMode === "byok" && byokKeyAvailable ? "byok" : "openwhispr";
- if (!provider) {
- logger.debug(
- "Streaming providers catalog not loaded, falling back to OpenAI default",
- {},
- "meeting"
- );
- return { provider: "openai-realtime" as const, model: "gpt-4o-mini-transcribe", mode };
- }
- const model =
- provider.models.find((m) => m.id === resolved.cloudTranscriptionModel)?.id ??
- provider.models.find((m) => m.default)?.id ??
- provider.models[0]?.id;
- return { provider: `${provider.id}-realtime` as const, model, mode };
-};
-
-const stopMediaStream = (stream: MediaStream | null) => {
- try {
- stream?.getTracks().forEach((track) => track.stop());
- } catch {}
-};
-
-const getDisplayCaptureOptions = (mode: "loopback" | "portal") => {
- if (mode === "loopback") {
- return { video: true, audio: true };
- }
-
- return {
- video: true,
- audio: true,
- systemAudio: "include",
- windowAudio: "system",
- selfBrowserSurface: "exclude",
- } as DisplayMediaStreamOptions & {
- systemAudio?: "include";
- windowAudio?: "system";
- selfBrowserSurface?: "exclude";
- };
-};
-
-const requestSystemAudioDisplayStream = async (mode: "loopback" | "portal") => {
- try {
- const stream = await navigator.mediaDevices.getDisplayMedia(getDisplayCaptureOptions(mode));
- const audioTrack = stream.getAudioTracks()[0];
-
- if (!audioTrack) {
- stopMediaStream(stream);
- return { stream: null, error: new Error("No system-audio track was returned.") };
- }
-
- stream.getVideoTracks().forEach((track) => track.stop());
- return { stream, error: null };
- } catch (error) {
- return { stream: null, error: error as Error };
- }
-};
-
-const prepareMeetingSystemAudioCapture = (initialSystemAudioAccess: SystemAudioAccessResult) => {
- const initialSystemAudioStrategy = initialSystemAudioAccess.strategy ?? "unsupported";
- const initialDisplayCaptureStrategy = isRendererSystemAudioStrategy(initialSystemAudioStrategy)
- ? initialSystemAudioStrategy
- : null;
- const systemCapturePromise = initialDisplayCaptureStrategy
- ? requestSystemAudioDisplayStream(
- getDisplayCaptureModeForStrategy(initialDisplayCaptureStrategy)
- )
- : Promise.resolve({ stream: null, error: null });
-
- return {
- initialSystemAudioStrategy,
- initialDisplayCaptureStrategy,
- systemCapturePromise,
- };
-};
-
-const ensureRendererSystemAudioCapture = async ({
- initialDisplayCaptureStrategy,
- systemAudioStrategy,
- systemCaptureResult,
-}: {
- initialDisplayCaptureStrategy: "loopback" | "browser-portal" | null;
- systemAudioStrategy: SystemAudioStrategy;
- systemCaptureResult: { stream: MediaStream | null; error: Error | null };
-}) => {
- if (
- systemCaptureResult.stream ||
- systemCaptureResult.error ||
- !isRendererSystemAudioStrategy(systemAudioStrategy) ||
- initialDisplayCaptureStrategy
- ) {
- return systemCaptureResult;
- }
-
- return requestSystemAudioDisplayStream(getDisplayCaptureModeForStrategy(systemAudioStrategy));
-};
-
-const getMeetingWorkletBlobUrl = (() => {
- let blobUrl: string | null = null;
-
- return () => {
- if (blobUrl) return blobUrl;
-
- const code = `
-const BUFFER_SIZE = ${MEETING_AUDIO_BUFFER_SIZE};
-class MeetingPCMProcessor extends AudioWorkletProcessor {
- constructor() {
- super();
- this._buffer = new Int16Array(BUFFER_SIZE);
- this._offset = 0;
- this._stopped = false;
- this.port.onmessage = (event) => {
- if (event.data === "stop") {
- if (this._offset > 0) {
- const partial = this._buffer.slice(0, this._offset);
- this.port.postMessage(partial.buffer, [partial.buffer]);
- this._buffer = new Int16Array(BUFFER_SIZE);
- this._offset = 0;
- }
- this._stopped = true;
- }
- };
- }
- process(inputs) {
- if (this._stopped) return false;
- const input = inputs[0]?.[0];
- if (!input) return true;
- for (let i = 0; i < input.length; i++) {
- const s = Math.max(-1, Math.min(1, input[i]));
- this._buffer[this._offset++] = s < 0 ? s * 0x8000 : s * 0x7fff;
- if (this._offset >= BUFFER_SIZE) {
- this.port.postMessage(this._buffer.buffer, [this._buffer.buffer]);
- this._buffer = new Int16Array(BUFFER_SIZE);
- this._offset = 0;
- }
- }
- return true;
- }
-}
-registerProcessor("meeting-pcm-processor", MeetingPCMProcessor);
-`;
-
- blobUrl = URL.createObjectURL(new Blob([code], { type: "application/javascript" }));
- return blobUrl;
- };
-})();
-
-const getMeetingMicConstraints = async (): Promise<MediaStreamConstraints> => {
- const { preferBuiltInMic, selectedMicDeviceId } = getSettings();
-
- if (preferBuiltInMic) {
- try {
- const devices = await navigator.mediaDevices.enumerateDevices();
- const builtInMic = devices.find(
- (device) => device.kind === "audioinput" && isBuiltInMicrophone(device.label)
- );
-
- if (builtInMic?.deviceId) {
- return {
- audio: {
- deviceId: { exact: builtInMic.deviceId },
- ...MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS,
- },
- };
- }
- } catch (err) {
- logger.debug(
- "Failed to enumerate microphones for meeting transcription",
- { error: (err as Error).message },
- "meeting"
- );
- }
- }
-
- if (selectedMicDeviceId && selectedMicDeviceId !== "default") {
- return {
- audio: {
- deviceId: { exact: selectedMicDeviceId },
- ...MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS,
- },
- };
- }
-
- return { audio: MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS };
-};
-
-const createAudioPipeline = async ({
- stream,
- context,
- onChunk,
-}: {
- stream: MediaStream;
- context: AudioContext;
- onChunk: (chunk: ArrayBuffer) => void;
-}) => {
- if (context.state === "suspended") {
- await context.resume();
- }
-
- await context.audioWorklet.addModule(getMeetingWorkletBlobUrl());
-
- const source = context.createMediaStreamSource(stream);
- const processor = new AudioWorkletNode(context, "meeting-pcm-processor");
- const silentGain = context.createGain();
- silentGain.gain.value = 0;
-
- processor.port.onmessage = (event) => {
- const chunk = event.data;
- if (!(chunk instanceof ArrayBuffer)) return;
- onChunk(chunk);
- };
-
- source.connect(processor);
- processor.connect(silentGain);
- silentGain.connect(context.destination);
-
- return { source, processor };
-};
-
-/**
- * Detach an AudioContext from hardware output to avoid Bluetooth routing issues.
- * When BT headphones become the default output, the AudioContext can stall due to
- * HFP sample-rate mismatches. Using a "none" sink keeps processing running without
- * coupling to any physical device.
- */
-const detachFromOutputDevice = async (ctx: AudioContext) => {
- if ("setSinkId" in ctx) {
- try {
- await (ctx as any).setSinkId({ type: "none" });
- } catch {}
- }
-};
-
-const flushAndDisconnectProcessor = async (processor: AudioWorkletNode | null) => {
- if (!processor) return;
-
- try {
- processor.port.postMessage("stop");
- await new Promise((resolve) => {
- window.setTimeout(resolve, MEETING_STOP_FLUSH_TIMEOUT_MS);
- });
- } catch {}
-
- processor.port.onmessage = null;
- processor.disconnect();
-};
-
-let segmentCounter = 0;
-
-export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
- const [isRecording, setIsRecording] = useState(false);
- const [transcript, setTranscript] = useState("");
- const [partialTranscript, setPartialTranscript] = useState("");
- const [segments, setSegments] = useState<TranscriptSegment[]>([]);
- const [micPartial, setMicPartial] = useState("");
- const [systemPartial, setSystemPartial] = useState("");
- const [systemPartialSpeakerId, setSystemPartialSpeakerId] = useState<string | null>(null);
- const [systemPartialSpeakerName, setSystemPartialSpeakerName] = useState<string | null>(null);
- const [error, setError] = useState<string | null>(null);
- const [diarizationSessionId, setDiarizationSessionId] = useState<string | null>(null);
- const [sessionDiarizationEnabled, _setSessionDiarizationEnabled] = useState<boolean>(
- () =>
- (getSettings() as { speakerDiarizationEnabled?: boolean }).speakerDiarizationEnabled ?? true
- );
- const [sessionExpectedCount, _setSessionExpectedCount] = useState<number>(
- DEFAULT_EXPECTED_SPEAKER_COUNT
- );
- const [userTouchedStepper, setUserTouchedStepper] = useState(false);
-
- const micContextRef = useRef<AudioContext | null>(null);
- const micSourceRef = useRef<MediaStreamAudioSourceNode | null>(null);
- const micProcessorRef = useRef<AudioWorkletNode | null>(null);
- const micStreamRef = useRef<MediaStream | null>(null);
- const systemContextRef = useRef<AudioContext | null>(null);
- const systemSourceRef = useRef<MediaStreamAudioSourceNode | null>(null);
- const systemProcessorRef = useRef<AudioWorkletNode | null>(null);
- const systemStreamRef = useRef<MediaStream | null>(null);
- const isRecordingRef = useRef(false);
- const isStartingRef = useRef(false);
- const isPreparedRef = useRef(false);
- const segmentsRef = useRef<TranscriptSegment[]>([]);
- const preparePromiseRef = useRef<Promise<void> | null>(null);
- const ipcCleanupsRef = useRef<Array<() => void>>([]);
- const pendingCleanupRef = useRef<ReturnType<typeof setTimeout> | null>(null);
- const speakerIdentificationsRef = useRef<SpeakerIdentification[]>([]);
- const nextPlaceholderSpeakerIndexRef = useRef(0);
- const systemPartialSpeakerIdRef = useRef<string | null>(null);
- const recentSystemSpeakerRef = useRef<RecentSystemSpeaker | null>(null);
- const speakerLocksRef = useRef<Map<string, string>>(new Map());
- const pushConfigRef = useRef<ReturnType<typeof setTimeout> | null>(null);
-
- const pushConfig = useCallback((enabled: boolean, expectedCount: number) => {
- if (pushConfigRef.current) clearTimeout(pushConfigRef.current);
- pushConfigRef.current = setTimeout(() => {
- (
- window.electronAPI as unknown as {
- setMeetingSessionSpeakerConfig?: (config: {
- enabled: boolean;
- expectedCount: number;
- }) => void;
- }
- )?.setMeetingSessionSpeakerConfig?.({ enabled, expectedCount });
- }, 150);
- }, []);
-
- const setSessionDiarizationEnabled = useCallback(
- (enabled: boolean) => {
- _setSessionDiarizationEnabled(enabled);
- pushConfig(enabled, sessionExpectedCount);
- },
- [pushConfig, sessionExpectedCount]
- );
-
- const setSessionExpectedCount = useCallback(
- (count: number) => {
- const clamped = Math.max(1, Math.min(MAX_SPEAKER_COUNT, count));
- _setSessionExpectedCount(clamped);
- setUserTouchedStepper(true);
- pushConfig(sessionDiarizationEnabled, clamped);
- },
- [pushConfig, sessionDiarizationEnabled]
- );
-
- const setSystemPartialSpeakerIdentity = useCallback(
- (speakerId: string | null, speakerName: string | null) => {
- systemPartialSpeakerIdRef.current = speakerId;
- setSystemPartialSpeakerId(speakerId);
- setSystemPartialSpeakerName(speakerName);
- },
- []
- );
-
- const applySpeakerIdentification = useCallback(
- (segment: TranscriptSegment, identification: SpeakerIdentification): TranscriptSegment => {
- if (
- segment.source !== "system" ||
- !isSegmentWithinIdentificationWindow(segment, identification) ||
- (segment.speaker &&
- !segment.speakerIsPlaceholder &&
- segment.speakerStatus !== "provisional") ||
- segment.speakerLocked
- ) {
- return segment;
- }
-
- return normalizeTranscriptSegment({
- ...segment,
- speaker: identification.speakerId,
- speakerName: identification.displayName ?? segment.speakerName,
- speakerIsPlaceholder: false,
- speakerStatus: "confirmed",
- });
- },
- []
- );
-
- const rememberSystemSpeaker = useCallback(
- (
- speakerId: string | null,
- speakerName: string | null,
- speakerIsPlaceholder: boolean,
- updatedAt = Date.now()
- ) => {
- recentSystemSpeakerRef.current = speakerId
- ? {
- speakerId,
- speakerName,
- speakerIsPlaceholder,
- updatedAt,
- }
- : null;
- },
- []
- );
-
- const getRecentSystemSpeaker = useCallback((nowMs: number) => {
- const candidate = recentSystemSpeakerRef.current;
- if (!candidate) {
- return null;
- }
-
- return nowMs - candidate.updatedAt <= SYSTEM_SPEAKER_CARRY_FORWARD_MS ? candidate : null;
- }, []);
-
- const reserveSpeakerIndex = useCallback((speakerId?: string) => {
- const idx = getSpeakerNumericIndex(speakerId);
- if (idx == null) {
- return;
- }
-
- nextPlaceholderSpeakerIndexRef.current = Math.max(
- nextPlaceholderSpeakerIndexRef.current,
- idx + 1
- );
- }, []);
-
- const assignProvisionalSpeaker = useCallback(
- (segment: TranscriptSegment) => {
- if (segment.source !== "system" || segment.speaker) {
- return segment;
- }
-
- const nowMs = segment.timestamp ?? Date.now();
- const partialSpeakerId = systemPartialSpeakerIdRef.current;
- if (partialSpeakerId) {
- reserveSpeakerIndex(partialSpeakerId);
- return normalizeTranscriptSegment({
- ...segment,
- speaker: partialSpeakerId,
- speakerIsPlaceholder: true,
- speakerStatus: "provisional",
- });
- }
-
- const recentSystemSpeaker = getRecentSystemSpeaker(nowMs);
- if (recentSystemSpeaker?.speakerId) {
- reserveSpeakerIndex(recentSystemSpeaker.speakerId);
- return normalizeTranscriptSegment({
- ...segment,
- speaker: recentSystemSpeaker.speakerId,
- speakerName: recentSystemSpeaker.speakerName ?? undefined,
- speakerIsPlaceholder: recentSystemSpeaker.speakerIsPlaceholder,
- speakerStatus: "provisional",
- });
- }
-
- const previousSystemSegment = [...segmentsRef.current]
- .reverse()
- .find(
- (candidate) =>
- candidate.source === "system" &&
- candidate.speaker &&
- candidate.timestamp != null &&
- nowMs - candidate.timestamp <= SYSTEM_SPEAKER_CARRY_FORWARD_MS
- );
-
- if (previousSystemSegment?.speaker) {
- reserveSpeakerIndex(previousSystemSegment.speaker);
- return normalizeTranscriptSegment({
- ...segment,
- speaker: previousSystemSegment.speaker,
- speakerName: previousSystemSegment.speakerName,
- speakerIsPlaceholder: true,
- speakerStatus: "provisional",
- });
- }
-
- const speakerId = `speaker_${nextPlaceholderSpeakerIndexRef.current}`;
- nextPlaceholderSpeakerIndexRef.current += 1;
-
- return normalizeTranscriptSegment({
- ...segment,
- speaker: speakerId,
- speakerIsPlaceholder: true,
- speakerStatus: "provisional",
- });
- },
- [getRecentSystemSpeaker, reserveSpeakerIndex]
- );
-
- const cleanup = useCallback(async () => {
- await flushAndDisconnectProcessor(micProcessorRef.current);
- micProcessorRef.current = null;
-
- micSourceRef.current?.disconnect();
- micSourceRef.current = null;
-
- try {
- micStreamRef.current?.getTracks().forEach((t) => t.stop());
- } catch {}
- micStreamRef.current = null;
-
- try {
- await micContextRef.current?.close();
- } catch {}
- micContextRef.current = null;
-
- await flushAndDisconnectProcessor(systemProcessorRef.current);
- systemProcessorRef.current = null;
-
- systemSourceRef.current?.disconnect();
- systemSourceRef.current = null;
-
- stopMediaStream(systemStreamRef.current);
- systemStreamRef.current = null;
-
- try {
- await systemContextRef.current?.close();
- } catch {}
- systemContextRef.current = null;
-
- ipcCleanupsRef.current.forEach((fn) => fn());
- ipcCleanupsRef.current = [];
- isPreparedRef.current = false;
- isRecordingRef.current = false;
- isStartingRef.current = false;
- }, []);
-
- const stopTranscription = useCallback(async () => {
- if (!isRecordingRef.current) return;
-
- isRecordingRef.current = false;
- isStartingRef.current = false;
- setIsRecording(false);
-
- await cleanup();
-
- try {
- const result = await window.electronAPI?.meetingTranscriptionStop?.();
- if (result?.diarizationSessionId) {
- setDiarizationSessionId(result.diarizationSessionId);
- }
- if (result?.success && result.transcript) {
- setTranscript(result.transcript);
- } else if (result?.error) {
- setError(result.error);
- }
- } catch (err) {
- setError((err as Error).message);
- logger.error(
- "Meeting transcription stop failed",
- { error: (err as Error).message },
- "meeting"
- );
- }
-
- logger.info("Meeting transcription stopped", {}, "meeting");
- }, [cleanup]);
-
- const prepareTranscription = useCallback(async () => {
- if (isPreparedRef.current || isRecordingRef.current || isStartingRef.current) return;
- if (preparePromiseRef.current) return;
-
- logger.info("Meeting transcription preparing (pre-warming WebSockets)...", {}, "meeting");
-
- const promise = (async () => {
- try {
- const result = await window.electronAPI?.meetingTranscriptionPrepare?.(
- getMeetingTranscriptionOptions()
- );
-
- if (result?.success) {
- isPreparedRef.current = true;
- logger.info(
- "Meeting transcription prepared",
- { alreadyPrepared: result.alreadyPrepared },
- "meeting"
- );
- } else {
- logger.error("Meeting transcription prepare failed", { error: result?.error }, "meeting");
- }
- } catch (err) {
- logger.error(
- "Meeting transcription prepare error",
- { error: (err as Error).message },
- "meeting"
- );
- } finally {
- preparePromiseRef.current = null;
- }
- })();
-
- preparePromiseRef.current = promise;
- await promise;
- }, []);
-
- const startTranscription = useCallback(
- async (_options?: {
- seedSegments?: TranscriptSegment[];
- noteId?: number | null;
- expectedCount?: number;
- }) => {
- if (isRecordingRef.current || isStartingRef.current) return;
- isStartingRef.current = true;
- const initialEnabled =
- (getSettings() as { speakerDiarizationEnabled?: boolean }).speakerDiarizationEnabled ??
- true;
- const initialCount = Math.max(
- 1,
- Math.min(MAX_SPEAKER_COUNT, _options?.expectedCount ?? DEFAULT_EXPECTED_SPEAKER_COUNT)
- );
- _setSessionDiarizationEnabled(initialEnabled);
- _setSessionExpectedCount(initialCount);
- setUserTouchedStepper(false);
- const systemAudioAccessPromise =
- window.electronAPI?.checkSystemAudioAccess?.() ??
- Promise.resolve(DEFAULT_SYSTEM_AUDIO_ACCESS);
-
- logger.info("Meeting transcription starting...", {}, "meeting");
- const seed = _options?.seedSegments ?? [];
- const locks = new Map<string, string>();
- let maxSpeakerIndex = -1;
- for (const s of seed) {
- const idx = getSpeakerNumericIndex(s.speaker);
- if (idx != null && idx > maxSpeakerIndex) maxSpeakerIndex = idx;
- if (s.speakerLocked && s.speaker && s.speakerName) {
- locks.set(s.speaker, s.speakerName);
- }
- }
- setTranscript(buildTranscriptText(seed));
- setPartialTranscript("");
- setSegments(seed);
- segmentsRef.current = seed;
- setMicPartial("");
- setSystemPartial("");
- setSystemPartialSpeakerIdentity(null, null);
- setError(null);
- speakerIdentificationsRef.current = [];
- nextPlaceholderSpeakerIndexRef.current = maxSpeakerIndex + 1;
- recentSystemSpeakerRef.current = null;
- speakerLocksRef.current = locks;
-
- isRecordingRef.current = true;
- setIsRecording(true);
-
- if (preparePromiseRef.current) {
- logger.debug("Waiting for in-flight prepare to finish...", {}, "meeting");
- await preparePromiseRef.current;
- }
-
- try {
- const startTime = performance.now();
- const initialSystemAudioAccess =
- (await systemAudioAccessPromise) ?? getFallbackSystemAudioAccess();
- const { initialSystemAudioStrategy, initialDisplayCaptureStrategy, systemCapturePromise } =
- prepareMeetingSystemAudioCapture(initialSystemAudioAccess);
-
- const [startResult, micResult, initialSystemCaptureResult] = await Promise.all([
- window.electronAPI?.meetingTranscriptionStart?.({
- ...getMeetingTranscriptionOptions(),
- noteId: _options?.noteId ?? null,
- }),
- getMeetingMicConstraints().then(async (constraints) => {
- try {
- return await navigator.mediaDevices.getUserMedia(constraints);
- } catch (err) {
- const hasExactDevice =
- typeof constraints.audio === "object" &&
- constraints.audio !== null &&
- "deviceId" in constraints.audio;
- if (hasExactDevice) {
- try {
- const fallbackStream = await navigator.mediaDevices.getUserMedia({
- audio: MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS,
- });
- logger.info(
- "Meeting mic capture recovered using default device",
- { error: (err as Error).message },
- "meeting"
- );
- return fallbackStream;
- } catch (fallbackErr) {
- logger.error(
- "Meeting mic capture failed, continuing with system audio only",
- { error: (fallbackErr as Error).message },
- "meeting"
- );
- return null;
- }
- }
- logger.error(
- "Meeting mic capture failed, continuing with system audio only",
- { error: (err as Error).message, constraints },
- "meeting"
- );
- return null;
- }
- }),
- systemCapturePromise,
- ]);
- let systemCaptureResult = initialSystemCaptureResult;
-
- const streamsMs = performance.now() - startTime;
- if (!isRecordingRef.current) {
- logger.info("Meeting transcription aborted during setup (stop called)", {}, "meeting");
- stopMediaStream(micResult);
- stopMediaStream(systemCaptureResult.stream);
- isStartingRef.current = false;
- return;
- }
-
- if (!startResult?.success) {
- logger.error(
- "Meeting transcription IPC start failed",
- { error: startResult?.error },
- "meeting"
- );
- setError(startResult?.error || "Failed to start meeting transcription");
- stopMediaStream(micResult);
- stopMediaStream(systemCaptureResult.stream);
- isRecordingRef.current = false;
- isStartingRef.current = false;
- setIsRecording(false);
- return;
- }
-
- const systemAudioMode = startResult.systemAudioMode || initialSystemAudioAccess.mode;
- const systemAudioStrategy = startResult.systemAudioStrategy || initialSystemAudioStrategy;
- systemCaptureResult = await ensureRendererSystemAudioCapture({
- initialDisplayCaptureStrategy,
- systemAudioStrategy,
- systemCaptureResult,
- });
- const systemAudioHandledInMain =
- systemAudioMode !== "unsupported" && !isRendererSystemAudioStrategy(systemAudioStrategy);
- const systemCaptureError = systemAudioHandledInMain ? null : systemCaptureResult.error;
-
- if (!micResult && (systemAudioHandledInMain || systemCaptureResult.stream)) {
- setError("Microphone capture failed. Continuing with system audio only.");
- }
-
- if (!micResult && !systemCaptureResult.stream && !systemAudioHandledInMain) {
- logger.error("Meeting transcription has no available audio source", {}, "meeting");
- setError(
- systemAudioMode === "unsupported"
- ? "No microphone is available and system audio capture is unsupported on this device."
- : systemCaptureError?.message ||
- "No microphone is available and system audio capture could not be started."
- );
- await window.electronAPI?.meetingTranscriptionStop?.();
- isRecordingRef.current = false;
- isStartingRef.current = false;
- setIsRecording(false);
- return;
- }
-
- const partialSetters = { mic: setMicPartial, system: setSystemPartial };
-
- const segmentCleanup = window.electronAPI?.onMeetingTranscriptionSegment?.(
- (data: {
- text: string;
- source: "mic" | "system";
- type: "partial" | "final" | "retract";
- timestamp?: number;
- }) => {
- const setPartialForSource = partialSetters[data.source];
-
- if (data.type === "retract") {
- setSegments((prev) => {
- const next = prev.filter(
- (seg) =>
- !(
- seg.source === data.source &&
- seg.timestamp === data.timestamp &&
- seg.text === data.text
- )
- );
- segmentsRef.current = next;
- setTranscript(buildTranscriptText(next));
- return next;
- });
- return;
- }
-
- if (data.type === "partial") {
- setPartialForSource(data.text);
- setPartialTranscript(data.text);
- if (data.source === "system" && !systemPartialSpeakerIdRef.current) {
- const speakerId = `speaker_${nextPlaceholderSpeakerIndexRef.current}`;
- nextPlaceholderSpeakerIndexRef.current += 1;
- setSystemPartialSpeakerIdentity(speakerId, null);
- }
- } else {
- let rawSegment: TranscriptSegment = normalizeTranscriptSegment({
- id: `seg-${++segmentCounter}`,
- text: data.text,
- source: data.source,
- timestamp: data.timestamp,
- });
-
- for (let i = speakerIdentificationsRef.current.length - 1; i >= 0; i -= 1) {
- rawSegment = applySpeakerIdentification(
- rawSegment,
- speakerIdentificationsRef.current[i]
- );
- }
-
- const provisional = assignProvisionalSpeaker(rawSegment);
- reserveSpeakerIndex(provisional.speaker);
- const lockedName = provisional.speaker
- ? speakerLocksRef.current.get(provisional.speaker)
- : undefined;
- const seg = lockedName
- ? lockTranscriptSpeaker(provisional, {
- speakerName: lockedName,
- speakerIsPlaceholder: false,
- suggestedName: undefined,
- suggestedProfileId: undefined,
- })
- : provisional;
- setSegments((prev) => {
- const ts = seg.timestamp ?? Infinity;
- let i = prev.length;
- while (i > 0 && (prev[i - 1].timestamp ?? 0) > ts) i--;
- const next =
- i === prev.length ? [...prev, seg] : [...prev.slice(0, i), seg, ...prev.slice(i)];
- segmentsRef.current = next;
- setTranscript(buildTranscriptText(next));
- return next;
- });
- if (data.source === "system" && seg.speaker) {
- rememberSystemSpeaker(
- seg.speaker,
- seg.speakerName ?? null,
- !!seg.speakerIsPlaceholder,
- seg.timestamp ?? Date.now()
- );
- }
- setPartialForSource("");
- if (data.source === "system") {
- setSystemPartialSpeakerIdentity(null, null);
- }
- setPartialTranscript("");
- }
- }
- );
- if (segmentCleanup) ipcCleanupsRef.current.push(segmentCleanup);
-
- const speakerCleanup = window.electronAPI?.onMeetingSpeakerIdentified?.((data) => {
- reserveSpeakerIndex(data.speakerId);
- setSystemPartialSpeakerIdentity(data.speakerId, data.displayName ?? null);
- rememberSystemSpeaker(data.speakerId, data.displayName ?? null, false, data.endTime);
- speakerIdentificationsRef.current = [
- ...speakerIdentificationsRef.current.filter(
- (id) => id.endTime >= data.endTime - SPEAKER_IDENTIFICATION_RETENTION_MS
- ),
- data,
- ];
- setSegments((prev) => {
- const next = prev.map((segment) => applySpeakerIdentification(segment, data));
- segmentsRef.current = next;
- return next;
- });
- });
- if (speakerCleanup) ipcCleanupsRef.current.push(speakerCleanup);
-
- const mergeCleanup = window.electronAPI?.onMeetingSpeakersMerged?.((merges) => {
- setSegments((prev) => {
- let next = prev;
- for (const { keep, remove, displayName } of merges) {
- next = next.map((seg) => {
- if (seg.speaker !== remove || seg.speakerLocked) return seg;
- return normalizeTranscriptSegment({
- ...seg,
- speaker: keep,
- speakerName: displayName ?? seg.speakerName,
- });
- });
- }
- segmentsRef.current = next;
- return next;
- });
-
- for (const { keep, remove, displayName } of merges) {
- if (recentSystemSpeakerRef.current?.speakerId === remove) {
- recentSystemSpeakerRef.current.speakerId = keep;
- if (displayName) recentSystemSpeakerRef.current.speakerName = displayName;
- }
-
- for (const id of speakerIdentificationsRef.current) {
- if (id.speakerId === remove) id.speakerId = keep;
- }
-
- const lockedName = speakerLocksRef.current.get(remove);
- if (lockedName) {
- speakerLocksRef.current.set(keep, lockedName);
- speakerLocksRef.current.delete(remove);
- }
- }
- });
- if (mergeCleanup) ipcCleanupsRef.current.push(mergeCleanup);
-
- const errorCleanup = window.electronAPI?.onMeetingTranscriptionError?.((err) => {
- setError(err);
- logger.error("Meeting transcription stream error", { error: err }, "meeting");
- });
- if (errorCleanup) ipcCleanupsRef.current.push(errorCleanup);
-
- if (startResult.oneOnOneAttendee) {
- const synthetic: SpeakerIdentification = {
- speakerId: "speaker_0",
- displayName: startResult.oneOnOneAttendee.displayName,
- startTime: 0,
- endTime: Number.MAX_SAFE_INTEGER,
- };
- reserveSpeakerIndex(synthetic.speakerId);
- setSystemPartialSpeakerIdentity(synthetic.speakerId, synthetic.displayName);
- rememberSystemSpeaker(synthetic.speakerId, synthetic.displayName, false, Date.now());
- speakerIdentificationsRef.current.push(synthetic);
- }
-
- const pendingMicChunks: ArrayBuffer[] = [];
- const pendingSystemChunks: ArrayBuffer[] = [];
- let socketReady = false;
-
- let micPipelinePromise: Promise<void> | null = null;
- if (micResult) {
- micStreamRef.current = micResult;
- const micContext = new AudioContext({ sampleRate: 24000 });
- await detachFromOutputDevice(micContext);
- micContextRef.current = micContext;
-
- micPipelinePromise = createAudioPipeline({
- stream: micResult,
- context: micContext,
- onChunk: (chunk) => {
- if (!isRecordingRef.current) return;
- if (socketReady) {
- window.electronAPI?.meetingTranscriptionSend?.(chunk, "mic");
- return;
- }
- pendingMicChunks.push(chunk.slice(0));
- },
- }).then(({ source, processor }) => {
- micSourceRef.current = source;
- micProcessorRef.current = processor;
-
- const micTrack = micResult.getAudioTracks()[0];
- logger.info(
- "Mic capture started for meeting transcription",
- {
- label: micTrack?.label,
- settings: micTrack?.getSettings(),
- },
- "meeting"
- );
- });
- }
-
- if (micPipelinePromise) {
- await micPipelinePromise;
- }
-
- if (systemCaptureResult.stream) {
- const systemStream = systemCaptureResult.stream;
- systemStreamRef.current = systemStream;
-
- const systemContext = new AudioContext({ sampleRate: 24000 });
- await detachFromOutputDevice(systemContext);
- systemContextRef.current = systemContext;
-
- await createAudioPipeline({
- stream: systemStream,
- context: systemContext,
- onChunk: (chunk) => {
- if (!isRecordingRef.current) return;
- if (socketReady) {
- window.electronAPI?.meetingTranscriptionSend?.(chunk, "system");
- return;
- }
- pendingSystemChunks.push(chunk.slice(0));
- },
- }).then(({ source, processor }) => {
- systemSourceRef.current = source;
- systemProcessorRef.current = processor;
- });
- } else if (systemCaptureError) {
- if (systemAudioStrategy === "browser-portal") {
- logger.warn(
- "Linux system audio capture failed, continuing with mic only",
- { error: systemCaptureError.message },
- "meeting"
- );
- } else if (systemAudioStrategy === "loopback") {
- logger.warn(
- "System audio loopback failed, continuing with mic only",
- { error: systemCaptureError.message },
- "meeting"
- );
- }
- }
-
- if (!isRecordingRef.current) {
- logger.info(
- "Meeting transcription aborted during pipeline setup (stop called)",
- {},
- "meeting"
- );
- isStartingRef.current = false;
- await cleanup();
- return;
- }
-
- isStartingRef.current = false;
- socketReady = true;
-
- for (const chunk of pendingMicChunks) {
- window.electronAPI?.meetingTranscriptionSend?.(chunk, "mic");
- }
- for (const chunk of pendingSystemChunks) {
- window.electronAPI?.meetingTranscriptionSend?.(chunk, "system");
- }
-
- const totalMs = performance.now() - startTime;
- logger.info(
- "Meeting transcription started successfully",
- {
- systemAudioMode,
- systemAudioStrategy,
- bufferedChunks: pendingMicChunks.length,
- bufferedSystemChunks: pendingSystemChunks.length,
- streamsMs: Math.round(streamsMs),
- totalMs: Math.round(totalMs),
- wasPrepared: isPreparedRef.current,
- },
- "meeting"
- );
- } catch (err) {
- logger.error(
- "Meeting transcription setup failed",
- { error: (err as Error).message },
- "meeting"
- );
- setError((err as Error).message);
- isRecordingRef.current = false;
- isStartingRef.current = false;
- setIsRecording(false);
- await cleanup();
- }
- },
- [
- applySpeakerIdentification,
- assignProvisionalSpeaker,
- cleanup,
- rememberSystemSpeaker,
- reserveSpeakerIndex,
- setSystemPartialSpeakerIdentity,
- ]
- );
-
- const lockSpeaker = useCallback(
- (speakerId: string, displayName: string) => {
- if (!speakerId || !displayName) return;
- speakerLocksRef.current.set(speakerId, displayName);
- setSegments((prev) => {
- const next = prev.map((s) =>
- s.speaker === speakerId
- ? lockTranscriptSpeaker(s, {
- speakerName: displayName,
- speakerIsPlaceholder: false,
- suggestedName: undefined,
- suggestedProfileId: undefined,
- })
- : s
- );
- segmentsRef.current = next;
- return next;
- });
- const recent = recentSystemSpeakerRef.current;
- if (recent?.speakerId === speakerId) {
- recentSystemSpeakerRef.current = {
- ...recent,
- speakerName: displayName,
- speakerIsPlaceholder: false,
- };
- }
- if (systemPartialSpeakerIdRef.current === speakerId) {
- setSystemPartialSpeakerIdentity(speakerId, displayName);
- }
- },
- [setSystemPartialSpeakerIdentity]
- );
-
- useEffect(() => {
- getMeetingWorkletBlobUrl();
- }, []);
-
- useEffect(() => {
- if (pendingCleanupRef.current) {
- clearTimeout(pendingCleanupRef.current);
- pendingCleanupRef.current = null;
- }
-
- return () => {
- pendingCleanupRef.current = setTimeout(() => {
- pendingCleanupRef.current = null;
- void cleanup();
- }, 0);
- if (pushConfigRef.current) {
- clearTimeout(pushConfigRef.current);
- pushConfigRef.current = null;
- }
- };
- }, [cleanup]);
-
- return {
- isRecording,
- transcript,
- partialTranscript,
- segments,
- micPartial,
- systemPartial,
- systemPartialSpeakerId,
- systemPartialSpeakerName,
- error,
- diarizationSessionId,
- sessionDiarizationEnabled,
- sessionExpectedCount,
- userTouchedStepper,
- setSessionDiarizationEnabled,
- setSessionExpectedCount,
- prepareTranscription,
- startTranscription,
- stopTranscription,
- lockSpeaker,
- };
-}
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts
index f6ec5516d..64191ac05 100644
--- a/src/hooks/useSettings.ts
+++ b/src/hooks/useSettings.ts
@@ -40,6 +40,7 @@ export interface CleanupSettings {
export interface HotkeySettings {
dictationKey: string;
meetingKey: string;
+ meetingHotkeyLayoutMode: "side-panel" | "full-width";
activationMode: "tap" | "push";
}
@@ -213,6 +214,8 @@ function useSettingsInternal() {
mistralApiKey: store.mistralApiKey,
dictationKey: store.dictationKey,
meetingKey: store.meetingKey,
+ meetingHotkeyLayoutMode: store.meetingHotkeyLayoutMode,
+ setMeetingHotkeyLayoutMode: store.setMeetingHotkeyLayoutMode,
theme: store.theme,
setUseLocalWhisper: store.setUseLocalWhisper,
setWhisperModel: store.setWhisperModel,
diff --git a/src/locales/de/translation.json b/src/locales/de/translation.json
index 0ce90fcac..c153482f4 100644
--- a/src/locales/de/translation.json
+++ b/src/locales/de/translation.json
@@ -1285,7 +1285,10 @@
"meetingHotkey": {
"title": "Meeting-Modus-Hotkey",
"description": "Meeting-Modus starten und das Panel an den Bildschirmrand verschieben",
- "clear": "Hotkey entfernen"
+ "clear": "Hotkey entfernen",
+ "layoutLabel": "Beim Auslösen per Hotkey öffnen in:",
+ "layoutFullWidth": "Volle Breite",
+ "layoutSidePanel": "Seitenleiste"
},
"microphone": {
"description": "Wählen Sie das Eingabegerät für das Diktat",
@@ -1842,6 +1845,9 @@
"comingSoon": "Demnächst verfügbar",
"back": "Zurück"
},
+ "meetingPill": {
+ "returnToNote": "Zurück zur Aufnahme"
+ },
"context": {
"moveToFolder": "In Ordner verschieben",
"delete": "Löschen",
diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json
index 4ed42e096..b4f76fa91 100644
--- a/src/locales/en/translation.json
+++ b/src/locales/en/translation.json
@@ -1381,7 +1381,10 @@
"meetingHotkey": {
"title": "Meeting Mode Hotkey",
"description": "Start meeting mode and snap the panel to the side of the screen",
- "clear": "Remove hotkey"
+ "clear": "Remove hotkey",
+ "layoutLabel": "When triggered by hotkey, open in:",
+ "layoutFullWidth": "Full width",
+ "layoutSidePanel": "Side panel"
},
"microphone": {
"description": "Select which input device to use for dictation",
@@ -1999,6 +2002,9 @@
"comingSoon": "Coming Soon",
"back": "Back"
},
+ "meetingPill": {
+ "returnToNote": "Return to recording"
+ },
"empty": {
"title": "No notes here yet",
"description": "Create your first note to start writing",
diff --git a/src/locales/es/translation.json b/src/locales/es/translation.json
index 56b74c805..14076efbd 100644
--- a/src/locales/es/translation.json
+++ b/src/locales/es/translation.json
@@ -1333,7 +1333,10 @@
"meetingHotkey": {
"title": "Atajo modo reunión",
"description": "Iniciar modo reunión y ajustar el panel al lado de la pantalla",
- "clear": "Eliminar atajo"
+ "clear": "Eliminar atajo",
+ "layoutLabel": "Al activarse con el atajo, abrir en:",
+ "layoutFullWidth": "Ancho completo",
+ "layoutSidePanel": "Panel lateral"
},
"microphone": {
"description": "Selecciona qué dispositivo de entrada usar para dictado",
@@ -1890,6 +1893,9 @@
"comingSoon": "Próximamente",
"back": "Atrás"
},
+ "meetingPill": {
+ "returnToNote": "Volver a la grabación"
+ },
"context": {
"moveToFolder": "Mover a carpeta",
"delete": "Eliminar",
diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.json
index 9c6a5f92c..5cbc72404 100644
--- a/src/locales/fr/translation.json
+++ b/src/locales/fr/translation.json
@@ -1333,7 +1333,10 @@
"meetingHotkey": {
"title": "Raccourci mode réunion",
"description": "Démarrer le mode réunion et ancrer le panneau sur le côté de l'écran",
- "clear": "Supprimer le raccourci"
+ "clear": "Supprimer le raccourci",
+ "layoutLabel": "Lors du déclenchement par raccourci, ouvrir en :",
+ "layoutFullWidth": "Pleine largeur",
+ "layoutSidePanel": "Panneau latéral"
},
"microphone": {
"description": "Sélectionnez le périphérique d'entrée à utiliser pour la dictée",
@@ -1951,6 +1954,9 @@
"comingSoon": "Bientôt disponible",
"back": "Retour"
},
+ "meetingPill": {
+ "returnToNote": "Revenir à l'enregistrement"
+ },
"empty": {
"title": "Aucune note ici pour l'instant",
"description": "Créez votre première note pour commencer à écrire",
diff --git a/src/locales/it/translation.json b/src/locales/it/translation.json
index 887b0e832..71876ea44 100644
--- a/src/locales/it/translation.json
+++ b/src/locales/it/translation.json
@@ -1285,7 +1285,10 @@
"meetingHotkey": {
"title": "Scorciatoia modalità meeting",
"description": "Avvia la modalità meeting e posiziona il pannello a lato dello schermo",
- "clear": "Rimuovi scorciatoia"
+ "clear": "Rimuovi scorciatoia",
+ "layoutLabel": "Quando attivata da scorciatoia, apri in:",
+ "layoutFullWidth": "Larghezza completa",
+ "layoutSidePanel": "Pannello laterale"
},
"microphone": {
"description": "Seleziona il dispositivo di ingresso da usare per la dettatura",
@@ -1842,6 +1845,9 @@
"comingSoon": "Prossimamente",
"back": "Indietro"
},
+ "meetingPill": {
+ "returnToNote": "Torna alla registrazione"
+ },
"context": {
"moveToFolder": "Sposta nella cartella",
"delete": "Elimina",
diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.json
index 188786d12..6fbabf32d 100644
--- a/src/locales/ja/translation.json
+++ b/src/locales/ja/translation.json
@@ -1285,7 +1285,10 @@
"meetingHotkey": {
"title": "ミーティングモードホットキー",
"description": "ミーティングモードを開始し、パネルを画面の横に配置する",
- "clear": "ホットキーを削除"
+ "clear": "ホットキーを削除",
+ "layoutLabel": "ホットキーで起動したときに開く:",
+ "layoutFullWidth": "全幅",
+ "layoutSidePanel": "サイドパネル"
},
"microphone": {
"description": "ディクテーションに使用する入力デバイスを選択",
@@ -1825,6 +1828,9 @@
"comingSoon": "近日公開",
"back": "戻る"
},
+ "meetingPill": {
+ "returnToNote": "録音に戻る"
+ },
"onboarding": {
"llm": {
"title": "AI モデルを設定",
diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json
index 0a2a92e8e..a1718875b 100644
--- a/src/locales/pt/translation.json
+++ b/src/locales/pt/translation.json
@@ -1257,7 +1257,10 @@
"meetingHotkey": {
"title": "Atalho modo reunião",
"description": "Iniciar modo reunião e posicionar o painel ao lado da tela",
- "clear": "Remover atalho"
+ "clear": "Remover atalho",
+ "layoutLabel": "Ao acionar pelo atalho, abrir em:",
+ "layoutFullWidth": "Largura total",
+ "layoutSidePanel": "Painel lateral"
},
"microphone": {
"description": "Selecione qual dispositivo de entrada usar para ditado",
@@ -1842,6 +1845,9 @@
"comingSoon": "Em breve",
"back": "Voltar"
},
+ "meetingPill": {
+ "returnToNote": "Voltar à gravação"
+ },
"context": {
"moveToFolder": "Mover para pasta",
"delete": "Excluir",
diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.json
index 32df43126..a791fee6f 100644
--- a/src/locales/ru/translation.json
+++ b/src/locales/ru/translation.json
@@ -1285,7 +1285,10 @@
"meetingHotkey": {
"title": "Горячая клавиша режима встречи",
"description": "Запустить режим встречи и закрепить панель сбоку экрана",
- "clear": "Удалить горячую клавишу"
+ "clear": "Удалить горячую клавишу",
+ "layoutLabel": "При запуске горячей клавишей открывать в:",
+ "layoutFullWidth": "Полная ширина",
+ "layoutSidePanel": "Боковая панель"
},
"microphone": {
"description": "Выберите устройство ввода для диктовки",
@@ -1842,6 +1845,9 @@
"comingSoon": "Скоро",
"back": "Назад"
},
+ "meetingPill": {
+ "returnToNote": "Вернуться к записи"
+ },
"context": {
"moveToFolder": "Переместить в папку",
"delete": "Удалить",
diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.json
index a7a099004..55a9f276d 100644
--- a/src/locales/zh-CN/translation.json
+++ b/src/locales/zh-CN/translation.json
@@ -1280,7 +1280,10 @@
"meetingHotkey": {
"title": "会议模式快捷键",
"description": "启动会议模式并将面板固定到屏幕侧边",
- "clear": "移除快捷键"
+ "clear": "移除快捷键",
+ "layoutLabel": "通过快捷键触发时,打开方式:",
+ "layoutFullWidth": "全宽",
+ "layoutSidePanel": "侧边栏"
},
"microphone": {
"description": "选择用于听写的输入设备",
@@ -1837,6 +1840,9 @@
"comingSoon": "即将推出",
"back": "返回"
},
+ "meetingPill": {
+ "returnToNote": "返回到录音"
+ },
"context": {
"moveToFolder": "移动到文件夹",
"delete": "删除",
diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.json
index 276d8b776..44b46cac3 100644
--- a/src/locales/zh-TW/translation.json
+++ b/src/locales/zh-TW/translation.json
@@ -1280,7 +1280,10 @@
"meetingHotkey": {
"title": "會議模式快捷鍵",
"description": "啟動會議模式並將面板固定到螢幕側邊",
- "clear": "移除快捷鍵"
+ "clear": "移除快捷鍵",
+ "layoutLabel": "透過快捷鍵觸發時,開啟方式:",
+ "layoutFullWidth": "全寬",
+ "layoutSidePanel": "側邊欄"
},
"microphone": {
"description": "選擇用於語音輸入的輸入裝置",
@@ -1837,6 +1840,9 @@
"comingSoon": "即將推出",
"back": "返回"
},
+ "meetingPill": {
+ "returnToNote": "返回到錄音"
+ },
"context": {
"moveToFolder": "移動到資料夾",
"delete": "刪除",
diff --git a/src/services/NotesService.ts b/src/services/NotesService.ts
index e2c214a97..eda977db5 100644
--- a/src/services/NotesService.ts
+++ b/src/services/NotesService.ts
@@ -10,6 +10,9 @@ interface NoteInput {
source_file?: string | null;
audio_duration_seconds?: number | null;
participants?: string | null;
+ calendar_event_id?: string | null;
+ diarization_enabled?: number | null;
+ expected_speaker_count?: number | null;
transcript?: string | null;
enhanced_at_content_hash?: string | null;
folder_id?: string | null;
@@ -30,6 +33,10 @@ interface CloudNote {
folder_id: string | null;
transcript: string | null;
enhanced_at_content_hash: string | null;
+ participants: string | null;
+ calendar_event_id: string | null;
+ diarization_enabled: number | null;
+ expected_speaker_count: number | null;
deleted_at: string | null;
created_at: string;
updated_at: string;
diff --git a/src/services/SyncService.ts b/src/services/SyncService.ts
index 195783f52..7cfcd224e 100644
--- a/src/services/SyncService.ts
+++ b/src/services/SyncService.ts
@@ -108,6 +108,10 @@ class SyncService {
source_file: note.source_file,
audio_duration_seconds: note.audio_duration_seconds,
transcript: note.transcript,
+ participants: note.participants,
+ calendar_event_id: note.calendar_event_id,
+ diarization_enabled: note.diarization_enabled,
+ expected_speaker_count: note.expected_speaker_count,
folder_id: cloudFolderId,
updated_at: note.updated_at,
});
@@ -123,6 +127,10 @@ class SyncService {
source_file: note.source_file,
audio_duration_seconds: note.audio_duration_seconds,
transcript: note.transcript,
+ participants: note.participants,
+ calendar_event_id: note.calendar_event_id,
+ diarization_enabled: note.diarization_enabled,
+ expected_speaker_count: note.expected_speaker_count,
folder_id: cloudFolderId,
created_at: note.created_at,
updated_at: note.updated_at,
diff --git a/src/stores/meetingRecordingStore.ts b/src/stores/meetingRecordingStore.ts
new file mode 100644
index 000000000..ca07dc2d6
--- /dev/null
+++ b/src/stores/meetingRecordingStore.ts
@@ -0,0 +1,1239 @@
+import { create } from "zustand";
+import { getSettings, selectResolvedMeetingTranscription } from "./settingsStore";
+import { useStreamingProvidersStore } from "./streamingProvidersStore";
+import { isBuiltInMicrophone } from "../utils/audioDeviceUtils";
+import type { SystemAudioAccessResult, SystemAudioStrategy } from "../types/electron";
+import {
+ DEFAULT_SYSTEM_AUDIO_ACCESS,
+ getDisplayCaptureModeForStrategy,
+ getFallbackSystemAudioAccess,
+ isRendererSystemAudioStrategy,
+} from "../utils/systemAudioAccess";
+import {
+ DEFAULT_EXPECTED_SPEAKER_COUNT,
+ MAX_SPEAKER_COUNT,
+} from "../constants/speakerDetection.json";
+import logger from "../utils/logger";
+import {
+ lockTranscriptSpeaker,
+ normalizeTranscriptSegment,
+ type TranscriptSpeakerLockSource,
+ type TranscriptSpeakerStatus,
+} from "../utils/transcriptSpeakerState";
+
+export interface TranscriptSegment {
+ id: string;
+ text: string;
+ source: "mic" | "system";
+ timestamp?: number;
+ speaker?: string;
+ speakerName?: string;
+ speakerIsPlaceholder?: boolean;
+ suggestedName?: string;
+ suggestedProfileId?: number;
+ speakerStatus?: TranscriptSpeakerStatus;
+ speakerLocked?: boolean;
+ speakerLockSource?: TranscriptSpeakerLockSource;
+}
+
+export const SIDE_PANEL_BREAKPOINT_PX = 1024;
+
+interface SpeakerIdentification {
+ speakerId: string;
+ displayName?: string | null;
+ startTime: number;
+ endTime: number;
+}
+
+interface RecentSystemSpeaker {
+ speakerId: string;
+ speakerName: string | null;
+ speakerIsPlaceholder: boolean;
+ updatedAt: number;
+}
+
+interface MeetingRecordingState {
+ isRecording: boolean;
+ isTranscribing: boolean;
+ recordingNoteId: number | null;
+ recordingNoteTitle: string | null;
+ recordingFolderId: number | null;
+ segments: TranscriptSegment[];
+ transcript: string;
+ micPartial: string;
+ systemPartial: string;
+ systemPartialSpeakerId: string | null;
+ systemPartialSpeakerName: string | null;
+ diarizationSessionId: string | null;
+ sessionDiarizationEnabled: boolean;
+ sessionExpectedCount: number;
+ userTouchedStepper: boolean;
+ error: string | null;
+ currentMicLevel: number;
+ windowWidth: number;
+}
+
+const MEETING_AUDIO_BUFFER_SIZE = 800;
+const MEETING_STOP_FLUSH_TIMEOUT_MS = 50;
+const MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS = {
+ echoCancellation: false,
+ noiseSuppression: false,
+ autoGainControl: false,
+} as const;
+
+const SPEAKER_IDENTIFICATION_RETENTION_MS = 30_000;
+const SYSTEM_SPEAKER_CARRY_FORWARD_MS = 8_000;
+
+const buildTranscriptText = (segments: TranscriptSegment[]) =>
+ segments
+ .map((segment) => segment.text)
+ .join(" ")
+ .trim();
+
+const getSpeakerNumericIndex = (speakerId?: string): number | null => {
+ if (!speakerId) return null;
+ const match = speakerId.match(/speaker_(\d+)/);
+ return match ? Number(match[1]) : null;
+};
+
+const isSegmentWithinIdentificationWindow = (
+ segment: TranscriptSegment,
+ identification: SpeakerIdentification
+) => {
+ if (segment.source !== "system" || segment.timestamp == null) return false;
+ return (
+ segment.timestamp >= identification.startTime && segment.timestamp <= identification.endTime
+ );
+};
+
+const getMeetingTranscriptionOptions = () => {
+ const state = getSettings();
+ const resolved = selectResolvedMeetingTranscription(state);
+
+ if (resolved.useLocalWhisper) {
+ return {
+ provider: "local" as const,
+ localProvider: resolved.localTranscriptionProvider,
+ localModel:
+ resolved.localTranscriptionProvider === "nvidia"
+ ? resolved.parakeetModel || "parakeet-tdt-0.6b-v3"
+ : resolved.whisperModel || "base",
+ };
+ }
+
+ const catalog = useStreamingProvidersStore.getState().providers;
+ const provider =
+ catalog?.find((p) => p.id === resolved.cloudTranscriptionProvider) ?? catalog?.[0];
+ const byokKeyAvailable = provider?.id === "openai" ? !!state.openaiApiKey : true;
+ const mode =
+ resolved.cloudTranscriptionMode === "byok" && byokKeyAvailable ? "byok" : "openwhispr";
+ if (!provider) {
+ logger.debug(
+ "Streaming providers catalog not loaded, falling back to OpenAI default",
+ {},
+ "meeting"
+ );
+ return { provider: "openai-realtime" as const, model: "gpt-4o-mini-transcribe", mode };
+ }
+ const model =
+ provider.models.find((m) => m.id === resolved.cloudTranscriptionModel)?.id ??
+ provider.models.find((m) => m.default)?.id ??
+ provider.models[0]?.id;
+ return { provider: `${provider.id}-realtime` as const, model, mode };
+};
+
+const stopMediaStream = (stream: MediaStream | null) => {
+ try {
+ stream?.getTracks().forEach((track) => track.stop());
+ } catch {}
+};
+
+const getDisplayCaptureOptions = (mode: "loopback" | "portal") => {
+ if (mode === "loopback") {
+ return { video: true, audio: true };
+ }
+
+ return {
+ video: true,
+ audio: true,
+ systemAudio: "include",
+ windowAudio: "system",
+ selfBrowserSurface: "exclude",
+ } as DisplayMediaStreamOptions & {
+ systemAudio?: "include";
+ windowAudio?: "system";
+ selfBrowserSurface?: "exclude";
+ };
+};
+
+const requestSystemAudioDisplayStream = async (mode: "loopback" | "portal") => {
+ try {
+ const stream = await navigator.mediaDevices.getDisplayMedia(getDisplayCaptureOptions(mode));
+ const audioTrack = stream.getAudioTracks()[0];
+
+ if (!audioTrack) {
+ stopMediaStream(stream);
+ return { stream: null, error: new Error("No system-audio track was returned.") };
+ }
+
+ stream.getVideoTracks().forEach((track) => track.stop());
+ return { stream, error: null };
+ } catch (error) {
+ return { stream: null, error: error as Error };
+ }
+};
+
+const prepareMeetingSystemAudioCapture = (initialSystemAudioAccess: SystemAudioAccessResult) => {
+ const initialSystemAudioStrategy = initialSystemAudioAccess.strategy ?? "unsupported";
+ const initialDisplayCaptureStrategy = isRendererSystemAudioStrategy(initialSystemAudioStrategy)
+ ? initialSystemAudioStrategy
+ : null;
+ const systemCapturePromise = initialDisplayCaptureStrategy
+ ? requestSystemAudioDisplayStream(
+ getDisplayCaptureModeForStrategy(initialDisplayCaptureStrategy)
+ )
+ : Promise.resolve({ stream: null, error: null });
+
+ return {
+ initialSystemAudioStrategy,
+ initialDisplayCaptureStrategy,
+ systemCapturePromise,
+ };
+};
+
+const ensureRendererSystemAudioCapture = async ({
+ initialDisplayCaptureStrategy,
+ systemAudioStrategy,
+ systemCaptureResult,
+}: {
+ initialDisplayCaptureStrategy: "loopback" | "browser-portal" | null;
+ systemAudioStrategy: SystemAudioStrategy;
+ systemCaptureResult: { stream: MediaStream | null; error: Error | null };
+}) => {
+ if (
+ systemCaptureResult.stream ||
+ systemCaptureResult.error ||
+ !isRendererSystemAudioStrategy(systemAudioStrategy) ||
+ initialDisplayCaptureStrategy
+ ) {
+ return systemCaptureResult;
+ }
+
+ return requestSystemAudioDisplayStream(getDisplayCaptureModeForStrategy(systemAudioStrategy));
+};
+
+const getMeetingWorkletBlobUrl = (() => {
+ let blobUrl: string | null = null;
+
+ return () => {
+ if (blobUrl) return blobUrl;
+
+ const code = `
+const BUFFER_SIZE = ${MEETING_AUDIO_BUFFER_SIZE};
+class MeetingPCMProcessor extends AudioWorkletProcessor {
+ constructor() {
+ super();
+ this._buffer = new Int16Array(BUFFER_SIZE);
+ this._offset = 0;
+ this._stopped = false;
+ this.port.onmessage = (event) => {
+ if (event.data === "stop") {
+ if (this._offset > 0) {
+ const partial = this._buffer.slice(0, this._offset);
+ this.port.postMessage(partial.buffer, [partial.buffer]);
+ this._buffer = new Int16Array(BUFFER_SIZE);
+ this._offset = 0;
+ }
+ this._stopped = true;
+ }
+ };
+ }
+ process(inputs) {
+ if (this._stopped) return false;
+ const input = inputs[0]?.[0];
+ if (!input) return true;
+ for (let i = 0; i < input.length; i++) {
+ const s = Math.max(-1, Math.min(1, input[i]));
+ this._buffer[this._offset++] = s < 0 ? s * 0x8000 : s * 0x7fff;
+ if (this._offset >= BUFFER_SIZE) {
+ this.port.postMessage(this._buffer.buffer, [this._buffer.buffer]);
+ this._buffer = new Int16Array(BUFFER_SIZE);
+ this._offset = 0;
+ }
+ }
+ return true;
+ }
+}
+registerProcessor("meeting-pcm-processor", MeetingPCMProcessor);
+`;
+
+ blobUrl = URL.createObjectURL(new Blob([code], { type: "application/javascript" }));
+ return blobUrl;
+ };
+})();
+
+export const primeMeetingWorklet = () => {
+ getMeetingWorkletBlobUrl();
+};
+
+const getMeetingMicConstraints = async (): Promise<MediaStreamConstraints> => {
+ const { preferBuiltInMic, selectedMicDeviceId } = getSettings();
+
+ if (preferBuiltInMic) {
+ try {
+ const devices = await navigator.mediaDevices.enumerateDevices();
+ const builtInMic = devices.find(
+ (device) => device.kind === "audioinput" && isBuiltInMicrophone(device.label)
+ );
+
+ if (builtInMic?.deviceId) {
+ return {
+ audio: {
+ deviceId: { exact: builtInMic.deviceId },
+ ...MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS,
+ },
+ };
+ }
+ } catch (err) {
+ logger.debug(
+ "Failed to enumerate microphones for meeting transcription",
+ { error: (err as Error).message },
+ "meeting"
+ );
+ }
+ }
+
+ if (selectedMicDeviceId && selectedMicDeviceId !== "default") {
+ return {
+ audio: {
+ deviceId: { exact: selectedMicDeviceId },
+ ...MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS,
+ },
+ };
+ }
+
+ return { audio: MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS };
+};
+
+const createAudioPipeline = async ({
+ stream,
+ context,
+ onChunk,
+}: {
+ stream: MediaStream;
+ context: AudioContext;
+ onChunk: (chunk: ArrayBuffer) => void;
+}) => {
+ if (context.state === "suspended") {
+ await context.resume();
+ }
+
+ await context.audioWorklet.addModule(getMeetingWorkletBlobUrl());
+
+ const source = context.createMediaStreamSource(stream);
+ const processor = new AudioWorkletNode(context, "meeting-pcm-processor");
+ const silentGain = context.createGain();
+ silentGain.gain.value = 0;
+
+ processor.port.onmessage = (event) => {
+ const chunk = event.data;
+ if (!(chunk instanceof ArrayBuffer)) return;
+ onChunk(chunk);
+ };
+
+ source.connect(processor);
+ processor.connect(silentGain);
+ silentGain.connect(context.destination);
+
+ return { source, processor };
+};
+
+// Detach the AudioContext from hardware output — when BT headphones switch to
+// HFP, the default-output context can stall on the sample-rate mismatch.
+const detachFromOutputDevice = async (ctx: AudioContext) => {
+ if ("setSinkId" in ctx) {
+ try {
+ await (ctx as unknown as { setSinkId: (cfg: { type: string }) => Promise<void> }).setSinkId({
+ type: "none",
+ });
+ } catch {}
+ }
+};
+
+const flushAndDisconnectProcessor = async (processor: AudioWorkletNode | null) => {
+ if (!processor) return;
+
+ try {
+ processor.port.postMessage("stop");
+ await new Promise((resolve) => {
+ window.setTimeout(resolve, MEETING_STOP_FLUSH_TIMEOUT_MS);
+ });
+ } catch {}
+
+ processor.port.onmessage = null;
+ processor.disconnect();
+};
+
+let segmentCounter = 0;
+
+// Pipeline lives in module scope — not on React refs — so it survives
+// view changes and re-mounts of the consumer view.
+let micContext: AudioContext | null = null;
+let micSource: MediaStreamAudioSourceNode | null = null;
+let micProcessor: AudioWorkletNode | null = null;
+let micStream: MediaStream | null = null;
+let micAnalyser: AnalyserNode | null = null;
+let systemContext: AudioContext | null = null;
+let systemSource: MediaStreamAudioSourceNode | null = null;
+let systemProcessor: AudioWorkletNode | null = null;
+let systemStream: MediaStream | null = null;
+let isRecordingFlag = false;
+let isStartingFlag = false;
+let isPrepared = false;
+let segmentsRefValue: TranscriptSegment[] = [];
+let preparePromise: Promise<void> | null = null;
+let ipcCleanups: Array<() => void> = [];
+let speakerIdentifications: SpeakerIdentification[] = [];
+let nextPlaceholderSpeakerIndex = 0;
+let systemPartialSpeakerIdValue: string | null = null;
+let recentSystemSpeaker: RecentSystemSpeaker | null = null;
+let speakerLocks: Map<string, string> = new Map();
+let pushConfigTimeout: ReturnType<typeof setTimeout> | null = null;
+
+export const useMeetingRecordingStore = create<MeetingRecordingState>()(() => ({
+ isRecording: false,
+ isTranscribing: false,
+ recordingNoteId: null,
+ recordingNoteTitle: null,
+ recordingFolderId: null,
+ segments: [],
+ transcript: "",
+ micPartial: "",
+ systemPartial: "",
+ systemPartialSpeakerId: null,
+ systemPartialSpeakerName: null,
+ diarizationSessionId: null,
+ sessionDiarizationEnabled:
+ (getSettings() as { speakerDiarizationEnabled?: boolean }).speakerDiarizationEnabled ?? true,
+ sessionExpectedCount: DEFAULT_EXPECTED_SPEAKER_COUNT,
+ userTouchedStepper: false,
+ error: null,
+ currentMicLevel: 0,
+ windowWidth: typeof window !== "undefined" ? window.innerWidth : SIDE_PANEL_BREAKPOINT_PX,
+}));
+
+export const getMicAnalyser = (): AnalyserNode | null => micAnalyser;
+
+function pushConfig(enabled: boolean, expectedCount: number) {
+ if (pushConfigTimeout) clearTimeout(pushConfigTimeout);
+ pushConfigTimeout = setTimeout(() => {
+ (
+ window.electronAPI as unknown as {
+ setMeetingSessionSpeakerConfig?: (config: {
+ enabled: boolean;
+ expectedCount: number;
+ }) => void;
+ }
+ )?.setMeetingSessionSpeakerConfig?.({ enabled, expectedCount });
+ }, 150);
+}
+
+export function setSessionDiarizationEnabled(enabled: boolean): void {
+ useMeetingRecordingStore.setState({ sessionDiarizationEnabled: enabled });
+ pushConfig(enabled, useMeetingRecordingStore.getState().sessionExpectedCount);
+ const noteId = useMeetingRecordingStore.getState().recordingNoteId;
+ if (noteId != null) {
+ window.electronAPI?.updateNote?.(noteId, { diarization_enabled: enabled ? 1 : 0 });
+ }
+}
+
+export function setSessionExpectedCount(count: number): void {
+ const clamped = Math.max(1, Math.min(MAX_SPEAKER_COUNT, count));
+ useMeetingRecordingStore.setState({
+ sessionExpectedCount: clamped,
+ userTouchedStepper: true,
+ });
+ pushConfig(useMeetingRecordingStore.getState().sessionDiarizationEnabled, clamped);
+ const noteId = useMeetingRecordingStore.getState().recordingNoteId;
+ if (noteId != null) {
+ window.electronAPI?.updateNote?.(noteId, { expected_speaker_count: clamped });
+ }
+}
+
+function setSystemPartialSpeakerIdentity(speakerId: string | null, speakerName: string | null) {
+ systemPartialSpeakerIdValue = speakerId;
+ useMeetingRecordingStore.setState({
+ systemPartialSpeakerId: speakerId,
+ systemPartialSpeakerName: speakerName,
+ });
+}
+
+function applySpeakerIdentification(
+ segment: TranscriptSegment,
+ identification: SpeakerIdentification
+): TranscriptSegment {
+ if (
+ segment.source !== "system" ||
+ !isSegmentWithinIdentificationWindow(segment, identification) ||
+ (segment.speaker && !segment.speakerIsPlaceholder && segment.speakerStatus !== "provisional") ||
+ segment.speakerLocked
+ ) {
+ return segment;
+ }
+
+ return normalizeTranscriptSegment({
+ ...segment,
+ speaker: identification.speakerId,
+ speakerName: identification.displayName ?? segment.speakerName,
+ speakerIsPlaceholder: false,
+ speakerStatus: "confirmed",
+ });
+}
+
+function rememberSystemSpeaker(
+ speakerId: string | null,
+ speakerName: string | null,
+ speakerIsPlaceholder: boolean,
+ updatedAt = Date.now()
+) {
+ recentSystemSpeaker = speakerId
+ ? {
+ speakerId,
+ speakerName,
+ speakerIsPlaceholder,
+ updatedAt,
+ }
+ : null;
+}
+
+function getRecentSystemSpeaker(nowMs: number) {
+ if (!recentSystemSpeaker) return null;
+ return nowMs - recentSystemSpeaker.updatedAt <= SYSTEM_SPEAKER_CARRY_FORWARD_MS
+ ? recentSystemSpeaker
+ : null;
+}
+
+function reserveSpeakerIndex(speakerId?: string) {
+ const idx = getSpeakerNumericIndex(speakerId);
+ if (idx == null) return;
+ nextPlaceholderSpeakerIndex = Math.max(nextPlaceholderSpeakerIndex, idx + 1);
+}
+
+function assignProvisionalSpeaker(segment: TranscriptSegment): TranscriptSegment {
+ if (segment.source !== "system" || segment.speaker) return segment;
+
+ const nowMs = segment.timestamp ?? Date.now();
+ if (systemPartialSpeakerIdValue) {
+ reserveSpeakerIndex(systemPartialSpeakerIdValue);
+ return normalizeTranscriptSegment({
+ ...segment,
+ speaker: systemPartialSpeakerIdValue,
+ speakerIsPlaceholder: true,
+ speakerStatus: "provisional",
+ });
+ }
+
+ const recent = getRecentSystemSpeaker(nowMs);
+ if (recent?.speakerId) {
+ reserveSpeakerIndex(recent.speakerId);
+ return normalizeTranscriptSegment({
+ ...segment,
+ speaker: recent.speakerId,
+ speakerName: recent.speakerName ?? undefined,
+ speakerIsPlaceholder: recent.speakerIsPlaceholder,
+ speakerStatus: "provisional",
+ });
+ }
+
+ const previousSystemSegment = [...segmentsRefValue]
+ .reverse()
+ .find(
+ (candidate) =>
+ candidate.source === "system" &&
+ candidate.speaker &&
+ candidate.timestamp != null &&
+ nowMs - candidate.timestamp <= SYSTEM_SPEAKER_CARRY_FORWARD_MS
+ );
+
+ if (previousSystemSegment?.speaker) {
+ reserveSpeakerIndex(previousSystemSegment.speaker);
+ return normalizeTranscriptSegment({
+ ...segment,
+ speaker: previousSystemSegment.speaker,
+ speakerName: previousSystemSegment.speakerName,
+ speakerIsPlaceholder: true,
+ speakerStatus: "provisional",
+ });
+ }
+
+ const speakerId = `speaker_${nextPlaceholderSpeakerIndex}`;
+ nextPlaceholderSpeakerIndex += 1;
+
+ return normalizeTranscriptSegment({
+ ...segment,
+ speaker: speakerId,
+ speakerIsPlaceholder: true,
+ speakerStatus: "provisional",
+ });
+}
+
+async function cleanup(): Promise<void> {
+ await flushAndDisconnectProcessor(micProcessor);
+ micProcessor = null;
+
+ micSource?.disconnect();
+ micSource = null;
+
+ micAnalyser?.disconnect();
+ micAnalyser = null;
+
+ try {
+ micStream?.getTracks().forEach((t) => t.stop());
+ } catch {}
+ micStream = null;
+
+ try {
+ await micContext?.close();
+ } catch {}
+ micContext = null;
+
+ await flushAndDisconnectProcessor(systemProcessor);
+ systemProcessor = null;
+
+ systemSource?.disconnect();
+ systemSource = null;
+
+ stopMediaStream(systemStream);
+ systemStream = null;
+
+ try {
+ await systemContext?.close();
+ } catch {}
+ systemContext = null;
+
+ ipcCleanups.forEach((fn) => fn());
+ ipcCleanups = [];
+ isPrepared = false;
+ isRecordingFlag = false;
+ isStartingFlag = false;
+}
+
+export async function prepareTranscription(): Promise<void> {
+ if (isPrepared || isRecordingFlag || isStartingFlag) return;
+ if (preparePromise) return preparePromise;
+
+ logger.info("Meeting transcription preparing (pre-warming WebSockets)...", {}, "meeting");
+
+ const promise = (async () => {
+ try {
+ const result = await window.electronAPI?.meetingTranscriptionPrepare?.(
+ getMeetingTranscriptionOptions()
+ );
+
+ if (result?.success) {
+ isPrepared = true;
+ logger.info(
+ "Meeting transcription prepared",
+ { alreadyPrepared: result.alreadyPrepared },
+ "meeting"
+ );
+ } else {
+ logger.error("Meeting transcription prepare failed", { error: result?.error }, "meeting");
+ }
+ } catch (err) {
+ logger.error(
+ "Meeting transcription prepare error",
+ { error: (err as Error).message },
+ "meeting"
+ );
+ } finally {
+ preparePromise = null;
+ }
+ })();
+
+ preparePromise = promise;
+ await promise;
+}
+
+export interface StartRecordingArgs {
+ noteId: number | null;
+ noteTitle: string | null;
+ folderId: number | null;
+ seedSegments?: TranscriptSegment[];
+ diarizationEnabled?: boolean | null;
+ expectedCount?: number | null;
+}
+
+export async function startRecording(args: StartRecordingArgs): Promise<void> {
+ if (isRecordingFlag || isStartingFlag) return;
+ isStartingFlag = true;
+
+ const initialEnabled =
+ args.diarizationEnabled ??
+ (getSettings() as { speakerDiarizationEnabled?: boolean }).speakerDiarizationEnabled ??
+ true;
+ const initialCount = Math.max(
+ 1,
+ Math.min(MAX_SPEAKER_COUNT, args.expectedCount ?? DEFAULT_EXPECTED_SPEAKER_COUNT)
+ );
+
+ const systemAudioAccessPromise =
+ window.electronAPI?.checkSystemAudioAccess?.() ?? Promise.resolve(DEFAULT_SYSTEM_AUDIO_ACCESS);
+
+ logger.info("Meeting transcription starting...", {}, "meeting");
+ const seed = args.seedSegments ?? [];
+ const locks = new Map<string, string>();
+ let maxSpeakerIndex = -1;
+ for (const s of seed) {
+ const idx = getSpeakerNumericIndex(s.speaker);
+ if (idx != null && idx > maxSpeakerIndex) maxSpeakerIndex = idx;
+ if (s.speakerLocked && s.speaker && s.speakerName) {
+ locks.set(s.speaker, s.speakerName);
+ }
+ }
+
+ segmentsRefValue = seed;
+ speakerIdentifications = [];
+ nextPlaceholderSpeakerIndex = maxSpeakerIndex + 1;
+ recentSystemSpeaker = null;
+ speakerLocks = locks;
+ systemPartialSpeakerIdValue = null;
+
+ useMeetingRecordingStore.setState({
+ isRecording: true,
+ isTranscribing: true,
+ recordingNoteId: args.noteId,
+ recordingNoteTitle: args.noteTitle,
+ recordingFolderId: args.folderId,
+ sessionDiarizationEnabled: initialEnabled,
+ sessionExpectedCount: initialCount,
+ userTouchedStepper: args.expectedCount != null,
+ segments: seed,
+ transcript: buildTranscriptText(seed),
+ micPartial: "",
+ systemPartial: "",
+ systemPartialSpeakerId: null,
+ systemPartialSpeakerName: null,
+ diarizationSessionId: null,
+ error: null,
+ });
+
+ isRecordingFlag = true;
+
+ if (preparePromise) {
+ logger.debug("Waiting for in-flight prepare to finish...", {}, "meeting");
+ await preparePromise;
+ }
+
+ try {
+ const startTime = performance.now();
+ const initialSystemAudioAccess =
+ (await systemAudioAccessPromise) ?? getFallbackSystemAudioAccess();
+ const { initialSystemAudioStrategy, initialDisplayCaptureStrategy, systemCapturePromise } =
+ prepareMeetingSystemAudioCapture(initialSystemAudioAccess);
+
+ const [startResult, micResult, initialSystemCaptureResult] = await Promise.all([
+ window.electronAPI?.meetingTranscriptionStart?.({
+ ...getMeetingTranscriptionOptions(),
+ noteId: args.noteId ?? null,
+ }),
+ getMeetingMicConstraints().then(async (constraints) => {
+ try {
+ return await navigator.mediaDevices.getUserMedia(constraints);
+ } catch (err) {
+ const hasExactDevice =
+ typeof constraints.audio === "object" &&
+ constraints.audio !== null &&
+ "deviceId" in constraints.audio;
+ if (hasExactDevice) {
+ try {
+ const fallbackStream = await navigator.mediaDevices.getUserMedia({
+ audio: MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS,
+ });
+ logger.info(
+ "Meeting mic capture recovered using default device",
+ { error: (err as Error).message },
+ "meeting"
+ );
+ return fallbackStream;
+ } catch (fallbackErr) {
+ logger.error(
+ "Meeting mic capture failed, continuing with system audio only",
+ { error: (fallbackErr as Error).message },
+ "meeting"
+ );
+ return null;
+ }
+ }
+ logger.error(
+ "Meeting mic capture failed, continuing with system audio only",
+ { error: (err as Error).message, constraints },
+ "meeting"
+ );
+ return null;
+ }
+ }),
+ systemCapturePromise,
+ ]);
+ let systemCaptureResult = initialSystemCaptureResult;
+
+ const streamsMs = performance.now() - startTime;
+ if (!isRecordingFlag) {
+ logger.info("Meeting transcription aborted during setup (stop called)", {}, "meeting");
+ stopMediaStream(micResult);
+ stopMediaStream(systemCaptureResult.stream);
+ isStartingFlag = false;
+ return;
+ }
+
+ if (!startResult?.success) {
+ logger.error(
+ "Meeting transcription IPC start failed",
+ { error: startResult?.error },
+ "meeting"
+ );
+ useMeetingRecordingStore.setState({
+ error: startResult?.error || "Failed to start meeting transcription",
+ isRecording: false,
+ isTranscribing: false,
+ });
+ stopMediaStream(micResult);
+ stopMediaStream(systemCaptureResult.stream);
+ isRecordingFlag = false;
+ isStartingFlag = false;
+ return;
+ }
+
+ const systemAudioMode = startResult.systemAudioMode || initialSystemAudioAccess.mode;
+ const systemAudioStrategy = startResult.systemAudioStrategy || initialSystemAudioStrategy;
+ systemCaptureResult = await ensureRendererSystemAudioCapture({
+ initialDisplayCaptureStrategy,
+ systemAudioStrategy,
+ systemCaptureResult,
+ });
+ const systemAudioHandledInMain =
+ systemAudioMode !== "unsupported" && !isRendererSystemAudioStrategy(systemAudioStrategy);
+ const systemCaptureError = systemAudioHandledInMain ? null : systemCaptureResult.error;
+
+ if (!micResult && (systemAudioHandledInMain || systemCaptureResult.stream)) {
+ useMeetingRecordingStore.setState({
+ error: "Microphone capture failed. Continuing with system audio only.",
+ });
+ }
+
+ if (!micResult && !systemCaptureResult.stream && !systemAudioHandledInMain) {
+ logger.error("Meeting transcription has no available audio source", {}, "meeting");
+ useMeetingRecordingStore.setState({
+ error:
+ systemAudioMode === "unsupported"
+ ? "No microphone is available and system audio capture is unsupported on this device."
+ : systemCaptureError?.message ||
+ "No microphone is available and system audio capture could not be started.",
+ isRecording: false,
+ isTranscribing: false,
+ });
+ await window.electronAPI?.meetingTranscriptionStop?.();
+ isRecordingFlag = false;
+ isStartingFlag = false;
+ return;
+ }
+
+ const segmentCleanup = window.electronAPI?.onMeetingTranscriptionSegment?.(
+ (data: {
+ text: string;
+ source: "mic" | "system";
+ type: "partial" | "final" | "retract";
+ timestamp?: number;
+ }) => {
+ if (data.type === "retract") {
+ const next = useMeetingRecordingStore
+ .getState()
+ .segments.filter(
+ (seg) =>
+ !(
+ seg.source === data.source &&
+ seg.timestamp === data.timestamp &&
+ seg.text === data.text
+ )
+ );
+ segmentsRefValue = next;
+ useMeetingRecordingStore.setState({
+ segments: next,
+ transcript: buildTranscriptText(next),
+ });
+ return;
+ }
+
+ if (data.type === "partial") {
+ if (data.source === "mic") {
+ useMeetingRecordingStore.setState({ micPartial: data.text });
+ } else {
+ useMeetingRecordingStore.setState({ systemPartial: data.text });
+ if (!systemPartialSpeakerIdValue) {
+ const speakerId = `speaker_${nextPlaceholderSpeakerIndex}`;
+ nextPlaceholderSpeakerIndex += 1;
+ setSystemPartialSpeakerIdentity(speakerId, null);
+ }
+ }
+ return;
+ }
+
+ let rawSegment: TranscriptSegment = normalizeTranscriptSegment({
+ id: `seg-${++segmentCounter}`,
+ text: data.text,
+ source: data.source,
+ timestamp: data.timestamp,
+ });
+
+ for (let i = speakerIdentifications.length - 1; i >= 0; i -= 1) {
+ rawSegment = applySpeakerIdentification(rawSegment, speakerIdentifications[i]);
+ }
+
+ const provisional = assignProvisionalSpeaker(rawSegment);
+ reserveSpeakerIndex(provisional.speaker);
+ const lockedName = provisional.speaker ? speakerLocks.get(provisional.speaker) : undefined;
+ const seg = lockedName
+ ? lockTranscriptSpeaker(provisional, {
+ speakerName: lockedName,
+ speakerIsPlaceholder: false,
+ suggestedName: undefined,
+ suggestedProfileId: undefined,
+ })
+ : provisional;
+
+ const prev = useMeetingRecordingStore.getState().segments;
+ const ts = seg.timestamp ?? Infinity;
+ let i = prev.length;
+ while (i > 0 && (prev[i - 1].timestamp ?? 0) > ts) i--;
+ const next =
+ i === prev.length ? [...prev, seg] : [...prev.slice(0, i), seg, ...prev.slice(i)];
+ segmentsRefValue = next;
+
+ const partialPatch = data.source === "mic" ? { micPartial: "" } : { systemPartial: "" };
+ useMeetingRecordingStore.setState({
+ segments: next,
+ transcript: buildTranscriptText(next),
+ ...partialPatch,
+ });
+ if (data.source === "system" && seg.speaker) {
+ rememberSystemSpeaker(
+ seg.speaker,
+ seg.speakerName ?? null,
+ !!seg.speakerIsPlaceholder,
+ seg.timestamp ?? Date.now()
+ );
+ }
+ if (data.source === "system") {
+ setSystemPartialSpeakerIdentity(null, null);
+ }
+ }
+ );
+ if (segmentCleanup) ipcCleanups.push(segmentCleanup);
+
+ const speakerCleanup = window.electronAPI?.onMeetingSpeakerIdentified?.((data) => {
+ reserveSpeakerIndex(data.speakerId);
+ setSystemPartialSpeakerIdentity(data.speakerId, data.displayName ?? null);
+ rememberSystemSpeaker(data.speakerId, data.displayName ?? null, false, data.endTime);
+ speakerIdentifications = [
+ ...speakerIdentifications.filter(
+ (id) => id.endTime >= data.endTime - SPEAKER_IDENTIFICATION_RETENTION_MS
+ ),
+ data,
+ ];
+ const next = useMeetingRecordingStore
+ .getState()
+ .segments.map((segment) => applySpeakerIdentification(segment, data));
+ segmentsRefValue = next;
+ useMeetingRecordingStore.setState({ segments: next });
+ });
+ if (speakerCleanup) ipcCleanups.push(speakerCleanup);
+
+ const mergeCleanup = window.electronAPI?.onMeetingSpeakersMerged?.((merges) => {
+ let next = useMeetingRecordingStore.getState().segments;
+ for (const { keep, remove, displayName } of merges) {
+ next = next.map((seg) => {
+ if (seg.speaker !== remove || seg.speakerLocked) return seg;
+ return normalizeTranscriptSegment({
+ ...seg,
+ speaker: keep,
+ speakerName: displayName ?? seg.speakerName,
+ });
+ });
+ }
+ segmentsRefValue = next;
+ useMeetingRecordingStore.setState({ segments: next });
+
+ for (const { keep, remove, displayName } of merges) {
+ if (recentSystemSpeaker?.speakerId === remove) {
+ recentSystemSpeaker.speakerId = keep;
+ if (displayName) recentSystemSpeaker.speakerName = displayName;
+ }
+
+ for (const id of speakerIdentifications) {
+ if (id.speakerId === remove) id.speakerId = keep;
+ }
+
+ const lockedName = speakerLocks.get(remove);
+ if (lockedName) {
+ speakerLocks.set(keep, lockedName);
+ speakerLocks.delete(remove);
+ }
+ }
+ });
+ if (mergeCleanup) ipcCleanups.push(mergeCleanup);
+
+ const errorCleanup = window.electronAPI?.onMeetingTranscriptionError?.((err) => {
+ useMeetingRecordingStore.setState({ error: err });
+ logger.error("Meeting transcription stream error", { error: err }, "meeting");
+ });
+ if (errorCleanup) ipcCleanups.push(errorCleanup);
+
+ if (startResult.oneOnOneAttendee) {
+ const synthetic: SpeakerIdentification = {
+ speakerId: "speaker_0",
+ displayName: startResult.oneOnOneAttendee.displayName,
+ startTime: 0,
+ endTime: Number.MAX_SAFE_INTEGER,
+ };
+ reserveSpeakerIndex(synthetic.speakerId);
+ setSystemPartialSpeakerIdentity(synthetic.speakerId, synthetic.displayName);
+ rememberSystemSpeaker(synthetic.speakerId, synthetic.displayName, false, Date.now());
+ speakerIdentifications.push(synthetic);
+ }
+
+ const pendingMicChunks: ArrayBuffer[] = [];
+ const pendingSystemChunks: ArrayBuffer[] = [];
+ let socketReady = false;
+
+ let micPipelinePromise: Promise<void> | null = null;
+ if (micResult) {
+ micStream = micResult;
+ const ctx = new AudioContext({ sampleRate: 24000 });
+ await detachFromOutputDevice(ctx);
+ micContext = ctx;
+
+ micPipelinePromise = createAudioPipeline({
+ stream: micResult,
+ context: ctx,
+ onChunk: (chunk) => {
+ if (!isRecordingFlag) return;
+ if (socketReady) {
+ window.electronAPI?.meetingTranscriptionSend?.(chunk, "mic");
+ return;
+ }
+ pendingMicChunks.push(chunk.slice(0));
+ },
+ }).then(({ source, processor }) => {
+ micSource = source;
+ micProcessor = processor;
+
+ const analyser = ctx.createAnalyser();
+ analyser.fftSize = 256;
+ source.connect(analyser);
+ micAnalyser = analyser;
+
+ const micTrack = micResult.getAudioTracks()[0];
+ logger.info(
+ "Mic capture started for meeting transcription",
+ {
+ label: micTrack?.label,
+ settings: micTrack?.getSettings(),
+ },
+ "meeting"
+ );
+ });
+ }
+
+ if (micPipelinePromise) {
+ await micPipelinePromise;
+ }
+
+ if (systemCaptureResult.stream) {
+ const stream = systemCaptureResult.stream;
+ systemStream = stream;
+
+ const ctx = new AudioContext({ sampleRate: 24000 });
+ await detachFromOutputDevice(ctx);
+ systemContext = ctx;
+
+ await createAudioPipeline({
+ stream,
+ context: ctx,
+ onChunk: (chunk) => {
+ if (!isRecordingFlag) return;
+ if (socketReady) {
+ window.electronAPI?.meetingTranscriptionSend?.(chunk, "system");
+ return;
+ }
+ pendingSystemChunks.push(chunk.slice(0));
+ },
+ }).then(({ source, processor }) => {
+ systemSource = source;
+ systemProcessor = processor;
+ });
+ } else if (systemCaptureError) {
+ if (systemAudioStrategy === "browser-portal") {
+ logger.warn(
+ "Linux system audio capture failed, continuing with mic only",
+ { error: systemCaptureError.message },
+ "meeting"
+ );
+ } else if (systemAudioStrategy === "loopback") {
+ logger.warn(
+ "System audio loopback failed, continuing with mic only",
+ { error: systemCaptureError.message },
+ "meeting"
+ );
+ }
+ }
+
+ if (!isRecordingFlag) {
+ logger.info(
+ "Meeting transcription aborted during pipeline setup (stop called)",
+ {},
+ "meeting"
+ );
+ isStartingFlag = false;
+ await cleanup();
+ return;
+ }
+
+ isStartingFlag = false;
+ socketReady = true;
+
+ for (const chunk of pendingMicChunks) {
+ window.electronAPI?.meetingTranscriptionSend?.(chunk, "mic");
+ }
+ for (const chunk of pendingSystemChunks) {
+ window.electronAPI?.meetingTranscriptionSend?.(chunk, "system");
+ }
+
+ const totalMs = performance.now() - startTime;
+ logger.info(
+ "Meeting transcription started successfully",
+ {
+ systemAudioMode,
+ systemAudioStrategy,
+ bufferedChunks: pendingMicChunks.length,
+ bufferedSystemChunks: pendingSystemChunks.length,
+ streamsMs: Math.round(streamsMs),
+ totalMs: Math.round(totalMs),
+ wasPrepared: isPrepared,
+ },
+ "meeting"
+ );
+ } catch (err) {
+ logger.error(
+ "Meeting transcription setup failed",
+ { error: (err as Error).message },
+ "meeting"
+ );
+ useMeetingRecordingStore.setState({
+ error: (err as Error).message,
+ isRecording: false,
+ isTranscribing: false,
+ });
+ isRecordingFlag = false;
+ isStartingFlag = false;
+ await cleanup();
+ }
+}
+
+export interface StopRecordingResult {
+ diarizationSessionId: string | null;
+}
+
+export async function stopRecording(): Promise<StopRecordingResult> {
+ if (!isRecordingFlag) {
+ return { diarizationSessionId: null };
+ }
+
+ isRecordingFlag = false;
+ isStartingFlag = false;
+ useMeetingRecordingStore.setState({ isRecording: false, isTranscribing: false });
+
+ await cleanup();
+
+ let diarizationSessionId: string | null = null;
+ try {
+ const result = await window.electronAPI?.meetingTranscriptionStop?.();
+ if (result?.diarizationSessionId) {
+ diarizationSessionId = result.diarizationSessionId;
+ useMeetingRecordingStore.setState({ diarizationSessionId });
+ }
+ if (result?.success && result.transcript) {
+ useMeetingRecordingStore.setState({ transcript: result.transcript });
+ } else if (result?.error) {
+ useMeetingRecordingStore.setState({ error: result.error });
+ }
+ } catch (err) {
+ useMeetingRecordingStore.setState({ error: (err as Error).message });
+ logger.error("Meeting transcription stop failed", { error: (err as Error).message }, "meeting");
+ }
+
+ useMeetingRecordingStore.setState({
+ micPartial: "",
+ systemPartial: "",
+ systemPartialSpeakerId: null,
+ systemPartialSpeakerName: null,
+ currentMicLevel: 0,
+ });
+
+ logger.info("Meeting transcription stopped", {}, "meeting");
+ return { diarizationSessionId };
+}
+
+export function lockSpeaker(speakerId: string, displayName: string): void {
+ if (!speakerId || !displayName) return;
+ speakerLocks.set(speakerId, displayName);
+ const next = useMeetingRecordingStore.getState().segments.map((s) =>
+ s.speaker === speakerId
+ ? lockTranscriptSpeaker(s, {
+ speakerName: displayName,
+ speakerIsPlaceholder: false,
+ suggestedName: undefined,
+ suggestedProfileId: undefined,
+ })
+ : s
+ );
+ segmentsRefValue = next;
+ useMeetingRecordingStore.setState({ segments: next });
+ if (recentSystemSpeaker?.speakerId === speakerId) {
+ recentSystemSpeaker = {
+ ...recentSystemSpeaker,
+ speakerName: displayName,
+ speakerIsPlaceholder: false,
+ };
+ }
+ if (systemPartialSpeakerIdValue === speakerId) {
+ setSystemPartialSpeakerIdentity(speakerId, displayName);
+ }
+}
+
+export function cancelPreparedTranscription(): void {
+ window.electronAPI?.meetingTranscriptionCancel?.();
+}
+
+// Throttled resize listener — keeps layout reflows during drag from thrashing
+// React. Registered once at module load; the store outlives any view.
+if (typeof window !== "undefined") {
+ let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
+ window.addEventListener("resize", () => {
+ if (resizeTimeout) return;
+ resizeTimeout = setTimeout(() => {
+ resizeTimeout = null;
+ useMeetingRecordingStore.setState({ windowWidth: window.innerWidth });
+ }, 60);
+ });
+}
+
+export function useIsNarrowWindow(): boolean {
+ const windowWidth = useMeetingRecordingStore((s) => s.windowWidth);
+ return windowWidth < SIDE_PANEL_BREAKPOINT_PX;
+}
+
+export function useIsMeetingMode(): boolean {
+ const isRecording = useMeetingRecordingStore((s) => s.isRecording);
+ const isNarrow = useIsNarrowWindow();
+ return isRecording && isNarrow;
+}
diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.ts
index 9460d9a06..d0723ebad 100644
--- a/src/stores/settingsStore.ts
+++ b/src/stores/settingsStore.ts
@@ -477,6 +477,7 @@ export interface SettingsState
setDictationKey: (key: string) => void;
setMeetingKey: (key: string) => void;
+ setMeetingHotkeyLayoutMode: (mode: "side-panel" | "full-width") => void;
setActivationMode: (mode: "tap" | "push") => void;
setPreferBuiltInMic: (value: boolean) => void;
@@ -677,6 +678,9 @@ export const useSettingsStore = create<SettingsState>()((set, get) => ({
dictationKey: readString("dictationKey", ""),
meetingKey: readString("meetingKey", ""),
+ meetingHotkeyLayoutMode: (readString("meetingHotkeyLayoutMode", "full-width") === "side-panel"
+ ? "side-panel"
+ : "full-width") as "side-panel" | "full-width",
activationMode: (readString("activationMode", "tap") === "push" ? "push" : "tap") as
| "tap"
| "push",
@@ -1077,6 +1081,11 @@ export const useSettingsStore = create<SettingsState>()((set, get) => ({
set({ meetingKey: key });
},
+ setMeetingHotkeyLayoutMode: (mode: "side-panel" | "full-width") => {
+ if (isBrowser) localStorage.setItem("meetingHotkeyLayoutMode", mode);
+ set({ meetingHotkeyLayoutMode: mode });
+ },
+
setActivationMode: (mode: "tap" | "push") => {
if (isBrowser) localStorage.setItem("activationMode", mode);
set({ activationMode: mode });
diff --git a/src/types/electron.ts b/src/types/electron.ts
index b72077fe8..7a364071d 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -52,6 +52,8 @@ export interface NoteItem {
transcript: string | null;
calendar_event_id: string | null;
participants: string | null;
+ diarization_enabled: number | null;
+ expected_speaker_count: number | null;
cloud_id: string | null;
created_at: string;
updated_at: string;
@@ -471,6 +473,8 @@ declare global {
transcript?: string | null;
calendar_event_id?: string | null;
participants?: string | null;
+ diarization_enabled?: number | null;
+ expected_speaker_count?: number | null;
}
) => Promise<{ success: boolean; note?: NoteItem }>;
deleteNote: (id: number) => Promise<{ success: boolean }>;
@@ -754,6 +758,7 @@ declare global {
windowMaximize: () => Promise<void>;
windowClose: () => Promise<void>;
windowIsMaximized: () => Promise<boolean>;
+ snapToMeetingMode: () => Promise<void>;
restoreFromMeetingMode: () => Promise<void>;
getPlatform: () => string;
startWindowDrag: () => Promise<void>;
@@ -1591,7 +1596,12 @@ declare global {
) => Promise<{ success: boolean }>;
joinCalendarMeeting?: (eventId: string) => Promise<{ success: boolean }>;
onNavigateToMeetingNote?: (
- callback: (data: { noteId: number; folderId: number; event: any }) => void
+ callback: (data: {
+ noteId: number;
+ folderId: number;
+ event: any;
+ trigger?: "hotkey" | "manual" | "calendar-join";
+ }) => void
) => () => void;
onNavigateToNote?: (
callback: (data: { noteId: number; folderId: number | null }) => void
diff --git a/src/utils/parseTranscriptSegments.ts b/src/utils/parseTranscriptSegments.ts
index f8429577b..fa833f5c5 100644
--- a/src/utils/parseTranscriptSegments.ts
+++ b/src/utils/parseTranscriptSegments.ts
@@ -1,4 +1,4 @@
-import type { TranscriptSegment } from "../hooks/useMeetingTranscription";
+import type { TranscriptSegment } from "../stores/meetingRecordingStore";
import { normalizeTranscriptSegments } from "./transcriptSpeakerState";
import logger from "./logger";
export function parseTranscriptSegments(raw: string): TranscriptSegment[] {
diff --git a/src/utils/transcriptSpeakerState.ts b/src/utils/transcriptSpeakerState.ts
index 6320f2f55..8a25928e8 100644
--- a/src/utils/transcriptSpeakerState.ts
+++ b/src/utils/transcriptSpeakerState.ts
@@ -1,4 +1,4 @@
-import type { TranscriptSegment } from "../hooks/useMeetingTranscription";
+import type { TranscriptSegment } from "../stores/meetingRecordingStore";
export type TranscriptSpeakerStatus = "provisional" | "confirmed" | "suggested" | "locked";
export type TranscriptSpeakerLockSource = "user" | "diarization" | "suggestion";