Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
refactor: eliminate duplication and fix style inconsistencies in dictation streaming
Gabriel Steinfdcc1e528513
diff --git a/preload.js b/preload.jsindex bb0d4d9ba..eb9d30a90 100644--- a/preload.js+++ b/preload.js@@ -473,10 +473,22 @@ contextBridge.exposeInMainWorld("electronAPI", {dictationRealtimeStart: (options) => ipcRenderer.invoke("dictation-realtime-start", options),dictationRealtimeSend: (buffer) => ipcRenderer.send("dictation-realtime-send", buffer),dictationRealtimeStop: () => ipcRenderer.invoke("dictation-realtime-stop"),- onDictationRealtimePartial: registerListener("dictation-realtime-partial", (cb) => (_e, d) => cb(d)),- onDictationRealtimeFinal: registerListener("dictation-realtime-final", (cb) => (_e, d) => cb(d)),- onDictationRealtimeError: registerListener("dictation-realtime-error", (cb) => (_e, d) => cb(d)),- onDictationRealtimeSessionEnd: registerListener("dictation-realtime-session-end", (cb) => (_e, d) => cb(d)),+ onDictationRealtimePartial: registerListener(+ "dictation-realtime-partial",+ (callback) => (_event, data) => callback(data)+ ),+ onDictationRealtimeFinal: registerListener(+ "dictation-realtime-final",+ (callback) => (_event, data) => callback(data)+ ),+ onDictationRealtimeError: registerListener(+ "dictation-realtime-error",+ (callback) => (_event, data) => callback(data)+ ),+ onDictationRealtimeSessionEnd: registerListener(+ "dictation-realtime-session-end",+ (callback) => (_event, data) => callback(data)+ ),// Usage limit events (for showing UpgradePrompt in ControlPanel)notifyLimitReached: (data) => ipcRenderer.send("limit-reached", data),diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 9ed250dae..9e5ce2fb5 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -13,6 +13,7 @@ import {const SHORT_CLIP_DURATION_SECONDS = 2.5;const REASONING_CACHE_TTL = 30000; // 30 seconds+const REALTIME_MODELS = new Set(["gpt-4o-mini-transcribe", "gpt-4o-transcribe"]);const PLACEHOLDER_KEYS = {openai: "your_openai_api_key_here",@@ -189,7 +190,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);getStreamingProvider() {const { cloudTranscriptionModel } = getSettings();- if (cloudTranscriptionModel === "gpt-4o-mini-transcribe" || cloudTranscriptionModel === "gpt-4o-transcribe") {+ if (REALTIME_MODELS.has(cloudTranscriptionModel)) {return STREAMING_PROVIDERS["openai-realtime"];}const providerName = this.sttConfig?.streamingProvider || "deepgram";@@ -1933,7 +1934,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);const s = getSettings();if (s.useLocalWhisper) return false;- if (s.cloudTranscriptionModel === "gpt-4o-mini-transcribe" || s.cloudTranscriptionModel === "gpt-4o-transcribe") {+ if (REALTIME_MODELS.has(s.cloudTranscriptionModel)) {if (s.cloudTranscriptionMode === "byok") return !!s.openaiApiKey;if (s.cloudTranscriptionMode === "openwhispr") return !!(isSignedInOverride ?? s.isSignedIn);return false;diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex f8f63a201..b55c902cf 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -134,21 +134,6 @@ class IPCHandlers {}}- _setupDictationCallbacks(streaming, event) {- streaming.onPartialTranscript = (text) => {- event.sender.send("dictation-realtime-partial", { text });- };- streaming.onFinalTranscript = (text) => {- event.sender.send("dictation-realtime-final", { text });- };- streaming.onError = (error) => {- event.sender.send("dictation-realtime-error", { error: error.message });- };- streaming.onSessionEnd = () => {- event.sender.send("dictation-realtime-session-end", {});- };- }-_cleanupTextEditMonitor() {if (this._autoLearnDebounceTimer) {clearTimeout(this._autoLearnDebounceTimer);@@ -2275,6 +2260,25 @@ class IPCHandlers {return win;};+ const setupDictationCallbacks = (streaming, event) => {+ streaming.onPartialTranscript = (text) => event.sender.send("dictation-realtime-partial", { text });+ streaming.onFinalTranscript = (text) => event.sender.send("dictation-realtime-final", { text });+ streaming.onError = (err) => event.sender.send("dictation-realtime-error", { error: err.message });+ streaming.onSessionEnd = (data) => event.sender.send("dictation-realtime-session-end", data || {});+ };++ const connectDictationStreaming = async (event, options) => {+ if (this._dictationStreaming) {+ await this._dictationStreaming.disconnect().catch(() => {});+ this._dictationStreaming = null;+ }+ const apiKey = await fetchRealtimeToken(event, { mode: options.mode });+ const streaming = new OpenAIRealtimeStreaming();+ setupDictationCallbacks(streaming, event);+ await streaming.connect({ apiKey, model: options.model || "gpt-4o-mini-transcribe" });+ this._dictationStreaming = streaming;+ };+// Pre-warm: fetch token + connect WebSocket before user hits recordipcMain.handle("meeting-transcription-prepare", async (event, options = {}) => {if (meetingTranscriptionPrepareInProgress || meetingTranscriptionStartInProgress) {@@ -2366,16 +2370,7 @@ class IPCHandlers {ipcMain.handle("dictation-realtime-warmup", async (event, options = {}) => {try {- if (this._dictationStreaming) {- await this._dictationStreaming.disconnect().catch(() => {});- this._dictationStreaming = null;- }-- const apiKey = await fetchRealtimeToken(event, { mode: options.mode });- const streaming = new OpenAIRealtimeStreaming();- this._setupDictationCallbacks(streaming, event);- await streaming.connect({ apiKey, model: options.model || "gpt-4o-mini-transcribe" });- this._dictationStreaming = streaming;+ await connectDictationStreaming(event, options);return { success: true };} catch (err) {return { success: false, error: err.message };@@ -2384,20 +2379,7 @@ class IPCHandlers {ipcMain.handle("dictation-realtime-start", async (event, options = {}) => {try {- if (this._dictationStreaming?.isConnected) {- return { success: true };- }-- if (this._dictationStreaming) {- await this._dictationStreaming.disconnect().catch(() => {});- this._dictationStreaming = null;- }-- const apiKey = await fetchRealtimeToken(event, { mode: options.mode });- const streaming = new OpenAIRealtimeStreaming();- this._setupDictationCallbacks(streaming, event);- await streaming.connect({ apiKey, model: options.model || "gpt-4o-mini-transcribe" });- this._dictationStreaming = streaming;+ if (!this._dictationStreaming?.isConnected) await connectDictationStreaming(event, options);return { success: true };} catch (err) {return { success: false, error: err.message };diff --git a/src/types/electron.ts b/src/types/electron.tsindex 0397908da..06024d7d0 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -1101,14 +1101,14 @@ declare global {onMeetingTranscriptionError?: (callback: (error: string) => void) => () => void;// Dictation realtime streaming- dictationRealtimeWarmup?(options: { model?: string; mode?: "byok" | "openwhispr" }): Promise<{ success: boolean; error?: string }>;- dictationRealtimeStart?(options: { model?: string; mode?: "byok" | "openwhispr" }): Promise<{ success: boolean; error?: string }>;- dictationRealtimeSend?(buffer: ArrayBuffer): void;- dictationRealtimeStop?(): Promise<{ success: boolean; text: string }>;- onDictationRealtimePartial?(callback: (data: { text: string }) => void): () => void;- onDictationRealtimeFinal?(callback: (data: { text: string }) => void): () => void;- onDictationRealtimeError?(callback: (data: { error: string }) => void): () => void;- onDictationRealtimeSessionEnd?(callback: (data: { text: string }) => void): () => void;+ dictationRealtimeWarmup?: (options: { model?: string; mode?: "byok" | "openwhispr" }) => Promise<{ success: boolean; error?: string }>;+ dictationRealtimeStart?: (options: { model?: string; mode?: "byok" | "openwhispr" }) => Promise<{ success: boolean; error?: string }>;+ dictationRealtimeSend?: (buffer: ArrayBuffer) => void;+ dictationRealtimeStop?: () => Promise<{ success: boolean; text: string }>;+ onDictationRealtimePartial?: (callback: (data: { text: string }) => void) => () => void;+ onDictationRealtimeFinal?: (callback: (data: { text: string }) => void) => () => void;+ onDictationRealtimeError?: (callback: (data: { error: string }) => void) => () => void;+ onDictationRealtimeSessionEnd?: (callback: (data: { text: string }) => void) => () => void;// Desktop audio capturegetDesktopSources?: (types: string[]) => Promise<Array<{ id: string; name: string }>>;