aicodeman 1.50.0 → 1.51.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/README.md +17 -10
- package/dist/config/attachment-guard.d.ts +5 -1
- package/dist/config/attachment-guard.d.ts.map +1 -1
- package/dist/config/attachment-guard.js +4 -2
- package/dist/config/attachment-guard.js.map +1 -1
- package/dist/config/cli-registry/schema.d.ts +2 -0
- package/dist/config/cli-registry/schema.d.ts.map +1 -1
- package/dist/config/cli-registry/schema.js +11 -0
- package/dist/config/cli-registry/schema.js.map +1 -1
- package/dist/config/cli-registry/stock.d.ts.map +1 -1
- package/dist/config/cli-registry/stock.js +155 -4
- package/dist/config/cli-registry/stock.js.map +1 -1
- package/dist/config/cli-registry/types.d.ts +33 -2
- package/dist/config/cli-registry/types.d.ts.map +1 -1
- package/dist/config/file-editing.d.ts +7 -3
- package/dist/config/file-editing.d.ts.map +1 -1
- package/dist/config/file-editing.js +12 -3
- package/dist/config/file-editing.js.map +1 -1
- package/dist/config/local-model-catalog.d.ts +95 -20
- package/dist/config/local-model-catalog.d.ts.map +1 -1
- package/dist/config/local-model-catalog.js +172 -37
- package/dist/config/local-model-catalog.js.map +1 -1
- package/dist/config-backup.js +1 -1
- package/dist/config-backup.js.map +1 -1
- package/dist/custom-model-injection.d.ts.map +1 -1
- package/dist/custom-model-injection.js +22 -14
- package/dist/custom-model-injection.js.map +1 -1
- package/dist/hooks-config.d.ts +62 -0
- package/dist/hooks-config.d.ts.map +1 -1
- package/dist/hooks-config.js +156 -0
- package/dist/hooks-config.js.map +1 -1
- package/dist/local-model/connect.d.ts +16 -2
- package/dist/local-model/connect.d.ts.map +1 -1
- package/dist/local-model/connect.js +17 -3
- package/dist/local-model/connect.js.map +1 -1
- package/dist/local-model/harness-facts.d.ts +8 -4
- package/dist/local-model/harness-facts.d.ts.map +1 -1
- package/dist/local-model/harness-facts.js +13 -5
- package/dist/local-model/harness-facts.js.map +1 -1
- package/dist/local-model/install-job.d.ts +208 -28
- package/dist/local-model/install-job.d.ts.map +1 -1
- package/dist/local-model/install-job.js +856 -94
- package/dist/local-model/install-job.js.map +1 -1
- package/dist/local-model/recommend.d.ts +11 -5
- package/dist/local-model/recommend.d.ts.map +1 -1
- package/dist/local-model/recommend.js +11 -5
- package/dist/local-model/recommend.js.map +1 -1
- package/dist/local-model/runtime.d.ts +12 -0
- package/dist/local-model/runtime.d.ts.map +1 -1
- package/dist/local-model/runtime.js +42 -0
- package/dist/local-model/runtime.js.map +1 -1
- package/dist/local-model/state-store.d.ts.map +1 -1
- package/dist/local-model/state-store.js +40 -0
- package/dist/local-model/state-store.js.map +1 -1
- package/dist/mux-interface.d.ts +3 -1
- package/dist/mux-interface.d.ts.map +1 -1
- package/dist/proc-tree.d.ts +23 -0
- package/dist/proc-tree.d.ts.map +1 -1
- package/dist/proc-tree.js +28 -0
- package/dist/proc-tree.js.map +1 -1
- package/dist/session-auto-ops.d.ts +95 -8
- package/dist/session-auto-ops.d.ts.map +1 -1
- package/dist/session-auto-ops.js +146 -32
- package/dist/session-auto-ops.js.map +1 -1
- package/dist/session-cli-registry-bridge.d.ts +2 -1
- package/dist/session-cli-registry-bridge.d.ts.map +1 -1
- package/dist/session-cli-registry-bridge.js.map +1 -1
- package/dist/session.d.ts +16 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +29 -5
- package/dist/session.js.map +1 -1
- package/dist/tmux-manager.d.ts +10 -1
- package/dist/tmux-manager.d.ts.map +1 -1
- package/dist/tmux-manager.js +45 -6
- package/dist/tmux-manager.js.map +1 -1
- package/dist/tui/tui-app.d.ts.map +1 -1
- package/dist/tui/tui-app.js +1 -0
- package/dist/tui/tui-app.js.map +1 -1
- package/dist/tui/tui-client.d.ts +1 -1
- package/dist/tui/tui-client.d.ts.map +1 -1
- package/dist/types/common.d.ts +5 -0
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/local-model-install.d.ts +202 -15
- package/dist/types/local-model-install.d.ts.map +1 -1
- package/dist/types/local-model-install.js +21 -4
- package/dist/types/local-model-install.js.map +1 -1
- package/dist/types/local-model.d.ts +32 -6
- package/dist/types/local-model.d.ts.map +1 -1
- package/dist/types/local-model.js.map +1 -1
- package/dist/types/session.d.ts +26 -4
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js +2 -1
- package/dist/types/session.js.map +1 -1
- package/dist/usage-telemetry.d.ts +3 -0
- package/dist/usage-telemetry.d.ts.map +1 -1
- package/dist/usage-telemetry.js +4 -0
- package/dist/usage-telemetry.js.map +1 -1
- package/dist/utils/token-validation.d.ts +3 -3
- package/dist/utils/token-validation.d.ts.map +1 -1
- package/dist/utils/token-validation.js +3 -3
- package/dist/utils/token-validation.js.map +1 -1
- package/dist/web/case-state-sync.d.ts +28 -0
- package/dist/web/case-state-sync.d.ts.map +1 -0
- package/dist/web/case-state-sync.js +41 -0
- package/dist/web/case-state-sync.js.map +1 -0
- package/dist/web/public/admin-ui.js.gz +0 -0
- package/dist/web/public/api-client.c9b1cddc.js.gz +0 -0
- package/dist/web/public/{app.8719143d.js → app.bddc2382.js} +9 -7
- package/dist/web/public/app.bddc2382.js.br +0 -0
- package/dist/web/public/app.bddc2382.js.gz +0 -0
- package/dist/web/public/approvals-ui.js.gz +0 -0
- package/dist/web/public/constants.782170e1.js.gz +0 -0
- package/dist/web/public/cron-ui.js.gz +0 -0
- package/dist/web/public/edit-history-ui.js.gz +0 -0
- package/dist/web/public/entrance-animations.js.gz +0 -0
- package/dist/web/public/foreign-sessions.js.gz +0 -0
- package/dist/web/public/git-status-ui.js.gz +0 -0
- package/dist/web/public/header-divider.eb2d2463.js.gz +0 -0
- package/dist/web/public/home-sessions.js +38 -18
- package/dist/web/public/home-sessions.js.br +0 -0
- package/dist/web/public/home-sessions.js.gz +0 -0
- package/dist/web/public/host-wake-ui.js.gz +0 -0
- package/dist/web/public/i18n.2e0cdcee.js +2 -0
- package/dist/web/public/i18n.2e0cdcee.js.br +0 -0
- package/dist/web/public/i18n.2e0cdcee.js.gz +0 -0
- package/dist/web/public/{image-input.a5d0f8f3.js → image-input.b75c41ca.js} +17 -1
- package/dist/web/public/image-input.b75c41ca.js.br +0 -0
- package/dist/web/public/image-input.b75c41ca.js.gz +0 -0
- package/dist/web/public/index.html +39 -15
- package/dist/web/public/index.html.br +0 -0
- package/dist/web/public/index.html.gz +0 -0
- package/dist/web/public/input-cjk.8bc46081.js.gz +0 -0
- package/dist/web/public/{keyboard-accessory.b941676c.js → keyboard-accessory.0800fc44.js} +160 -2
- package/dist/web/public/keyboard-accessory.0800fc44.js.br +0 -0
- package/dist/web/public/keyboard-accessory.0800fc44.js.gz +0 -0
- package/dist/web/public/local-model-ui.js +618 -32
- package/dist/web/public/local-model-ui.js.br +0 -0
- package/dist/web/public/local-model-ui.js.gz +0 -0
- package/dist/web/public/mobile-handlers.f7c3f692.js.gz +0 -0
- package/dist/web/public/mobile-ime-preview.2dbaf262.js.gz +0 -0
- package/dist/web/public/mobile-overview.js +31 -14
- package/dist/web/public/mobile-overview.js.br +0 -0
- package/dist/web/public/mobile-overview.js.gz +0 -0
- package/dist/web/public/mobile.984e9058.css +1 -0
- package/dist/web/public/mobile.984e9058.css.br +0 -0
- package/dist/web/public/mobile.984e9058.css.gz +0 -0
- package/dist/web/public/notification-manager.feb82c04.js.gz +0 -0
- package/dist/web/public/orchestrator-panel.js.gz +0 -0
- package/dist/web/public/{panels-ui.d3f4f1c4.js → panels-ui.ee2330a4.js} +99 -97
- package/dist/web/public/panels-ui.ee2330a4.js.br +0 -0
- package/dist/web/public/panels-ui.ee2330a4.js.gz +0 -0
- package/dist/web/public/ralph-panel.b350e2ef.js.gz +0 -0
- package/dist/web/public/ralph-wizard.b6c0dd19.js.gz +0 -0
- package/dist/web/public/readmymind-ui.js.gz +0 -0
- package/dist/web/public/reboot-restore-ui.js.gz +0 -0
- package/dist/web/public/respawn-ui.304ba0d4.js.gz +0 -0
- package/dist/web/public/sanitize-html.e7147e76.js.gz +0 -0
- package/dist/web/public/session-lineage.js.gz +0 -0
- package/dist/web/public/session-ui.4273cbc5.js +106 -0
- package/dist/web/public/session-ui.4273cbc5.js.br +0 -0
- package/dist/web/public/session-ui.4273cbc5.js.gz +0 -0
- package/dist/web/public/{settings-ui.11da6f15.js → settings-ui.8b37cf07.js} +14 -14
- package/dist/web/public/settings-ui.8b37cf07.js.br +0 -0
- package/dist/web/public/settings-ui.8b37cf07.js.gz +0 -0
- package/dist/web/public/spreadsheet-preview-worker.js.gz +0 -0
- package/dist/web/public/spreadsheet-preview.75c751de.js.gz +0 -0
- package/dist/web/public/spreadsheet-xlsx-core.js.gz +0 -0
- package/dist/web/public/styles.81d95f50.css +1 -0
- package/dist/web/public/styles.81d95f50.css.br +0 -0
- package/dist/web/public/styles.81d95f50.css.gz +0 -0
- package/dist/web/public/subagent-windows.07277a58.js.gz +0 -0
- package/dist/web/public/sw.js +2 -2
- package/dist/web/public/sw.js.br +0 -0
- package/dist/web/public/sw.js.gz +0 -0
- package/dist/web/public/tab-layout-browser.2d6189f7.js.gz +0 -0
- package/dist/web/public/tab-rail-resize.b5cdceaf.js.gz +0 -0
- package/dist/web/public/terminal-keycode229-recovery.98843069.js.gz +0 -0
- package/dist/web/public/terminal-split.js.gz +0 -0
- package/dist/web/public/terminal-tile.js +1 -1
- package/dist/web/public/terminal-tile.js.br +0 -0
- package/dist/web/public/terminal-tile.js.gz +0 -0
- package/dist/web/public/{terminal-ui.f92eae28.js → terminal-ui.8e4c2017.js} +1 -1
- package/dist/web/public/terminal-ui.8e4c2017.js.br +0 -0
- package/dist/web/public/terminal-ui.8e4c2017.js.gz +0 -0
- package/dist/web/public/tile-grid.js.gz +0 -0
- package/dist/web/public/ultracode-panel.js.gz +0 -0
- package/dist/web/public/ultracode-windows.js.gz +0 -0
- package/dist/web/public/vendor/dompurify.min.js.gz +0 -0
- package/dist/web/public/vendor/exceljs.min.js.gz +0 -0
- package/dist/web/public/vendor/fflate.min.js.gz +0 -0
- package/dist/web/public/vendor/marked.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-serialize.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-predictive-echo.276b11d9.js.gz +0 -0
- package/dist/web/public/vendor/xterm-zerolag-input.1be42307.js.gz +0 -0
- package/dist/web/public/vendor/xterm.css.gz +0 -0
- package/dist/web/public/vendor/xterm.min.js.gz +0 -0
- package/dist/web/public/{voice-input.2342c37b.js → voice-input.d0580528.js} +232 -137
- package/dist/web/public/voice-input.d0580528.js.br +0 -0
- package/dist/web/public/voice-input.d0580528.js.gz +0 -0
- package/dist/web/public/voice-pcm-worklet.js.gz +0 -0
- package/dist/web/public/webview-tabs.js.gz +0 -0
- package/dist/web/public/whats-new.json +9 -9
- package/dist/web/routes/case-routes.d.ts.map +1 -1
- package/dist/web/routes/case-routes.js +31 -5
- package/dist/web/routes/case-routes.js.map +1 -1
- package/dist/web/routes/file-routes.d.ts +4 -2
- package/dist/web/routes/file-routes.d.ts.map +1 -1
- package/dist/web/routes/file-routes.js +112 -6
- package/dist/web/routes/file-routes.js.map +1 -1
- package/dist/web/routes/hook-event-routes.d.ts.map +1 -1
- package/dist/web/routes/hook-event-routes.js +45 -16
- package/dist/web/routes/hook-event-routes.js.map +1 -1
- package/dist/web/routes/local-model-routes.d.ts +18 -6
- package/dist/web/routes/local-model-routes.d.ts.map +1 -1
- package/dist/web/routes/local-model-routes.js +47 -10
- package/dist/web/routes/local-model-routes.js.map +1 -1
- package/dist/web/routes/session-routes.d.ts.map +1 -1
- package/dist/web/routes/session-routes.js +52 -4
- package/dist/web/routes/session-routes.js.map +1 -1
- package/dist/web/routes/status-telemetry-routes.d.ts.map +1 -1
- package/dist/web/routes/status-telemetry-routes.js +6 -0
- package/dist/web/routes/status-telemetry-routes.js.map +1 -1
- package/dist/web/routes/system-routes.d.ts +2 -2
- package/dist/web/routes/system-routes.d.ts.map +1 -1
- package/dist/web/routes/system-routes.js +35 -4
- package/dist/web/routes/system-routes.js.map +1 -1
- package/dist/web/schemas.d.ts +30 -0
- package/dist/web/schemas.d.ts.map +1 -1
- package/dist/web/schemas.js +56 -4
- package/dist/web/schemas.js.map +1 -1
- package/dist/web/sensitive-path.d.ts +8 -1
- package/dist/web/sensitive-path.d.ts.map +1 -1
- package/dist/web/sensitive-path.js +23 -4
- package/dist/web/sensitive-path.js.map +1 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +1 -0
- package/dist/web/server.js.map +1 -1
- package/dist/web/session-wait-registry.d.ts +19 -4
- package/dist/web/session-wait-registry.d.ts.map +1 -1
- package/dist/web/session-wait-registry.js +26 -5
- package/dist/web/session-wait-registry.js.map +1 -1
- package/dist/web/voice-stream.d.ts +4 -3
- package/dist/web/voice-stream.d.ts.map +1 -1
- package/dist/web/voice-stream.js +5 -4
- package/dist/web/voice-stream.js.map +1 -1
- package/package.json +1 -1
- package/skills/codeman/SKILL.md +147 -42
- package/skills/codeman/preamble.sh +102 -26
- package/skills/codeman/reference/endpoints.md +13 -9
- package/skills/codeman/reference/messaging.md +2 -2
- package/skills/codeman/reference/recipes.md +2 -2
- package/skills/codeman/reference/verbs.md +46 -15
- package/dist/web/public/app.8719143d.js.br +0 -0
- package/dist/web/public/app.8719143d.js.gz +0 -0
- package/dist/web/public/i18n.1e96a258.js +0 -2
- package/dist/web/public/i18n.1e96a258.js.br +0 -0
- package/dist/web/public/i18n.1e96a258.js.gz +0 -0
- package/dist/web/public/image-input.a5d0f8f3.js.br +0 -0
- package/dist/web/public/image-input.a5d0f8f3.js.gz +0 -0
- package/dist/web/public/keyboard-accessory.b941676c.js.br +0 -0
- package/dist/web/public/keyboard-accessory.b941676c.js.gz +0 -0
- package/dist/web/public/mobile.4dfd5c55.css +0 -1
- package/dist/web/public/mobile.4dfd5c55.css.br +0 -0
- package/dist/web/public/mobile.4dfd5c55.css.gz +0 -0
- package/dist/web/public/panels-ui.d3f4f1c4.js.br +0 -0
- package/dist/web/public/panels-ui.d3f4f1c4.js.gz +0 -0
- package/dist/web/public/session-ui.a7c8c095.js +0 -106
- package/dist/web/public/session-ui.a7c8c095.js.br +0 -0
- package/dist/web/public/session-ui.a7c8c095.js.gz +0 -0
- package/dist/web/public/settings-ui.11da6f15.js.br +0 -0
- package/dist/web/public/settings-ui.11da6f15.js.gz +0 -0
- package/dist/web/public/styles.63382d6e.css +0 -1
- package/dist/web/public/styles.63382d6e.css.br +0 -0
- package/dist/web/public/styles.63382d6e.css.gz +0 -0
- package/dist/web/public/terminal-ui.f92eae28.js.br +0 -0
- package/dist/web/public/terminal-ui.f92eae28.js.gz +0 -0
- package/dist/web/public/voice-input.2342c37b.js.br +0 -0
- package/dist/web/public/voice-input.2342c37b.js.gz +0 -0
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
* auto-detects MIME type (opus/webm/mp4), and supports custom key terms for dev vocabulary.
|
|
15
15
|
*
|
|
16
16
|
* - VoiceInput — High-level voice input controller. Toggle mode: tap mic to start, tap
|
|
17
|
-
* again to stop. Auto-stops after
|
|
17
|
+
* again to stop. Auto-stops after configurable silence. Shows floating preview overlay with recording
|
|
18
18
|
* indicator, level meter (AnalyserNode), and elapsed timer. Two insert modes: "direct"
|
|
19
19
|
* (inject into local echo overlay or PTY) and "compose" (editable textarea overlay).
|
|
20
20
|
* Includes a temporary green Send button that replaces the settings gear icon after voice input.
|
|
21
|
-
* Web Speech API
|
|
21
|
+
* Web Speech API retries empty runs twice with backoff and preserves late results after Stop.
|
|
22
22
|
*
|
|
23
23
|
* @globals {object} ClaudeVoiceProvider
|
|
24
24
|
* @globals {object} DeepgramProvider
|
|
@@ -216,9 +216,12 @@ const DeepgramProvider = {
|
|
|
216
216
|
|
|
217
217
|
_resetSilenceTimeout() {
|
|
218
218
|
clearTimeout(this._silenceTimeout);
|
|
219
|
+
this._silenceTimeout = null;
|
|
220
|
+
const delay = VoiceInput.getSilenceTimeoutMs(3000);
|
|
221
|
+
if (delay === 0) return;
|
|
219
222
|
this._silenceTimeout = setTimeout(() => {
|
|
220
223
|
this.stop();
|
|
221
|
-
},
|
|
224
|
+
}, delay);
|
|
222
225
|
},
|
|
223
226
|
|
|
224
227
|
stop() {
|
|
@@ -269,8 +272,8 @@ const DeepgramProvider = {
|
|
|
269
272
|
* DeepgramProvider's recorder. The AudioContext is constructed at 16000 Hz so the
|
|
270
273
|
* browser does the resampling.
|
|
271
274
|
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
275
|
+
* Transcript frames cover the current utterance. Replace interims and append
|
|
276
|
+
* each endpoint final once; an endpoint alone does not end the recording.
|
|
274
277
|
*/
|
|
275
278
|
const ClaudeVoiceProvider = {
|
|
276
279
|
_ws: null,
|
|
@@ -284,6 +287,8 @@ const ClaudeVoiceProvider = {
|
|
|
284
287
|
_onError: null,
|
|
285
288
|
_onEnd: null,
|
|
286
289
|
_finalized: false,
|
|
290
|
+
_finalizeTimeout: null,
|
|
291
|
+
_generation: 0,
|
|
287
292
|
|
|
288
293
|
/** How long without any transcript before the recording gives up on its own. */
|
|
289
294
|
SILENCE_MS: 6000,
|
|
@@ -293,6 +298,8 @@ const ClaudeVoiceProvider = {
|
|
|
293
298
|
* @param {object} opts - { language, keyterms[], onResult(text, isFinal), onError(msg), onEnd(), onStream(stream) }
|
|
294
299
|
*/
|
|
295
300
|
async start(opts) {
|
|
301
|
+
this._cleanup();
|
|
302
|
+
const generation = this._generation;
|
|
296
303
|
this._onResult = opts.onResult;
|
|
297
304
|
this._onError = opts.onError;
|
|
298
305
|
this._onEnd = opts.onEnd;
|
|
@@ -304,10 +311,17 @@ const ClaudeVoiceProvider = {
|
|
|
304
311
|
return;
|
|
305
312
|
}
|
|
306
313
|
try {
|
|
307
|
-
|
|
314
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
308
315
|
audio: { noiseSuppression: true, echoCancellation: true, autoGainControl: true }
|
|
309
316
|
});
|
|
317
|
+
// Permission prompts can resolve after Stop/reconnect or a newer recording.
|
|
318
|
+
if (generation !== this._generation || this._finalized) {
|
|
319
|
+
stream.getTracks().forEach(t => t.stop());
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
this._stream = stream;
|
|
310
323
|
} catch (err) {
|
|
324
|
+
if (generation !== this._generation || this._finalized) return;
|
|
311
325
|
const msg = err.name === 'NotAllowedError'
|
|
312
326
|
? 'Microphone access denied. Check browser settings.'
|
|
313
327
|
: 'Microphone error: ' + err.message;
|
|
@@ -331,10 +345,12 @@ const ClaudeVoiceProvider = {
|
|
|
331
345
|
this._ws.binaryType = 'arraybuffer';
|
|
332
346
|
|
|
333
347
|
this._ws.onopen = () => {
|
|
348
|
+
if (generation !== this._generation || this._finalized) return;
|
|
334
349
|
// Capture starts only once the socket is up: PCM buffered before that would
|
|
335
350
|
// be the oldest audio, and dropping it keeps the transcript aligned with what
|
|
336
351
|
// the user hears themselves saying.
|
|
337
|
-
this._startCapture().catch((err) => {
|
|
352
|
+
this._startCapture(generation).catch((err) => {
|
|
353
|
+
if (generation !== this._generation || this._finalized) return;
|
|
338
354
|
this._onError?.('Microphone capture failed: ' + err.message);
|
|
339
355
|
this.stop();
|
|
340
356
|
});
|
|
@@ -342,6 +358,7 @@ const ClaudeVoiceProvider = {
|
|
|
342
358
|
};
|
|
343
359
|
|
|
344
360
|
this._ws.onmessage = (event) => {
|
|
361
|
+
if (generation !== this._generation) return;
|
|
345
362
|
let msg;
|
|
346
363
|
try {
|
|
347
364
|
msg = JSON.parse(event.data);
|
|
@@ -361,6 +378,7 @@ const ClaudeVoiceProvider = {
|
|
|
361
378
|
};
|
|
362
379
|
|
|
363
380
|
this._ws.onclose = (event) => {
|
|
381
|
+
if (generation !== this._generation) return;
|
|
364
382
|
if (event.code === 4004) {
|
|
365
383
|
this._onError?.(this._unavailableMessage(event.reason));
|
|
366
384
|
} else if (event.code === 4008) {
|
|
@@ -385,16 +403,19 @@ const ClaudeVoiceProvider = {
|
|
|
385
403
|
},
|
|
386
404
|
|
|
387
405
|
/** Wire mic -> 16 kHz PCM16 frames -> WebSocket. */
|
|
388
|
-
async _startCapture() {
|
|
406
|
+
async _startCapture(generation = this._generation) {
|
|
407
|
+
if (generation !== this._generation || this._finalized) return;
|
|
389
408
|
const Ctx = window.AudioContext || window.webkitAudioContext;
|
|
390
409
|
// Ask for 16 kHz directly so the browser resamples; Safari may hand back its
|
|
391
410
|
// own rate, which _pcmFromFloat32 then downsamples to match.
|
|
392
411
|
this._audioContext = new Ctx({ sampleRate: 16000 });
|
|
393
412
|
if (this._audioContext.state === 'suspended') await this._audioContext.resume();
|
|
413
|
+
if (generation !== this._generation || this._finalized) return;
|
|
394
414
|
this._sourceNode = this._audioContext.createMediaStreamSource(this._stream);
|
|
395
415
|
|
|
396
416
|
if (this._audioContext.audioWorklet) {
|
|
397
417
|
await this._audioContext.audioWorklet.addModule(this._workletUrl());
|
|
418
|
+
if (generation !== this._generation || this._finalized) return;
|
|
398
419
|
this._workletNode = new AudioWorkletNode(this._audioContext, 'pcm-frame-processor');
|
|
399
420
|
this._workletNode.port.onmessage = (event) => this._sendAudio(event.data);
|
|
400
421
|
this._sourceNode.connect(this._workletNode);
|
|
@@ -455,7 +476,10 @@ const ClaudeVoiceProvider = {
|
|
|
455
476
|
|
|
456
477
|
_resetSilenceTimeout() {
|
|
457
478
|
clearTimeout(this._silenceTimeout);
|
|
458
|
-
this._silenceTimeout =
|
|
479
|
+
this._silenceTimeout = null;
|
|
480
|
+
const delay = VoiceInput.getSilenceTimeoutMs(this.SILENCE_MS);
|
|
481
|
+
if (delay === 0) return;
|
|
482
|
+
this._silenceTimeout = setTimeout(() => this.stop(), delay);
|
|
459
483
|
},
|
|
460
484
|
|
|
461
485
|
/**
|
|
@@ -469,6 +493,13 @@ const ClaudeVoiceProvider = {
|
|
|
469
493
|
if (this._finalized) return;
|
|
470
494
|
this._finalized = true;
|
|
471
495
|
this._stopCapture();
|
|
496
|
+
// Bound both manual and silence-triggered finalization on a dead connection.
|
|
497
|
+
// Repeated stop requests return above, so they cannot extend this deadline.
|
|
498
|
+
this._finalizeTimeout = setTimeout(() => {
|
|
499
|
+
const onEnd = this._onEnd;
|
|
500
|
+
this._cleanup();
|
|
501
|
+
onEnd?.();
|
|
502
|
+
}, 5000);
|
|
472
503
|
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
473
504
|
try {
|
|
474
505
|
this._ws.send(JSON.stringify({ t: 'finalize' }));
|
|
@@ -510,15 +541,19 @@ const ClaudeVoiceProvider = {
|
|
|
510
541
|
|
|
511
542
|
/** Hard stop: drop the socket without waiting for a final transcript. */
|
|
512
543
|
_cleanup() {
|
|
544
|
+
this._generation++;
|
|
513
545
|
this._finalized = true;
|
|
546
|
+
clearTimeout(this._finalizeTimeout);
|
|
547
|
+
this._finalizeTimeout = null;
|
|
514
548
|
clearTimeout(this._silenceTimeout);
|
|
515
549
|
this._silenceTimeout = null;
|
|
516
550
|
this._stopCapture();
|
|
517
551
|
if (this._ws) {
|
|
552
|
+
this._ws.onopen = null;
|
|
518
553
|
this._ws.onclose = null;
|
|
519
554
|
this._ws.onmessage = null;
|
|
520
555
|
this._ws.onerror = null;
|
|
521
|
-
if (this._ws.readyState === WebSocket.OPEN) {
|
|
556
|
+
if (this._ws.readyState === WebSocket.OPEN || this._ws.readyState === WebSocket.CONNECTING) {
|
|
522
557
|
try { this._ws.close(1000); } catch (_e) { /* ignore */ }
|
|
523
558
|
}
|
|
524
559
|
this._ws = null;
|
|
@@ -537,18 +572,27 @@ const ClaudeVoiceProvider = {
|
|
|
537
572
|
* Inserts final text into the active session (user presses Enter to submit).
|
|
538
573
|
*/
|
|
539
574
|
const VoiceInput = {
|
|
575
|
+
SILENCE_TIMEOUT_SECONDS: Object.freeze([0, 3, 6, 15, 30]),
|
|
576
|
+
WEB_SPEECH_INSTANT_END_MS: 1000, // an empty run shorter than this counts toward the retry cap
|
|
540
577
|
recognition: null,
|
|
541
578
|
isRecording: false,
|
|
542
579
|
supported: false,
|
|
543
580
|
silenceTimeout: null,
|
|
544
581
|
previewEl: null,
|
|
545
|
-
_lastTranscript: '',
|
|
546
|
-
_stabilityTimer: null,
|
|
547
582
|
_accumulatedFinal: '',
|
|
548
|
-
|
|
583
|
+
_pendingInterim: '',
|
|
584
|
+
_webSpeechCommitted: '', // Text from completed native recognition runs.
|
|
585
|
+
_webSpeechSingleUtterance: false,
|
|
586
|
+
_webSpeechSoundActive: false,
|
|
587
|
+
_webSpeechActivityUntil: 0,
|
|
588
|
+
_webSpeechStopping: false,
|
|
589
|
+
_webSpeechStopTimer: null,
|
|
590
|
+
_webSpeechRestartTimer: null,
|
|
591
|
+
_activeProvider: null, // 'claude' | 'deepgram' | 'webspeech' | null
|
|
549
592
|
_recordingStartedAt: 0, // timestamp when recording started
|
|
550
|
-
_retryCount: 0, //
|
|
551
|
-
_hasReceivedResult: false, // whether
|
|
593
|
+
_retryCount: 0, // consecutive Web Speech runs that ended empty right after starting
|
|
594
|
+
_hasReceivedResult: false, // whether this native recognition run received speech
|
|
595
|
+
_webSpeechRunStartedAt: 0, // when the current native recognition run was started
|
|
552
596
|
_durationInterval: null, // timer for updating elapsed time display
|
|
553
597
|
_analyser: null, // AudioContext analyser for level meter
|
|
554
598
|
_analyserSource: null, // MediaStreamSource for level meter
|
|
@@ -599,6 +643,12 @@ const VoiceInput = {
|
|
|
599
643
|
}
|
|
600
644
|
},
|
|
601
645
|
|
|
646
|
+
/** Seconds in settings; zero means stop only when the user asks. */
|
|
647
|
+
getSilenceTimeoutMs(fallback) {
|
|
648
|
+
const seconds = this._getDeepgramConfig().silenceTimeout;
|
|
649
|
+
return this.SILENCE_TIMEOUT_SECONDS.includes(seconds) ? seconds * 1000 : fallback;
|
|
650
|
+
},
|
|
651
|
+
|
|
602
652
|
_saveDeepgramConfig(config) {
|
|
603
653
|
localStorage.setItem('codeman-voice-settings', JSON.stringify(config));
|
|
604
654
|
},
|
|
@@ -648,7 +698,18 @@ const VoiceInput = {
|
|
|
648
698
|
if (!this.supported) return;
|
|
649
699
|
|
|
650
700
|
this.recognition = new SR();
|
|
651
|
-
|
|
701
|
+
// Android's continuous bridge promotes growing partials to separate finals.
|
|
702
|
+
// Single-utterance mode keeps refinements provisional; onend resumes the mic
|
|
703
|
+
// while our own silence deadline controls the overall dictation session.
|
|
704
|
+
// Android tablets in desktop-site mode may identify as touch-capable Linux.
|
|
705
|
+
// ChromeOS also reports Linux but says CrOS, so it keeps continuous mode.
|
|
706
|
+
// A Linux laptop with a touchscreen still matches; single-utterance works
|
|
707
|
+
// there too, with one native restart per phrase.
|
|
708
|
+
const ua = navigator.userAgent || '';
|
|
709
|
+
this._webSpeechSingleUtterance = navigator.userAgentData?.platform === 'Android'
|
|
710
|
+
|| /Android/i.test(ua)
|
|
711
|
+
|| (navigator.maxTouchPoints > 0 && /Linux/i.test(navigator.platform || '') && !/CrOS/.test(ua));
|
|
712
|
+
this.recognition.continuous = !this._webSpeechSingleUtterance;
|
|
652
713
|
this.recognition.interimResults = true;
|
|
653
714
|
this.recognition.lang = 'en-US';
|
|
654
715
|
this.recognition.maxAlternatives = 1;
|
|
@@ -656,6 +717,8 @@ const VoiceInput = {
|
|
|
656
717
|
this.recognition.onresult = (e) => this._onWebSpeechResult(e);
|
|
657
718
|
this.recognition.onerror = (e) => this._onWebSpeechError(e);
|
|
658
719
|
this.recognition.onend = () => this._onWebSpeechEnd();
|
|
720
|
+
this.recognition.onsoundstart = this.recognition.onspeechstart = () => this._onWebSpeechSound(true);
|
|
721
|
+
this.recognition.onsoundend = this.recognition.onspeechend = this.recognition.onaudioend = () => this._onWebSpeechSound(false);
|
|
659
722
|
},
|
|
660
723
|
|
|
661
724
|
toggle() {
|
|
@@ -706,7 +769,7 @@ const VoiceInput = {
|
|
|
706
769
|
this.isRecording = true;
|
|
707
770
|
this._activeProvider = 'claude';
|
|
708
771
|
this._accumulatedFinal = '';
|
|
709
|
-
this.
|
|
772
|
+
this._pendingInterim = '';
|
|
710
773
|
this._hasReceivedResult = false;
|
|
711
774
|
this._recordingStartedAt = Date.now();
|
|
712
775
|
this._updateButtons('recording');
|
|
@@ -725,25 +788,25 @@ const VoiceInput = {
|
|
|
725
788
|
onResult: (text, isFinal) => {
|
|
726
789
|
if (!this.isRecording) return;
|
|
727
790
|
this._hasReceivedResult = true;
|
|
728
|
-
//
|
|
729
|
-
this._accumulatedFinal = text;
|
|
791
|
+
// Interims replace the current utterance; each endpoint commits it once.
|
|
730
792
|
if (isFinal) {
|
|
731
|
-
this.
|
|
732
|
-
this.
|
|
733
|
-
this.stop();
|
|
793
|
+
this._accumulatedFinal = [this._accumulatedFinal, text].filter(Boolean).join(' ');
|
|
794
|
+
this._pendingInterim = '';
|
|
795
|
+
if (ClaudeVoiceProvider._finalized) this.stop(true);
|
|
796
|
+
else this._showPreview(this._accumulatedFinal, 'claude');
|
|
734
797
|
} else {
|
|
735
|
-
this.
|
|
798
|
+
this._pendingInterim = (this._accumulatedFinal ? ' ' : '') + text;
|
|
799
|
+
this._showPreview(this._accumulatedFinal + this._pendingInterim, 'claude');
|
|
736
800
|
}
|
|
737
801
|
},
|
|
738
802
|
onError: (msg) => {
|
|
739
803
|
const wasRecording = this.isRecording;
|
|
740
|
-
this.stop();
|
|
804
|
+
this.stop(true);
|
|
741
805
|
if (wasRecording) app.showToast(msg, 'error');
|
|
742
806
|
},
|
|
743
807
|
onEnd: () => {
|
|
744
808
|
if (this.isRecording) {
|
|
745
|
-
|
|
746
|
-
this.stop();
|
|
809
|
+
this.stop(true);
|
|
747
810
|
}
|
|
748
811
|
}
|
|
749
812
|
});
|
|
@@ -756,7 +819,7 @@ const VoiceInput = {
|
|
|
756
819
|
this.isRecording = true;
|
|
757
820
|
this._activeProvider = 'deepgram';
|
|
758
821
|
this._accumulatedFinal = '';
|
|
759
|
-
this.
|
|
822
|
+
this._pendingInterim = '';
|
|
760
823
|
this._hasReceivedResult = false;
|
|
761
824
|
this._recordingStartedAt = Date.now();
|
|
762
825
|
this._updateButtons('recording');
|
|
@@ -777,12 +840,12 @@ const VoiceInput = {
|
|
|
777
840
|
if (!this.isRecording) return;
|
|
778
841
|
this._hasReceivedResult = true;
|
|
779
842
|
if (isFinal) {
|
|
780
|
-
this._accumulatedFinal += text;
|
|
781
|
-
this.
|
|
782
|
-
this.
|
|
783
|
-
this.stop();
|
|
843
|
+
this._accumulatedFinal += (this._accumulatedFinal ? ' ' : '') + text;
|
|
844
|
+
this._pendingInterim = '';
|
|
845
|
+
this._showPreview(this._accumulatedFinal, 'deepgram');
|
|
784
846
|
} else {
|
|
785
|
-
|
|
847
|
+
this._pendingInterim = (this._accumulatedFinal ? ' ' : '') + text;
|
|
848
|
+
const display = this._accumulatedFinal + this._pendingInterim;
|
|
786
849
|
this._showPreview(display, 'deepgram');
|
|
787
850
|
}
|
|
788
851
|
},
|
|
@@ -793,9 +856,6 @@ const VoiceInput = {
|
|
|
793
856
|
},
|
|
794
857
|
onEnd: () => {
|
|
795
858
|
if (this.isRecording) {
|
|
796
|
-
if (this._accumulatedFinal) {
|
|
797
|
-
this._insertText(this._accumulatedFinal);
|
|
798
|
-
}
|
|
799
859
|
this.stop();
|
|
800
860
|
}
|
|
801
861
|
}
|
|
@@ -818,44 +878,74 @@ const VoiceInput = {
|
|
|
818
878
|
}
|
|
819
879
|
this.isRecording = true;
|
|
820
880
|
this._activeProvider = 'webspeech';
|
|
881
|
+
this._retryCount = 0;
|
|
882
|
+
this._webSpeechCommitted = '';
|
|
883
|
+
this._webSpeechSoundActive = false;
|
|
884
|
+
this._webSpeechActivityUntil = 0;
|
|
821
885
|
this._accumulatedFinal = '';
|
|
822
|
-
this.
|
|
886
|
+
this._pendingInterim = '';
|
|
823
887
|
this._hasReceivedResult = false;
|
|
824
888
|
this._recordingStartedAt = Date.now();
|
|
825
889
|
this._updateButtons('recording');
|
|
826
890
|
this._showPreview('Listening...');
|
|
827
891
|
this._startDurationTimer();
|
|
828
892
|
try {
|
|
893
|
+
this._webSpeechRunStartedAt = Date.now();
|
|
829
894
|
this.recognition.start();
|
|
830
895
|
} catch (e) {
|
|
831
896
|
// InvalidStateError = already started — ignore. Other errors = genuine failure.
|
|
832
897
|
if (e.name !== 'InvalidStateError') {
|
|
833
|
-
this.stop();
|
|
898
|
+
this.stop(true);
|
|
834
899
|
app.showToast('Voice input failed to start: ' + e.message, 'error');
|
|
835
900
|
return;
|
|
836
901
|
}
|
|
837
902
|
}
|
|
838
903
|
this._resetSilenceTimeout();
|
|
839
|
-
//
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
this._startLevelMeter(stream);
|
|
844
|
-
} else {
|
|
845
|
-
stream.getTracks().forEach(t => t.stop());
|
|
846
|
-
}
|
|
847
|
-
}).catch(() => { /* level meter just won't show */ });
|
|
904
|
+
// SpeechRecognition owns its microphone. A second getUserMedia capture for
|
|
905
|
+
// a cosmetic meter can take audio away from Android's recognition service.
|
|
906
|
+
// Streaming providers still meter the same stream they transcribe.
|
|
907
|
+
this._drawLevelMeter();
|
|
848
908
|
// Haptic feedback on mobile
|
|
849
909
|
if (navigator.vibrate) navigator.vibrate(50);
|
|
850
910
|
},
|
|
851
911
|
|
|
852
|
-
stop() {
|
|
912
|
+
stop(providerFinished = false) {
|
|
853
913
|
if (!this.isRecording) return;
|
|
914
|
+
if (this._webSpeechRestartTimer !== null) {
|
|
915
|
+
clearTimeout(this._webSpeechRestartTimer);
|
|
916
|
+
this._webSpeechRestartTimer = null;
|
|
917
|
+
// The recognizer already ended; no onend remains to wait for.
|
|
918
|
+
providerFinished = true;
|
|
919
|
+
}
|
|
920
|
+
// Claude delivers its final transcript after finalize. Keep accepting it
|
|
921
|
+
// until that frame (or onEnd) completes this recording.
|
|
922
|
+
if (this._activeProvider === 'claude' && !providerFinished && ClaudeVoiceProvider._ws?.readyState === WebSocket.OPEN) {
|
|
923
|
+
ClaudeVoiceProvider.stop();
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
if (this._activeProvider === 'webspeech' && !providerFinished) {
|
|
927
|
+
if (this._webSpeechStopping) return;
|
|
928
|
+
this._webSpeechStopping = true;
|
|
929
|
+
clearTimeout(this.silenceTimeout);
|
|
930
|
+
// stop() requests a result; Android may deliver it only before onend.
|
|
931
|
+
// Keep accepting results, with a backstop for engines that never end.
|
|
932
|
+
this._webSpeechStopTimer = setTimeout(() => {
|
|
933
|
+
try { this.recognition?.abort(); } catch (_e) { /* already ended */ }
|
|
934
|
+
this.stop(true);
|
|
935
|
+
}, 3000);
|
|
936
|
+
try { this.recognition?.stop(); } catch (_e) { this.stop(true); }
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
clearTimeout(this._webSpeechStopTimer);
|
|
940
|
+
this._webSpeechStopTimer = null;
|
|
941
|
+
this._webSpeechStopping = false;
|
|
854
942
|
this.isRecording = false;
|
|
943
|
+
const text = this._accumulatedFinal + this._pendingInterim;
|
|
944
|
+
this._accumulatedFinal = '';
|
|
945
|
+
this._pendingInterim = '';
|
|
946
|
+
if (text) this._insertText(text);
|
|
855
947
|
clearTimeout(this.silenceTimeout);
|
|
856
|
-
clearTimeout(this._stabilityTimer);
|
|
857
948
|
this.silenceTimeout = null;
|
|
858
|
-
this._stabilityTimer = null;
|
|
859
949
|
this._retryCount = 0;
|
|
860
950
|
this._stopDurationTimer();
|
|
861
951
|
this._stopLevelMeter();
|
|
@@ -863,21 +953,10 @@ const VoiceInput = {
|
|
|
863
953
|
this._hidePreview();
|
|
864
954
|
|
|
865
955
|
if (this._activeProvider === 'claude') {
|
|
866
|
-
//
|
|
867
|
-
ClaudeVoiceProvider.
|
|
956
|
+
// Completion received, or forced teardown: callbacks must not outlive it.
|
|
957
|
+
ClaudeVoiceProvider._cleanup();
|
|
868
958
|
} else if (this._activeProvider === 'deepgram') {
|
|
869
959
|
DeepgramProvider.stop();
|
|
870
|
-
} else if (this._activeProvider === 'webspeech') {
|
|
871
|
-
try {
|
|
872
|
-
this.recognition?.stop();
|
|
873
|
-
} catch (_e) {
|
|
874
|
-
// Already stopped — ignore
|
|
875
|
-
}
|
|
876
|
-
// Stop the mic stream we opened for the level meter
|
|
877
|
-
if (this._webSpeechStream) {
|
|
878
|
-
this._webSpeechStream.getTracks().forEach(t => t.stop());
|
|
879
|
-
this._webSpeechStream = null;
|
|
880
|
-
}
|
|
881
960
|
}
|
|
882
961
|
this._activeProvider = null;
|
|
883
962
|
|
|
@@ -885,41 +964,44 @@ const VoiceInput = {
|
|
|
885
964
|
if (navigator.vibrate) navigator.vibrate([30, 50, 30]);
|
|
886
965
|
},
|
|
887
966
|
|
|
967
|
+
_onWebSpeechSound(active) {
|
|
968
|
+
if (!this.isRecording || this._activeProvider !== 'webspeech' || this._webSpeechStopping) return;
|
|
969
|
+
this._webSpeechSoundActive = active;
|
|
970
|
+
if (!active) this._webSpeechActivityUntil = 0;
|
|
971
|
+
},
|
|
972
|
+
|
|
888
973
|
_onWebSpeechResult(event) {
|
|
889
974
|
if (!this.isRecording) return;
|
|
890
|
-
this._hasReceivedResult = true;
|
|
891
975
|
this._resetSilenceTimeout();
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
if (finalText) {
|
|
904
|
-
this._accumulatedFinal += finalText;
|
|
905
|
-
this._hidePreview();
|
|
906
|
-
this._insertText(this._accumulatedFinal);
|
|
907
|
-
this.stop();
|
|
908
|
-
} else if (interim) {
|
|
909
|
-
const display = this._accumulatedFinal + interim;
|
|
910
|
-
this._showPreview(display);
|
|
911
|
-
// iOS Safari workaround: isFinal is always false.
|
|
912
|
-
// Detect when interim results stop changing for 750ms → treat as final.
|
|
913
|
-
this._iosStabilityCheck(interim);
|
|
976
|
+
// results is the current run's complete snapshot, not a list of new words.
|
|
977
|
+
// Rebuild by result position so repeats/corrections replace the same text.
|
|
978
|
+
// Never deduplicate by text: "go go" and repeated phrases can be intentional.
|
|
979
|
+
const finals = [];
|
|
980
|
+
const interims = [];
|
|
981
|
+
for (let i = 0; i < event.results.length; i++) {
|
|
982
|
+
const result = event.results[i];
|
|
983
|
+
const text = result[0]?.transcript?.trim();
|
|
984
|
+
if (text) (result.isFinal ? finals : interims).push(text);
|
|
914
985
|
}
|
|
986
|
+
this._accumulatedFinal = [this._webSpeechCommitted, ...finals].filter(Boolean).join(' ');
|
|
987
|
+
const interim = interims.join(' ');
|
|
988
|
+
this._hasReceivedResult ||= finals.length > 0 || !!interim;
|
|
989
|
+
this._pendingInterim = interim ? (this._accumulatedFinal ? ' ' : '') + interim : '';
|
|
990
|
+
this._showPreview(this._accumulatedFinal + this._pendingInterim);
|
|
991
|
+
// Some engines omit sound events; transcript updates are also real evidence
|
|
992
|
+
// of speech activity. This is an activity animation, not an amplitude meter.
|
|
993
|
+
if (finals.length || interim) this._webSpeechActivityUntil = Date.now() + 600;
|
|
915
994
|
},
|
|
916
995
|
|
|
917
996
|
_onWebSpeechError(event) {
|
|
918
997
|
// During auto-retry, 'aborted' and 'no-speech' errors are expected — ignore them
|
|
919
998
|
if (this._retryCount > 0 && (event.error === 'aborted' || event.error === 'no-speech')) return;
|
|
920
999
|
|
|
1000
|
+
// Browser silence events must not override an extended/manual deadline.
|
|
1001
|
+
if (event.error === 'no-speech' && this.getSilenceTimeoutMs(3000) !== 3000) return;
|
|
1002
|
+
|
|
921
1003
|
const wasRecording = this.isRecording;
|
|
922
|
-
this.stop();
|
|
1004
|
+
this.stop(true);
|
|
923
1005
|
if (!wasRecording) return;
|
|
924
1006
|
|
|
925
1007
|
switch (event.error) {
|
|
@@ -943,27 +1025,45 @@ const VoiceInput = {
|
|
|
943
1025
|
_onWebSpeechEnd() {
|
|
944
1026
|
// Recognition ended (browser auto-stopped or we called stop())
|
|
945
1027
|
if (!this.isRecording) return;
|
|
1028
|
+
this._onWebSpeechSound(false);
|
|
1029
|
+
if (this._webSpeechStopping) {
|
|
1030
|
+
this.stop(true);
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
946
1033
|
|
|
947
|
-
|
|
948
|
-
//
|
|
949
|
-
//
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
// If restart fails, fall through to stop
|
|
956
|
-
if (this._accumulatedFinal) this._insertText(this._accumulatedFinal);
|
|
957
|
-
this.stop();
|
|
958
|
-
}
|
|
1034
|
+
// Only a run that ends empty right after start() counts toward the cap: that
|
|
1035
|
+
// is a recognizer that cannot listen. A silent run of normal length is the
|
|
1036
|
+
// engine's own no-speech window, and 30 s or Manual must outlast many of them.
|
|
1037
|
+
const empty = !this._hasReceivedResult;
|
|
1038
|
+
const instant = empty && Date.now() - this._webSpeechRunStartedAt < this.WEB_SPEECH_INSTANT_END_MS;
|
|
1039
|
+
this._retryCount = instant ? this._retryCount + 1 : 0;
|
|
1040
|
+
if (this._retryCount > 2) {
|
|
1041
|
+
this.stop(true);
|
|
959
1042
|
return;
|
|
960
1043
|
}
|
|
961
1044
|
|
|
962
|
-
//
|
|
963
|
-
|
|
964
|
-
|
|
1045
|
+
// Native endpoints must not extend the configured silence deadline.
|
|
1046
|
+
const delay = this.getSilenceTimeoutMs(3000);
|
|
1047
|
+
if (empty || this._webSpeechSingleUtterance || delay === 0 || delay > 3000) {
|
|
1048
|
+
// Commit this run once before the next run resets its result indexes.
|
|
1049
|
+
this._webSpeechCommitted = (this._accumulatedFinal + this._pendingInterim).trim();
|
|
1050
|
+
this._accumulatedFinal = this._webSpeechCommitted;
|
|
1051
|
+
this._pendingInterim = '';
|
|
1052
|
+
const restart = () => {
|
|
1053
|
+
this._webSpeechRestartTimer = null;
|
|
1054
|
+
if (!this.isRecording || this._webSpeechStopping) return;
|
|
1055
|
+
this._hasReceivedResult = false;
|
|
1056
|
+
this._webSpeechRunStartedAt = Date.now();
|
|
1057
|
+
try { this.recognition.start(); } catch (_e) { this.stop(true); }
|
|
1058
|
+
};
|
|
1059
|
+
// A broken or unavailable recognizer must not spin forever in Manual mode.
|
|
1060
|
+
if (empty) this._webSpeechRestartTimer = setTimeout(restart, 250);
|
|
1061
|
+
else restart();
|
|
1062
|
+
return;
|
|
965
1063
|
}
|
|
966
|
-
|
|
1064
|
+
|
|
1065
|
+
// Genuine end — finalize any accumulated text
|
|
1066
|
+
this.stop(true);
|
|
967
1067
|
},
|
|
968
1068
|
|
|
969
1069
|
/** The session this dictation belongs to (see _targetSessionId). */
|
|
@@ -1138,30 +1238,14 @@ const VoiceInput = {
|
|
|
1138
1238
|
|
|
1139
1239
|
_resetSilenceTimeout() {
|
|
1140
1240
|
clearTimeout(this.silenceTimeout);
|
|
1241
|
+
this.silenceTimeout = null;
|
|
1242
|
+
const delay = this.getSilenceTimeoutMs(3000);
|
|
1243
|
+
if (delay === 0) return;
|
|
1141
1244
|
this.silenceTimeout = setTimeout(() => {
|
|
1142
1245
|
if (this.isRecording) {
|
|
1143
|
-
// Finalize any accumulated text before stopping
|
|
1144
|
-
if (this._accumulatedFinal) {
|
|
1145
|
-
this._insertText(this._accumulatedFinal);
|
|
1146
|
-
}
|
|
1147
1246
|
this.stop();
|
|
1148
1247
|
}
|
|
1149
|
-
},
|
|
1150
|
-
},
|
|
1151
|
-
|
|
1152
|
-
_iosStabilityCheck(transcript) {
|
|
1153
|
-
if (transcript !== this._lastTranscript) {
|
|
1154
|
-
this._lastTranscript = transcript;
|
|
1155
|
-
clearTimeout(this._stabilityTimer);
|
|
1156
|
-
this._stabilityTimer = setTimeout(() => {
|
|
1157
|
-
if (this.isRecording) {
|
|
1158
|
-
const finalText = this._accumulatedFinal + transcript;
|
|
1159
|
-
this._hidePreview();
|
|
1160
|
-
this._insertText(finalText);
|
|
1161
|
-
this.stop();
|
|
1162
|
-
}
|
|
1163
|
-
}, 750);
|
|
1164
|
-
}
|
|
1248
|
+
}, delay);
|
|
1165
1249
|
},
|
|
1166
1250
|
|
|
1167
1251
|
_startDurationTimer() {
|
|
@@ -1200,6 +1284,8 @@ const VoiceInput = {
|
|
|
1200
1284
|
},
|
|
1201
1285
|
|
|
1202
1286
|
_stopLevelMeter() {
|
|
1287
|
+
this._webSpeechSoundActive = false;
|
|
1288
|
+
this._webSpeechActivityUntil = 0;
|
|
1203
1289
|
if (this._levelAnimFrame) {
|
|
1204
1290
|
cancelAnimationFrame(this._levelAnimFrame);
|
|
1205
1291
|
this._levelAnimFrame = null;
|
|
@@ -1216,13 +1302,21 @@ const VoiceInput = {
|
|
|
1216
1302
|
},
|
|
1217
1303
|
|
|
1218
1304
|
_drawLevelMeter() {
|
|
1219
|
-
if (!this.
|
|
1220
|
-
|
|
1221
|
-
this.
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1305
|
+
if (!this.isRecording) return;
|
|
1306
|
+
let rms = 0;
|
|
1307
|
+
if (this._activeProvider === 'webspeech') {
|
|
1308
|
+
// The speech API exposes activity events, but no microphone sample level.
|
|
1309
|
+
const active = !this._webSpeechStopping
|
|
1310
|
+
&& (this._webSpeechSoundActive || Date.now() < this._webSpeechActivityUntil);
|
|
1311
|
+
if (active) rms = 0.25 + 0.55 * (1 + Math.sin(Date.now() / 110)) / 2;
|
|
1312
|
+
} else {
|
|
1313
|
+
if (!this._analyser) return;
|
|
1314
|
+
const dataArray = new Uint8Array(this._analyser.frequencyBinCount);
|
|
1315
|
+
this._analyser.getByteFrequencyData(dataArray);
|
|
1316
|
+
let sum = 0;
|
|
1317
|
+
for (let i = 0; i < dataArray.length; i++) sum += dataArray[i] * dataArray[i];
|
|
1318
|
+
rms = Math.sqrt(sum / dataArray.length) / 255;
|
|
1319
|
+
}
|
|
1226
1320
|
// Update the level bars in the preview
|
|
1227
1321
|
const barsEl = this.previewEl?.querySelector('.voice-level-bars');
|
|
1228
1322
|
if (barsEl) {
|
|
@@ -1252,6 +1346,8 @@ const VoiceInput = {
|
|
|
1252
1346
|
indicator.innerHTML = '<span class="voice-rec-dot"></span>';
|
|
1253
1347
|
const barsEl = document.createElement('span');
|
|
1254
1348
|
barsEl.className = 'voice-level-bars';
|
|
1349
|
+
barsEl.setAttribute('aria-label', this._activeProvider === 'webspeech' ? 'Speech activity' : 'Microphone level');
|
|
1350
|
+
barsEl.title = this._activeProvider === 'webspeech' ? 'Speech activity' : 'Microphone level';
|
|
1255
1351
|
for (let i = 0; i < 5; i++) {
|
|
1256
1352
|
const bar = document.createElement('span');
|
|
1257
1353
|
bar.className = 'voice-level-bar';
|
|
@@ -1319,28 +1415,27 @@ const VoiceInput = {
|
|
|
1319
1415
|
|
|
1320
1416
|
/** Cleanup on SSE reconnect or page unload */
|
|
1321
1417
|
cleanup() {
|
|
1322
|
-
|
|
1418
|
+
// Hide the Send button first: stop(true) below may insert the words it
|
|
1419
|
+
// salvaged and show the button again for them.
|
|
1323
1420
|
this._hideVoiceSendBtn();
|
|
1421
|
+
if (this.isRecording) {
|
|
1422
|
+
this.stop(true);
|
|
1423
|
+
try { this.recognition?.abort(); } catch (_e) { /* already ended */ }
|
|
1424
|
+
}
|
|
1324
1425
|
DeepgramProvider._cleanup();
|
|
1325
1426
|
ClaudeVoiceProvider._cleanup();
|
|
1326
1427
|
this.recognition = null;
|
|
1327
1428
|
this._activeProvider = null;
|
|
1328
1429
|
this._stopDurationTimer();
|
|
1329
1430
|
this._stopLevelMeter();
|
|
1330
|
-
if (this._webSpeechStream) {
|
|
1331
|
-
this._webSpeechStream.getTracks().forEach(t => t.stop());
|
|
1332
|
-
this._webSpeechStream = null;
|
|
1333
|
-
}
|
|
1334
1431
|
if (this.previewEl) {
|
|
1335
1432
|
this.previewEl.remove();
|
|
1336
1433
|
this.previewEl = null;
|
|
1337
1434
|
}
|
|
1338
1435
|
clearTimeout(this.silenceTimeout);
|
|
1339
|
-
clearTimeout(this._stabilityTimer);
|
|
1340
1436
|
this.silenceTimeout = null;
|
|
1341
|
-
this._stabilityTimer = null;
|
|
1342
1437
|
this._accumulatedFinal = '';
|
|
1343
|
-
this.
|
|
1438
|
+
this._pendingInterim = '';
|
|
1344
1439
|
this._retryCount = 0;
|
|
1345
1440
|
this._hasReceivedResult = false;
|
|
1346
1441
|
}
|