superbased 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SUPERBASED_SKILL.md +91 -32
- package/dist/headless/electron/modules/active-window.js +8 -0
- package/dist/headless/electron/modules/api-server.js +137 -3
- package/dist/headless/electron/modules/azure-speech-realtime.js +187 -54
- package/dist/headless/electron/modules/dictation.js +122 -0
- package/dist/headless/headless/dictation-hotkey.js +212 -47
- package/dist/headless/headless/dictation-overlay.js +218 -0
- package/dist/headless/headless/mic-capture.js +95 -1
- package/dist/headless/headless/platform-headless.js +103 -3
- package/dist/headless/headless/win32-text-injector.js +359 -0
- package/mcp-server/dist/index.js +4 -4
- package/package.json +1 -1
|
@@ -63,6 +63,10 @@ let hookStarted = false;
|
|
|
63
63
|
let transcriptionMode = 'batch';
|
|
64
64
|
let azureConfig = null;
|
|
65
65
|
let realtimeActive = false;
|
|
66
|
+
// Pre-saved clipboard content from before dictation (saved during tail window)
|
|
67
|
+
let pendingClipboardRestore = null;
|
|
68
|
+
// Pre-created VBScript for SendKeys paste — avoids PowerShell spawn overhead (~230ms → ~50ms)
|
|
69
|
+
let sendKeysVbsPath = null;
|
|
66
70
|
// Pre-cached imports for speed — avoids dynamic import() on every dictation
|
|
67
71
|
let cachedRt = null;
|
|
68
72
|
let cachedUserPhrases = null;
|
|
@@ -70,6 +74,62 @@ let cachedCleanupFns = null;
|
|
|
70
74
|
// Timing helpers
|
|
71
75
|
function ts() { return performance.now(); }
|
|
72
76
|
function elapsed(start) { return `${(performance.now() - start).toFixed(0)}ms`; }
|
|
77
|
+
// ── Terminal UI indicators ──
|
|
78
|
+
const ANSI = {
|
|
79
|
+
reset: '\x1b[0m',
|
|
80
|
+
red: '\x1b[31m',
|
|
81
|
+
green: '\x1b[32m',
|
|
82
|
+
yellow: '\x1b[33m',
|
|
83
|
+
cyan: '\x1b[36m',
|
|
84
|
+
dim: '\x1b[2m',
|
|
85
|
+
bold: '\x1b[1m',
|
|
86
|
+
clearLine: '\r\x1b[K',
|
|
87
|
+
};
|
|
88
|
+
const REC_FRAMES = ['● ', '◉ ', '● ', '○ '];
|
|
89
|
+
let indicatorInterval = null;
|
|
90
|
+
let indicatorFrame = 0;
|
|
91
|
+
let lastIntermediateText = '';
|
|
92
|
+
function showRecording() {
|
|
93
|
+
stopIndicator();
|
|
94
|
+
indicatorFrame = 0;
|
|
95
|
+
indicatorInterval = setInterval(() => {
|
|
96
|
+
const dot = REC_FRAMES[indicatorFrame % REC_FRAMES.length];
|
|
97
|
+
const label = lastIntermediateText
|
|
98
|
+
? `${ANSI.clearLine}${ANSI.red}${dot}${ANSI.reset}${ANSI.dim}${lastIntermediateText}${ANSI.reset}`
|
|
99
|
+
: `${ANSI.clearLine}${ANSI.red}${dot}REC${ANSI.reset} ${ANSI.dim}listening...${ANSI.reset}`;
|
|
100
|
+
process.stderr.write(label);
|
|
101
|
+
indicatorFrame++;
|
|
102
|
+
}, 400);
|
|
103
|
+
}
|
|
104
|
+
function updateIntermediate(text) {
|
|
105
|
+
lastIntermediateText = text;
|
|
106
|
+
const dot = REC_FRAMES[indicatorFrame % REC_FRAMES.length];
|
|
107
|
+
process.stderr.write(`${ANSI.clearLine}${ANSI.red}${dot}${ANSI.reset}${text}`);
|
|
108
|
+
}
|
|
109
|
+
function showTranscribing() {
|
|
110
|
+
stopIndicator();
|
|
111
|
+
const SPIN = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
112
|
+
let frame = 0;
|
|
113
|
+
indicatorInterval = setInterval(() => {
|
|
114
|
+
process.stderr.write(`${ANSI.clearLine}${ANSI.yellow}${SPIN[frame % SPIN.length]} transcribing...${ANSI.reset}`);
|
|
115
|
+
frame++;
|
|
116
|
+
}, 80);
|
|
117
|
+
}
|
|
118
|
+
function showDone(text) {
|
|
119
|
+
stopIndicator();
|
|
120
|
+
process.stderr.write(`${ANSI.clearLine}${ANSI.green}${ANSI.bold}✓${ANSI.reset} ${text}\n`);
|
|
121
|
+
}
|
|
122
|
+
function showError(msg) {
|
|
123
|
+
stopIndicator();
|
|
124
|
+
process.stderr.write(`${ANSI.clearLine}${ANSI.red}✗${ANSI.reset} ${msg}\n`);
|
|
125
|
+
}
|
|
126
|
+
function stopIndicator() {
|
|
127
|
+
if (indicatorInterval) {
|
|
128
|
+
clearInterval(indicatorInterval);
|
|
129
|
+
indicatorInterval = null;
|
|
130
|
+
}
|
|
131
|
+
lastIntermediateText = '';
|
|
132
|
+
}
|
|
73
133
|
function updateRequiredKeycodes() {
|
|
74
134
|
requiredKeycodes = new Set();
|
|
75
135
|
for (const mod of shortcutModifiers) {
|
|
@@ -132,29 +192,38 @@ async function startDictation() {
|
|
|
132
192
|
if (state !== 'idle')
|
|
133
193
|
return;
|
|
134
194
|
if (!(0, auth_1.isAuthenticated)()) {
|
|
135
|
-
|
|
195
|
+
showError('Not signed in — run: superbased auth login');
|
|
136
196
|
return;
|
|
137
197
|
}
|
|
138
198
|
if (!(0, mic_capture_1.isMicAvailable)()) {
|
|
139
|
-
|
|
199
|
+
showError('No mic backend — install ffmpeg');
|
|
140
200
|
return;
|
|
141
201
|
}
|
|
142
202
|
const t0 = ts();
|
|
143
203
|
state = 'recording';
|
|
204
|
+
// Pre-save clipboard NOW (async, non-blocking) so it's ready by the time
|
|
205
|
+
// we need to paste. Moves ~200-300ms PowerShell spawn out of the stop path.
|
|
206
|
+
pendingClipboardRestore = null;
|
|
207
|
+
if (!(0, platform_1.getPlatform)().isElectron() && process.platform === 'win32') {
|
|
208
|
+
const { exec } = require('child_process');
|
|
209
|
+
exec('powershell -command "Get-Clipboard -Raw"', { encoding: 'utf-8', timeout: 3000 }, (err, stdout) => {
|
|
210
|
+
pendingClipboardRestore = err ? '' : (stdout || '').trim();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
144
213
|
try {
|
|
145
214
|
const maxDuration = (0, json_store_1.getSetting)('dictationSettings')?.maxDurationSeconds || 120;
|
|
146
215
|
if (transcriptionMode === 'realtime' && azureConfig) {
|
|
147
|
-
|
|
216
|
+
showRecording();
|
|
148
217
|
await startRealtimeRecording(maxDuration, t0);
|
|
149
218
|
}
|
|
150
219
|
else {
|
|
151
|
-
|
|
220
|
+
showRecording();
|
|
152
221
|
currentRecording = (0, mic_capture_1.startRecording)(maxDuration);
|
|
153
222
|
file_logger_1.default.info(`[Dictation] [PERF] ffmpeg spawn: ${elapsed(t0)}`);
|
|
154
223
|
}
|
|
155
224
|
}
|
|
156
225
|
catch (err) {
|
|
157
|
-
|
|
226
|
+
showError(`Failed to start: ${err}`);
|
|
158
227
|
state = 'idle';
|
|
159
228
|
}
|
|
160
229
|
}
|
|
@@ -164,23 +233,30 @@ async function startRealtimeRecording(maxDuration, t0) {
|
|
|
164
233
|
const tPreBuf = ts();
|
|
165
234
|
rt.startPreBuffering();
|
|
166
235
|
file_logger_1.default.info(`[Dictation] [PERF] pre-buffer start: ${elapsed(t0)}`);
|
|
167
|
-
//
|
|
168
|
-
const tFfmpeg = ts();
|
|
169
|
-
currentRecording = (0, mic_capture_1.startRecording)(maxDuration);
|
|
170
|
-
realtimeActive = true;
|
|
171
|
-
file_logger_1.default.info(`[Dictation] [PERF] ffmpeg spawn: ${elapsed(t0)} (ffmpeg only: ${elapsed(tFfmpeg)})`);
|
|
172
|
-
// Wire PCM streaming: ffmpeg stdout → Azure SDK (real-time)
|
|
236
|
+
// Wire PCM streaming: mic → Azure SDK (real-time)
|
|
173
237
|
let chunkCount = 0;
|
|
174
|
-
|
|
175
|
-
currentRecording.onPcmChunk((chunk) => {
|
|
238
|
+
const pcmHandler = (chunk) => {
|
|
176
239
|
chunkCount++;
|
|
177
240
|
if (chunkCount === 1) {
|
|
178
|
-
firstChunkTime = ts();
|
|
179
241
|
file_logger_1.default.info(`[Dictation] [PERF] first PCM chunk: ${elapsed(t0)}`);
|
|
180
242
|
}
|
|
181
243
|
const ab = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
|
|
182
244
|
rt.pushAudioData(ab);
|
|
183
|
-
}
|
|
245
|
+
};
|
|
246
|
+
// Use warm mic if available (instant start, no ffmpeg spawn delay).
|
|
247
|
+
// Falls back to cold start if warm mic isn't running.
|
|
248
|
+
const tFfmpeg = ts();
|
|
249
|
+
if ((0, mic_capture_1.isWarmMicRunning)()) {
|
|
250
|
+
(0, mic_capture_1.startWarmCapture)(pcmHandler);
|
|
251
|
+
realtimeActive = true;
|
|
252
|
+
file_logger_1.default.info(`[Dictation] [PERF] warm mic attached: ${elapsed(t0)} (instant)`);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
currentRecording = (0, mic_capture_1.startRecording)(maxDuration);
|
|
256
|
+
realtimeActive = true;
|
|
257
|
+
currentRecording.onPcmChunk(pcmHandler);
|
|
258
|
+
file_logger_1.default.info(`[Dictation] [PERF] ffmpeg spawn: ${elapsed(t0)} (ffmpeg only: ${elapsed(tFfmpeg)})`);
|
|
259
|
+
}
|
|
184
260
|
// Read settings with desktop-matching defaults
|
|
185
261
|
const settings = (0, json_store_1.getSetting)('dictationSettings');
|
|
186
262
|
const endSilenceMs = settings?.endSilenceMs ?? 5000;
|
|
@@ -199,7 +275,7 @@ async function startRealtimeRecording(maxDuration, t0) {
|
|
|
199
275
|
const tAzure = ts();
|
|
200
276
|
await rt.startRealtimeRecognition(azureConfig.apiKey, azureConfig.region, settings?.language || 'en-US', {
|
|
201
277
|
onIntermediate: (text) => {
|
|
202
|
-
|
|
278
|
+
updateIntermediate(text);
|
|
203
279
|
},
|
|
204
280
|
onFinal: (text) => {
|
|
205
281
|
file_logger_1.default.info('[Dictation] RT final:', text.substring(0, 50));
|
|
@@ -212,28 +288,40 @@ async function startRealtimeRecording(maxDuration, t0) {
|
|
|
212
288
|
file_logger_1.default.info(`[Dictation] [PERF] PCM chunks sent during init: ${chunkCount}`);
|
|
213
289
|
}
|
|
214
290
|
async function stopDictation() {
|
|
215
|
-
if (state !== 'recording'
|
|
291
|
+
if (state !== 'recording')
|
|
292
|
+
return;
|
|
293
|
+
if (!currentRecording && !realtimeActive)
|
|
216
294
|
return;
|
|
217
295
|
const t0 = ts();
|
|
218
296
|
state = 'transcribing';
|
|
219
|
-
|
|
297
|
+
showTranscribing();
|
|
220
298
|
try {
|
|
221
299
|
let rawText;
|
|
222
300
|
if (realtimeActive && azureConfig) {
|
|
223
301
|
// Realtime mode: audio already streamed to Azure.
|
|
224
|
-
//
|
|
302
|
+
// Clipboard was pre-saved at recording start (async) — pendingClipboardRestore is ready.
|
|
303
|
+
// Keep capturing for a brief tail window after key release so the
|
|
304
|
+
// last syllable isn't clipped, then stop forwarding.
|
|
305
|
+
const tTail = ts();
|
|
306
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
307
|
+
file_logger_1.default.info(`[Dictation] [PERF] audio tail: ${elapsed(tTail)}`);
|
|
225
308
|
const tStop = ts();
|
|
226
|
-
currentRecording
|
|
227
|
-
|
|
228
|
-
|
|
309
|
+
if (currentRecording) {
|
|
310
|
+
currentRecording.stop().catch(() => { });
|
|
311
|
+
currentRecording = null;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
(0, mic_capture_1.stopWarmCapture)();
|
|
315
|
+
}
|
|
316
|
+
file_logger_1.default.info(`[Dictation] [PERF] mic stop: ${elapsed(tStop)}`);
|
|
229
317
|
// Get final result from Azure
|
|
230
318
|
const tAzureStop = ts();
|
|
231
319
|
const rt = cachedRt || await Promise.resolve().then(() => __importStar(require('../electron/modules/azure-speech-realtime')));
|
|
232
320
|
rawText = await rt.stopRealtimeRecognition();
|
|
233
321
|
realtimeActive = false;
|
|
234
|
-
file_logger_1.default.info(`[Dictation] [PERF]
|
|
322
|
+
file_logger_1.default.info(`[Dictation] [PERF] azure stop: ${elapsed(tAzureStop)}`);
|
|
235
323
|
}
|
|
236
|
-
else {
|
|
324
|
+
else if (currentRecording) {
|
|
237
325
|
// Batch mode: need the audio buffer
|
|
238
326
|
const tStop = ts();
|
|
239
327
|
const audioBuffer = await currentRecording.stop();
|
|
@@ -245,41 +333,97 @@ async function stopDictation() {
|
|
|
245
333
|
rawText = await transcribeViaBackend(audioBase64, undefined, 'dictation-hotkey');
|
|
246
334
|
file_logger_1.default.info(`[Dictation] [PERF] Whisper round-trip: ${elapsed(tWhisper)}`);
|
|
247
335
|
}
|
|
336
|
+
else {
|
|
337
|
+
rawText = '';
|
|
338
|
+
}
|
|
248
339
|
if (!rawText || rawText.trim().length === 0) {
|
|
249
|
-
|
|
340
|
+
showError('No speech detected');
|
|
250
341
|
state = 'idle';
|
|
251
342
|
return;
|
|
252
343
|
}
|
|
253
|
-
// Text cleanup
|
|
344
|
+
// Text cleanup — same pipeline as desktop: dedup → technical terms → fillers → short phrase
|
|
254
345
|
const tCleanup = ts();
|
|
255
346
|
let finalText = rawText;
|
|
256
347
|
if (cachedCleanupFns) {
|
|
257
|
-
finalText = cachedCleanupFns.deduplicateConsecutiveWords(
|
|
348
|
+
finalText = cachedCleanupFns.deduplicateConsecutiveWords(finalText);
|
|
349
|
+
finalText = cachedCleanupFns.normalizeTechnicalTerms(finalText);
|
|
350
|
+
finalText = cachedCleanupFns.removeFillerWords(finalText);
|
|
351
|
+
finalText = cachedCleanupFns.normalizeShortPhrase(finalText);
|
|
258
352
|
}
|
|
259
|
-
|
|
260
|
-
|
|
353
|
+
const cleanupMs = elapsed(tCleanup);
|
|
354
|
+
file_logger_1.default.info(`[Dictation] [PERF] cleanup: ${cleanupMs}`);
|
|
355
|
+
// Write text → paste → restore clipboard.
|
|
356
|
+
// Clipboard was pre-saved during the tail window (pendingClipboardRestore).
|
|
357
|
+
// On Windows: use clip.exe for write (instant), WScript.Shell for SendKeys,
|
|
358
|
+
// then restore via clip.exe in background after a delay.
|
|
261
359
|
const tPaste = ts();
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
360
|
+
if (!(0, platform_1.getPlatform)().isElectron() && process.platform === 'win32') {
|
|
361
|
+
try {
|
|
362
|
+
const { execSync: execSyncPaste } = require('child_process');
|
|
363
|
+
// Write text to clipboard via clip.exe (much faster than PowerShell Set-Clipboard)
|
|
364
|
+
execSyncPaste('clip', { input: finalText, timeout: 2000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
365
|
+
// Send Ctrl+V — use pre-created VBScript via cscript (much faster than PowerShell)
|
|
366
|
+
if (sendKeysVbsPath) {
|
|
367
|
+
execSyncPaste(`cscript //nologo "${sendKeysVbsPath}"`, { timeout: 2000, stdio: 'pipe' });
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
execSyncPaste('powershell -command "(New-Object -ComObject WScript.Shell).SendKeys(\'^v\')"', { timeout: 3000, stdio: 'pipe' });
|
|
371
|
+
}
|
|
372
|
+
// Restore clipboard in background after target app processes the paste
|
|
373
|
+
if (pendingClipboardRestore) {
|
|
374
|
+
const prev = pendingClipboardRestore;
|
|
375
|
+
pendingClipboardRestore = null;
|
|
376
|
+
setTimeout(() => {
|
|
377
|
+
try {
|
|
378
|
+
const { execSync: execSyncBg } = require('child_process');
|
|
379
|
+
execSyncBg('clip', { input: prev, timeout: 2000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
380
|
+
}
|
|
381
|
+
catch { /* ignore */ }
|
|
382
|
+
}, 500);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (err) {
|
|
386
|
+
file_logger_1.default.warn('[Dictation] Paste failed:', err);
|
|
387
|
+
}
|
|
269
388
|
}
|
|
270
|
-
|
|
271
|
-
//
|
|
389
|
+
else if (!(0, platform_1.getPlatform)().isElectron()) {
|
|
390
|
+
// macOS / Linux: use platform clipboard + osascript/xdotool
|
|
391
|
+
const { execSync: execSyncPaste } = require('child_process');
|
|
392
|
+
const previousClipboard = (0, platform_1.getPlatform)().getClipboardText();
|
|
393
|
+
(0, platform_1.getPlatform)().setClipboardText(finalText);
|
|
394
|
+
try {
|
|
395
|
+
if (process.platform === 'darwin') {
|
|
396
|
+
execSyncPaste('osascript -e \'tell application "System Events" to keystroke "v" using command down\'', { timeout: 3000, stdio: 'pipe' });
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
execSyncPaste('xdotool key ctrl+v 2>/dev/null', { timeout: 3000, stdio: 'pipe' });
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
catch { /* paste failed */ }
|
|
403
|
+
// Restore clipboard in background
|
|
404
|
+
if (previousClipboard) {
|
|
405
|
+
setTimeout(() => { (0, platform_1.getPlatform)().setClipboardText(previousClipboard); }, 500);
|
|
406
|
+
}
|
|
272
407
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
(0, platform_1.getPlatform)().
|
|
408
|
+
else {
|
|
409
|
+
// Desktop/Electron: use nut-js
|
|
410
|
+
const previousClipboard = (0, platform_1.getPlatform)().getClipboardText();
|
|
411
|
+
(0, platform_1.getPlatform)().setClipboardText(finalText);
|
|
412
|
+
try {
|
|
413
|
+
const { simulatePaste } = require('../electron/modules/keystroke');
|
|
414
|
+
await simulatePaste();
|
|
415
|
+
}
|
|
416
|
+
catch { /* not available */ }
|
|
417
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
418
|
+
if (previousClipboard)
|
|
419
|
+
(0, platform_1.getPlatform)().setClipboardText(previousClipboard);
|
|
276
420
|
}
|
|
277
|
-
file_logger_1.default.info(`[Dictation] [PERF]
|
|
278
|
-
file_logger_1.default.info(`[Dictation] [PERF]
|
|
279
|
-
|
|
421
|
+
file_logger_1.default.info(`[Dictation] [PERF] paste: ${elapsed(tPaste)}`);
|
|
422
|
+
file_logger_1.default.info(`[Dictation] [PERF] TOTAL stop→paste: ${elapsed(t0)}`);
|
|
423
|
+
showDone(`${finalText} ${ANSI.dim}(${elapsed(t0)})${ANSI.reset}`);
|
|
280
424
|
}
|
|
281
425
|
catch (err) {
|
|
282
|
-
|
|
426
|
+
showError(`Transcription failed: ${err}`);
|
|
283
427
|
realtimeActive = false;
|
|
284
428
|
}
|
|
285
429
|
finally {
|
|
@@ -297,10 +441,24 @@ async function initDictationHotkey() {
|
|
|
297
441
|
return;
|
|
298
442
|
}
|
|
299
443
|
(0, mic_capture_1.prewarm)();
|
|
444
|
+
// Pre-create VBScript for SendKeys paste (cscript is ~180ms faster than PowerShell)
|
|
445
|
+
if (process.platform === 'win32') {
|
|
446
|
+
try {
|
|
447
|
+
const os = require('os');
|
|
448
|
+
const path = require('path');
|
|
449
|
+
const fs = require('fs');
|
|
450
|
+
sendKeysVbsPath = path.join(os.tmpdir(), 'superbased-paste.vbs');
|
|
451
|
+
fs.writeFileSync(sendKeysVbsPath, 'CreateObject("WScript.Shell").SendKeys "^v"');
|
|
452
|
+
}
|
|
453
|
+
catch { /* ignore */ }
|
|
454
|
+
}
|
|
455
|
+
// Start warm mic — keeps ffmpeg process alive so dictation starts instantly
|
|
456
|
+
// (eliminates ~800ms dshow device open delay on each dictation)
|
|
457
|
+
(0, mic_capture_1.startWarmMic)();
|
|
300
458
|
// Pre-cache text cleanup functions (avoids 250ms dynamic import on first dictation)
|
|
301
459
|
try {
|
|
302
|
-
const { removeFillerWords, deduplicateConsecutiveWords } = require('../electron/modules/dictation');
|
|
303
|
-
cachedCleanupFns = { removeFillerWords, deduplicateConsecutiveWords };
|
|
460
|
+
const { removeFillerWords, deduplicateConsecutiveWords, normalizeTechnicalTerms, normalizeShortPhrase } = require('../electron/modules/dictation');
|
|
461
|
+
cachedCleanupFns = { removeFillerWords, deduplicateConsecutiveWords, normalizeTechnicalTerms, normalizeShortPhrase };
|
|
304
462
|
}
|
|
305
463
|
catch { /* not available */ }
|
|
306
464
|
// Fetch Azure config + pre-load SDK (non-blocking)
|
|
@@ -333,6 +491,7 @@ async function initDictationHotkey() {
|
|
|
333
491
|
}
|
|
334
492
|
}
|
|
335
493
|
async function teardownDictationHotkey() {
|
|
494
|
+
(0, mic_capture_1.shutdownWarmMic)();
|
|
336
495
|
if (currentRecording) {
|
|
337
496
|
currentRecording.cancel();
|
|
338
497
|
currentRecording = null;
|
|
@@ -345,6 +504,12 @@ async function teardownDictationHotkey() {
|
|
|
345
504
|
catch { /* ignore */ }
|
|
346
505
|
realtimeActive = false;
|
|
347
506
|
}
|
|
507
|
+
// Fully shut down the persistent Azure recognizer on exit
|
|
508
|
+
try {
|
|
509
|
+
const rt = cachedRt || await Promise.resolve().then(() => __importStar(require('../electron/modules/azure-speech-realtime')));
|
|
510
|
+
await rt.shutdownRecognizer();
|
|
511
|
+
}
|
|
512
|
+
catch { /* ignore */ }
|
|
348
513
|
try {
|
|
349
514
|
const { uIOhook } = await Promise.resolve().then(() => __importStar(require('uiohook-napi')));
|
|
350
515
|
uIOhook.off('keydown', onKeyDown);
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Floating overlay indicator for headless dictation (Windows).
|
|
3
|
+
// Pre-spawns a PowerShell/WinForms process that shows a small always-on-top
|
|
4
|
+
// pill when a signal file exists, and hides it when removed.
|
|
5
|
+
// This avoids the keyboard input pipeline entirely — no modifier key conflicts.
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.initOverlay = initOverlay;
|
|
44
|
+
exports.showOverlay = showOverlay;
|
|
45
|
+
exports.hideOverlay = hideOverlay;
|
|
46
|
+
exports.shutdownOverlay = shutdownOverlay;
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const os = __importStar(require("os"));
|
|
50
|
+
const child_process_1 = require("child_process");
|
|
51
|
+
const file_logger_1 = __importDefault(require("../electron/core/file-logger"));
|
|
52
|
+
const SIGNAL_FILE = path.join(os.tmpdir(), 'superbased-dictation.signal');
|
|
53
|
+
const EXIT_FILE = path.join(os.tmpdir(), 'superbased-dictation-exit.signal');
|
|
54
|
+
let overlayProcess = null;
|
|
55
|
+
let ready = false;
|
|
56
|
+
function initOverlay() {
|
|
57
|
+
if (process.platform !== 'win32')
|
|
58
|
+
return; // Windows only for now
|
|
59
|
+
// Clean up stale signal files
|
|
60
|
+
try {
|
|
61
|
+
fs.unlinkSync(SIGNAL_FILE);
|
|
62
|
+
}
|
|
63
|
+
catch { /* ignore */ }
|
|
64
|
+
try {
|
|
65
|
+
fs.unlinkSync(EXIT_FILE);
|
|
66
|
+
}
|
|
67
|
+
catch { /* ignore */ }
|
|
68
|
+
const scriptPath = path.join(os.tmpdir(), 'superbased-overlay.ps1');
|
|
69
|
+
fs.writeFileSync(scriptPath, OVERLAY_PS1);
|
|
70
|
+
overlayProcess = (0, child_process_1.spawn)('powershell', [
|
|
71
|
+
'-ExecutionPolicy', 'Bypass',
|
|
72
|
+
'-WindowStyle', 'Hidden',
|
|
73
|
+
'-File', scriptPath,
|
|
74
|
+
SIGNAL_FILE,
|
|
75
|
+
EXIT_FILE,
|
|
76
|
+
], {
|
|
77
|
+
stdio: 'ignore',
|
|
78
|
+
detached: false,
|
|
79
|
+
windowsHide: true,
|
|
80
|
+
});
|
|
81
|
+
overlayProcess.on('error', (err) => {
|
|
82
|
+
file_logger_1.default.warn('[Overlay] Failed to spawn:', err);
|
|
83
|
+
overlayProcess = null;
|
|
84
|
+
});
|
|
85
|
+
overlayProcess.on('exit', () => {
|
|
86
|
+
overlayProcess = null;
|
|
87
|
+
ready = false;
|
|
88
|
+
});
|
|
89
|
+
// Allow time for PowerShell + WinForms init (~2-3s)
|
|
90
|
+
setTimeout(() => { if (overlayProcess)
|
|
91
|
+
ready = true; }, 3000);
|
|
92
|
+
file_logger_1.default.info('[Overlay] Pre-spawned dictation overlay process');
|
|
93
|
+
}
|
|
94
|
+
function showOverlay(mode = 'recording') {
|
|
95
|
+
if (!ready || !overlayProcess)
|
|
96
|
+
return;
|
|
97
|
+
try {
|
|
98
|
+
fs.writeFileSync(SIGNAL_FILE, mode);
|
|
99
|
+
}
|
|
100
|
+
catch { /* ignore */ }
|
|
101
|
+
}
|
|
102
|
+
function hideOverlay() {
|
|
103
|
+
try {
|
|
104
|
+
fs.unlinkSync(SIGNAL_FILE);
|
|
105
|
+
}
|
|
106
|
+
catch { /* ignore */ }
|
|
107
|
+
}
|
|
108
|
+
function shutdownOverlay() {
|
|
109
|
+
// Signal the overlay to exit gracefully
|
|
110
|
+
try {
|
|
111
|
+
fs.writeFileSync(EXIT_FILE, 'exit');
|
|
112
|
+
}
|
|
113
|
+
catch { /* ignore */ }
|
|
114
|
+
try {
|
|
115
|
+
fs.unlinkSync(SIGNAL_FILE);
|
|
116
|
+
}
|
|
117
|
+
catch { /* ignore */ }
|
|
118
|
+
if (overlayProcess) {
|
|
119
|
+
const proc = overlayProcess;
|
|
120
|
+
overlayProcess = null;
|
|
121
|
+
// Give it time to exit gracefully, then force kill
|
|
122
|
+
setTimeout(() => { try {
|
|
123
|
+
proc.kill();
|
|
124
|
+
}
|
|
125
|
+
catch { /* ignore */ } }, 2000);
|
|
126
|
+
}
|
|
127
|
+
ready = false;
|
|
128
|
+
}
|
|
129
|
+
// PowerShell script that creates a WinForms overlay window.
|
|
130
|
+
// Uses file-based signaling: poll signal file every 150ms.
|
|
131
|
+
// - File exists with "recording" → show red "Recording..." pill
|
|
132
|
+
// - File exists with "transcribing" → show yellow "Transcribing..." pill
|
|
133
|
+
// - File deleted → hide
|
|
134
|
+
// - Exit file exists → exit process
|
|
135
|
+
const OVERLAY_PS1 = `param([string]$SignalFile, [string]$ExitFile)
|
|
136
|
+
|
|
137
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
138
|
+
Add-Type -AssemblyName System.Drawing
|
|
139
|
+
|
|
140
|
+
$w = 190; $h = 38
|
|
141
|
+
|
|
142
|
+
$form = New-Object System.Windows.Forms.Form
|
|
143
|
+
$form.FormBorderStyle = 'None'
|
|
144
|
+
$form.TopMost = $true
|
|
145
|
+
$form.ShowInTaskbar = $false
|
|
146
|
+
$form.Size = New-Object System.Drawing.Size($w, $h)
|
|
147
|
+
$form.StartPosition = 'Manual'
|
|
148
|
+
$form.Opacity = 0.94
|
|
149
|
+
$form.BackColor = [System.Drawing.Color]::FromArgb(28, 28, 42)
|
|
150
|
+
|
|
151
|
+
# Position at top-center of primary screen
|
|
152
|
+
$scr = [System.Windows.Forms.Screen]::PrimaryScreen
|
|
153
|
+
$form.Location = New-Object System.Drawing.Point(
|
|
154
|
+
[int](($scr.WorkingArea.Width - $w) / 2), 10
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# Rounded corners
|
|
158
|
+
$gp = New-Object System.Drawing.Drawing2D.GraphicsPath
|
|
159
|
+
$r = 14
|
|
160
|
+
$gp.AddArc(0, 0, $r, $r, 180, 90)
|
|
161
|
+
$gp.AddArc($w - $r - 1, 0, $r, $r, 270, 90)
|
|
162
|
+
$gp.AddArc($w - $r - 1, $h - $r - 1, $r, $r, 0, 90)
|
|
163
|
+
$gp.AddArc(0, $h - $r - 1, $r, $r, 90, 90)
|
|
164
|
+
$gp.CloseFigure()
|
|
165
|
+
$form.Region = New-Object System.Drawing.Region($gp)
|
|
166
|
+
|
|
167
|
+
$lbl = New-Object System.Windows.Forms.Label
|
|
168
|
+
$lbl.ForeColor = [System.Drawing.Color]::White
|
|
169
|
+
$lbl.Font = New-Object System.Drawing.Font("Segoe UI Semibold", 10.5)
|
|
170
|
+
$lbl.AutoSize = $false
|
|
171
|
+
$lbl.Dock = 'Fill'
|
|
172
|
+
$lbl.TextAlign = 'MiddleCenter'
|
|
173
|
+
$lbl.BackColor = [System.Drawing.Color]::Transparent
|
|
174
|
+
$form.Controls.Add($lbl)
|
|
175
|
+
|
|
176
|
+
$st = @{ vis = $false; f = 0 }
|
|
177
|
+
$dots = @([char]0x25CF, [char]0x25C9, [char]0x25CF, [char]0x25CB)
|
|
178
|
+
|
|
179
|
+
$tmr = New-Object System.Windows.Forms.Timer
|
|
180
|
+
$tmr.Interval = 150
|
|
181
|
+
$tmr.Add_Tick({
|
|
182
|
+
# Check exit signal
|
|
183
|
+
if ([IO.File]::Exists($ExitFile)) {
|
|
184
|
+
try { [IO.File]::Delete($ExitFile) } catch {}
|
|
185
|
+
$tmr.Stop(); $form.Close(); return
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if ([IO.File]::Exists($SignalFile)) {
|
|
189
|
+
$m = 'recording'
|
|
190
|
+
try { $m = [IO.File]::ReadAllText($SignalFile).Trim() } catch {}
|
|
191
|
+
|
|
192
|
+
if (-not $st.vis) {
|
|
193
|
+
$form.Show(); $form.BringToFront()
|
|
194
|
+
$st.vis = $true; $st.f = 0
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if ($m -eq 'transcribing') {
|
|
198
|
+
$form.BackColor = [System.Drawing.Color]::FromArgb(38, 32, 14)
|
|
199
|
+
$lbl.ForeColor = [System.Drawing.Color]::FromArgb(255, 210, 80)
|
|
200
|
+
$spin = @([char]0x2836, [char]0x2834, [char]0x2826, [char]0x2807, [char]0x280B, [char]0x2819, [char]0x2838, [char]0x2830)
|
|
201
|
+
$lbl.Text = $spin[$st.f % 8] + ' Transcribing...'
|
|
202
|
+
} else {
|
|
203
|
+
$form.BackColor = [System.Drawing.Color]::FromArgb(38, 14, 14)
|
|
204
|
+
$lbl.ForeColor = [System.Drawing.Color]::FromArgb(255, 90, 90)
|
|
205
|
+
$d = $dots[$st.f % 4]
|
|
206
|
+
$lbl.Text = "$d Recording..."
|
|
207
|
+
}
|
|
208
|
+
$st.f++
|
|
209
|
+
} elseif ($st.vis) {
|
|
210
|
+
$form.Hide()
|
|
211
|
+
$st.vis = $false
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
# Hide immediately on shown, then start polling
|
|
216
|
+
$form.Add_Shown({ $form.Hide(); $tmr.Start() })
|
|
217
|
+
[System.Windows.Forms.Application]::Run($form)
|
|
218
|
+
`;
|