Skip to content

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

feat: extend OpenAI Realtime WebSocket streaming to normal dictation

Gabriel Steina730a3f5a796
diff --git a/preload.js b/preload.js
index ee3b157d4..bb0d4d9ba 100644
--- a/preload.js
+++ b/preload.js
@@ -468,6 +468,16 @@ contextBridge.exposeInMainWorld("electronAPI", {
(callback) => (_event, data) => callback(data)
),
+ // Dictation realtime streaming
+ dictationRealtimeWarmup: (options) => ipcRenderer.invoke("dictation-realtime-warmup", options),
+ 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)),
+
// Usage limit events (for showing UpgradePrompt in ControlPanel)
notifyLimitReached: (data) => ipcRenderer.send("limit-reached", data),
onLimitReached: registerListener("limit-reached", (callback) => (_event, data) => callback(data)),
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index 4d64607cf..9ed250dae 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -51,6 +51,16 @@ const STREAMING_PROVIDERS = {
onError: (cb) => window.electronAPI.onAssemblyAiError(cb),
onSessionEnd: (cb) => window.electronAPI.onAssemblyAiSessionEnd(cb),
},
+ "openai-realtime": {
+ warmup: (opts) => window.electronAPI.dictationRealtimeWarmup(opts),
+ start: (opts) => window.electronAPI.dictationRealtimeStart(opts),
+ send: (buf) => window.electronAPI.dictationRealtimeSend(buf),
+ stop: () => window.electronAPI.dictationRealtimeStop(),
+ onPartial: (cb) => window.electronAPI.onDictationRealtimePartial(cb),
+ onFinal: (cb) => window.electronAPI.onDictationRealtimeFinal(cb),
+ onError: (cb) => window.electronAPI.onDictationRealtimeError(cb),
+ onSessionEnd: (cb) => window.electronAPI.onDictationRealtimeSessionEnd(cb),
+ },
};
class AudioManager {
@@ -178,6 +188,10 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
}
getStreamingProvider() {
+ const { cloudTranscriptionModel } = getSettings();
+ if (cloudTranscriptionModel === "gpt-4o-mini-transcribe" || cloudTranscriptionModel === "gpt-4o-transcribe") {
+ return STREAMING_PROVIDERS["openai-realtime"];
+ }
const providerName = this.sttConfig?.streamingProvider || "deepgram";
return STREAMING_PROVIDERS[providerName] || STREAMING_PROVIDERS.deepgram;
}
@@ -1917,23 +1931,23 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
shouldUseStreaming(isSignedInOverride) {
const s = getSettings();
- const isSignedIn = isSignedInOverride ?? s.isSignedIn;
- if (s.useLocalWhisper || s.cloudTranscriptionMode !== "openwhispr" || !isSignedIn) {
+ if (s.useLocalWhisper) return false;
+
+ if (s.cloudTranscriptionModel === "gpt-4o-mini-transcribe" || s.cloudTranscriptionModel === "gpt-4o-transcribe") {
+ if (s.cloudTranscriptionMode === "byok") return !!s.openaiApiKey;
+ if (s.cloudTranscriptionMode === "openwhispr") return !!(isSignedInOverride ?? s.isSignedIn);
return false;
}
- // For notes context, require explicit opt-in to streaming
+ if (s.cloudTranscriptionMode !== "openwhispr" || !(isSignedInOverride ?? s.isSignedIn)) {
+ return false;
+ }
if (this.context === "notes") {
return localStorage.getItem("notesStreamingPreference") === "streaming";
}
-
- // Config-driven: check mode for this context
if (this.sttConfig) {
- const contextConfig = this.sttConfig.dictation;
- return contextConfig?.mode === "streaming";
+ return this.sttConfig.dictation?.mode === "streaming";
}
-
- // Fallback when config not yet loaded
return localStorage.getItem("deepgramStreaming") !== "false";
}
@@ -1948,11 +1962,13 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
const [, wsResult] = await Promise.all([
this.cacheMicrophoneDeviceId(),
withSessionRefresh(async () => {
- const warmupLang = getSettings().preferredLanguage;
+ const { preferredLanguage: warmupLang, cloudTranscriptionModel, cloudTranscriptionMode } = getSettings();
const res = await provider.warmup({
sampleRate: 16000,
language: warmupLang && warmupLang !== "auto" ? warmupLang : undefined,
keyterms: this.getKeyterms(),
+ model: cloudTranscriptionModel,
+ mode: cloudTranscriptionMode === "byok" ? "byok" : "openwhispr",
});
// Throw error to trigger retry if AUTH_EXPIRED
if (!res.success && res.code) {
@@ -2162,11 +2178,13 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
// 4. Connect WebSocket — audio is already flowing from the pipeline above,
// so Deepgram receives data immediately (no idle timeout).
const result = await withSessionRefresh(async () => {
- const preferredLang = getSettings().preferredLanguage;
+ const { preferredLanguage: preferredLang, cloudTranscriptionModel, cloudTranscriptionMode } = getSettings();
const res = await provider.start({
sampleRate: 16000,
language: preferredLang && preferredLang !== "auto" ? preferredLang : undefined,
keyterms: this.getKeyterms(),
+ model: cloudTranscriptionModel,
+ mode: cloudTranscriptionMode === "byok" ? "byok" : "openwhispr",
});
if (!res.success) {
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 09293c12c..f8f63a201 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -107,6 +107,7 @@ class IPCHandlers {
this.assemblyAiStreaming = null;
this.deepgramStreaming = null;
this.openaiRealtimeStreaming = null;
+ this._dictationStreaming = null;
this._autoLearnEnabled = true; // Default on, synced from renderer
this._autoLearnDebounceTimer = null;
this._autoLearnLatestData = null;
@@ -133,6 +134,21 @@ 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);
@@ -2348,6 +2364,59 @@ 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;
+ return { success: true };
+ } catch (err) {
+ return { success: false, error: err.message };
+ }
+ });
+
+ 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;
+ return { success: true };
+ } catch (err) {
+ return { success: false, error: err.message };
+ }
+ });
+
+ ipcMain.on("dictation-realtime-send", (_event, buffer) => {
+ this._dictationStreaming?.sendAudio(Buffer.from(buffer));
+ });
+
+ ipcMain.handle("dictation-realtime-stop", async () => {
+ if (!this._dictationStreaming) {
+ return { success: true, text: "" };
+ }
+ const result = await this._dictationStreaming.disconnect().catch(() => ({ text: "" }));
+ this._dictationStreaming = null;
+ return { success: true, text: result.text || "" };
+ });
+
ipcMain.handle("update-transcription-text", async (_event, id, text, rawText) => {
try {
this.databaseManager.updateTranscriptionText(id, text, rawText);
diff --git a/src/types/electron.ts b/src/types/electron.ts
index 756ccde79..0397908da 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -1100,6 +1100,16 @@ declare global {
onMeetingTranscriptionFinal?: (callback: (text: string) => void) => () => void;
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;
+
// Desktop audio capture
getDesktopSources?: (types: string[]) => Promise<Array<{ id: string; name: string }>>;