@openchamber/web 2.0.4 → 2.1.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/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
- package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
- package/dist/assets/FilesView-B_NJFLBH.js +17 -0
- package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
- package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
- package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
- package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
- package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
- package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
- package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
- package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
- package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
- package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
- package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
- package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
- package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
- package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
- package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
- package/dist/assets/de-D4hpTCNY.js +10 -0
- package/dist/assets/es-Bw9m3H62.js +16 -0
- package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
- package/dist/assets/fr-Bhll42P0.js +14 -0
- package/dist/assets/index-Btd2mmYT.js +42 -0
- package/dist/assets/index-C-7hQnEc.css +1 -0
- package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
- package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
- package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
- package/dist/assets/ja-CsHoT43d.js +16 -0
- package/dist/assets/ko-BBNdtFa4.js +16 -0
- package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
- package/dist/assets/main-kYkr_urz.js +1000 -0
- package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
- package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
- package/dist/assets/mobile-CviaXnnU.js +2 -0
- package/dist/assets/nl-DszyktfH.js +16 -0
- package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
- package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
- package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
- package/dist/assets/pl-Bk9_mUXc.js +16 -0
- package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
- package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
- package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
- package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
- package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
- package/dist/assets/space-close-C1tL-_0t.js +1 -0
- package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
- package/dist/assets/tr-C_13w7CX.js +7 -0
- package/dist/assets/uk-BZTsG-q_.js +16 -0
- package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
- package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
- package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
- package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
- package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
- package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
- package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
- package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
- package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
- package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
- package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
- package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
- package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +4 -4
- package/server/index.js +58 -1
- package/server/lib/browser-control/DOCUMENTATION.md +8 -1
- package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
- package/server/lib/dev-tunnel/runtime.js +94 -38
- package/server/lib/dev-tunnel/tunnel.test.js +16 -2
- package/server/lib/dictation/DOCUMENTATION.md +23 -10
- package/server/lib/dictation/audio.js +28 -0
- package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
- package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
- package/server/lib/dictation/local/worker-client.js +28 -10
- package/server/lib/dictation/local/worker-process.js +25 -1
- package/server/lib/dictation/stream-manager.js +160 -53
- package/server/lib/dictation/stream-manager.test.js +108 -7
- package/server/lib/enterprise-mode.d.ts +2 -0
- package/server/lib/enterprise-mode.js +84 -9
- package/server/lib/enterprise-mode.test.js +115 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -2
- package/server/lib/fs/routes.js +28 -1
- package/server/lib/fs/routes.test.js +31 -5
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +61 -2
- package/server/lib/git/service.test.js +141 -0
- package/server/lib/github/DOCUMENTATION.md +18 -0
- package/server/lib/github/checks-summary.js +76 -0
- package/server/lib/github/pr-summaries.js +282 -0
- package/server/lib/github/pr-summaries.test.js +209 -0
- package/server/lib/github/routes.js +42 -77
- package/server/lib/github/routes.test.js +77 -0
- package/server/lib/inherited-env.js +51 -0
- package/server/lib/inherited-env.test.js +59 -0
- package/server/lib/message-search/DOCUMENTATION.md +83 -0
- package/server/lib/message-search/indexer.js +336 -0
- package/server/lib/message-search/indexer.test.js +341 -0
- package/server/lib/message-search/routes.js +92 -0
- package/server/lib/message-search/runtime.js +234 -0
- package/server/lib/message-search/runtime.test.js +108 -0
- package/server/lib/message-search/sqlite.js +74 -0
- package/server/lib/message-search/store.js +289 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
- package/server/lib/openchamber-control/actions.js +1 -1
- package/server/lib/openchamber-control/service.js +21 -2
- package/server/lib/openchamber-control/service.test.js +50 -0
- package/server/lib/openchamber-sessions/routes.js +15 -0
- package/server/lib/openchamber-sessions/routes.test.js +31 -0
- package/server/lib/opencode/DOCUMENTATION.md +43 -38
- package/server/lib/opencode/auth.d.ts +24 -0
- package/server/lib/opencode/auth.js +130 -66
- package/server/lib/opencode/auth.test.js +114 -70
- package/server/lib/opencode/compatibility.js +4 -3
- package/server/lib/opencode/compatibility.test.js +10 -10
- package/server/lib/opencode/feature-routes-runtime.js +3 -0
- package/server/lib/opencode/lifecycle.js +21 -12
- package/server/lib/opencode/lifecycle.test.js +38 -5
- package/server/lib/opencode/provider-source-route.test.js +55 -2
- package/server/lib/opencode/routes.js +17 -4
- package/server/lib/opencode/settings-helpers.js +6 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +16 -0
- package/server/lib/opencode/settings-runtime.js +9 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/v1-migration-topup.js +13 -3
- package/server/lib/opencode/v2-install.test.js +13 -13
- package/server/lib/quota/DOCUMENTATION.md +11 -5
- package/server/lib/quota/providers/claude/auth.js +19 -6
- package/server/lib/quota/providers/claude/auth.test.js +22 -9
- package/server/lib/quota/providers/claude/index.js +3 -3
- package/server/lib/quota/providers/claude/index.test.js +3 -2
- package/server/lib/quota/providers/cline-pass.js +4 -4
- package/server/lib/quota/providers/codex.js +3 -4
- package/server/lib/quota/providers/codex.test.js +1 -1
- package/server/lib/quota/providers/copilot.js +4 -5
- package/server/lib/quota/providers/copilot.test.js +1 -1
- package/server/lib/quota/providers/deepseek.js +3 -4
- package/server/lib/quota/providers/deepseek.test.js +1 -1
- package/server/lib/quota/providers/google/auth.js +1 -3
- package/server/lib/quota/providers/google/index.js +3 -2
- package/server/lib/quota/providers/hyper.js +4 -4
- package/server/lib/quota/providers/index.js +9 -2
- package/server/lib/quota/providers/index.test.js +5 -3
- package/server/lib/quota/providers/kimi.js +16 -11
- package/server/lib/quota/providers/kimi.test.js +81 -38
- package/server/lib/quota/providers/minimax-shared.js +3 -4
- package/server/lib/quota/providers/nanogpt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.test.js +1 -1
- package/server/lib/quota/providers/openai.js +2 -8
- package/server/lib/quota/providers/opencode-go.js +5 -5
- package/server/lib/quota/providers/opencode-go.test.js +1 -1
- package/server/lib/quota/providers/openrouter.js +30 -6
- package/server/lib/quota/providers/openrouter.test.js +122 -1
- package/server/lib/quota/providers/wafer.js +3 -4
- package/server/lib/quota/providers/xai.js +12 -12
- package/server/lib/quota/providers/zai.js +3 -4
- package/server/lib/quota/providers/zai.test.js +1 -1
- package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
- package/server/lib/quota/routes.js +1 -1
- package/server/lib/routing/DOCUMENTATION.md +4 -0
- package/server/lib/routing/runtime.js +45 -4
- package/server/lib/routing/runtime.test.js +35 -6
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
- package/server/lib/scheduled-tasks/chats-scope.js +50 -0
- package/server/lib/scheduled-tasks/runtime.js +57 -23
- package/server/lib/scheduled-tasks/runtime.test.js +103 -1
- package/server/lib/scheduled-tasks/service.js +37 -29
- package/server/lib/scheduled-tasks/service.test.js +39 -0
- package/server/lib/spaces/DOCUMENTATION.md +54 -9
- package/server/lib/spaces/host.js +24 -3
- package/server/lib/spaces/journey.js +111 -11
- package/server/lib/spaces/journey.test.js +189 -8
- package/server/lib/spaces/places/docker-disk.js +151 -0
- package/server/lib/spaces/places/docker-disk.test.js +167 -0
- package/server/lib/spaces/places/docker-tools.js +11 -1
- package/server/lib/spaces/places/docker.js +4 -2
- package/server/lib/spaces/places/fake-docker.js +36 -2
- package/server/lib/spaces/routes.js +21 -4
- package/server/lib/spaces/routes.test.js +6 -2
- package/server/lib/spaces/space-archive.js +275 -0
- package/server/lib/spaces/space-archive.test.js +194 -0
- package/server/lib/spaces/space-opencode.js +139 -6
- package/server/lib/spaces/space-opencode.test.js +82 -1
- package/server/lib/spaces/space-records.js +3 -0
- package/server/lib/spaces/space-setup.js +10 -5
- package/server/lib/spaces/space-setup.test.js +8 -2
- package/server/lib/terminal/DOCUMENTATION.md +1 -0
- package/server/lib/terminal/runtime.js +6 -1
- package/server/lib/terminal/runtime.test.js +19 -0
- package/server/lib/tts/routes.js +2 -2
- package/server/lib/tts/service.js +8 -8
- package/dist/assets/FilesView-CN34wm_N.js +0 -17
- package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
- package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
- package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
- package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
- package/dist/assets/SettingsWindow-CofS020b.js +0 -1
- package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
- package/dist/assets/de-DlgBHUAI.js +0 -10
- package/dist/assets/es-BC8G41U8.js +0 -16
- package/dist/assets/fr-I0z3vVjy.js +0 -14
- package/dist/assets/index-CgR5rJq_.js +0 -41
- package/dist/assets/index-adyy_sEk.css +0 -1
- package/dist/assets/ja-BIElEsY8.js +0 -16
- package/dist/assets/ko-DRnnHetA.js +0 -16
- package/dist/assets/main-DVX34beR.js +0 -886
- package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
- package/dist/assets/mobile-BrlBrNfZ.js +0 -2
- package/dist/assets/nl-DzUV-kwp.js +0 -16
- package/dist/assets/pl-Bb-cb7k7.js +0 -16
- package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
- package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
- package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
- package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
- package/dist/assets/tr-DXEDSoYO.js +0 -7
- package/dist/assets/uk-C8hN--q_.js +0 -16
- package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
- package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
- package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
- package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
- package/server/lib/opencode/credential-db.js +0 -144
- package/server/lib/opencode/credential-db.test.js +0 -104
|
@@ -190,32 +190,58 @@ export class SherpaSegmentTranscriptionSession extends EventEmitter {
|
|
|
190
190
|
this.pcm16 = this.pcm16.length === 0 ? chunk : Buffer.concat([this.pcm16, chunk]);
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Close the current segment and hand it back for decoding, WITHOUT decoding.
|
|
195
|
+
* The caller decodes later (e.g. on the next event-loop turn) so a long
|
|
196
|
+
* segment's quadratic decode never blocks the worker's IPC — see
|
|
197
|
+
* worker-process.js session.commit. Returns null when not connected or the
|
|
198
|
+
* segment holds no audio.
|
|
199
|
+
* @returns {{ segmentId: string, previousSegmentId: string|null, pcm16: Buffer } | null}
|
|
200
|
+
*/
|
|
201
|
+
takePendingSegment() {
|
|
194
202
|
if (!this.connected || !this.currentSegmentId) {
|
|
195
203
|
this.emit('error', new Error('Sherpa transcription session not connected'));
|
|
196
|
-
return;
|
|
204
|
+
return null;
|
|
197
205
|
}
|
|
198
|
-
|
|
199
206
|
const segmentId = this.currentSegmentId;
|
|
200
207
|
const previousSegmentId = this.previousSegmentId;
|
|
201
208
|
const pcm16 = this.pcm16;
|
|
202
209
|
|
|
203
|
-
// Start the next segment before decoding: decoding
|
|
204
|
-
//
|
|
210
|
+
// Start the next segment before decoding: decoding can take seconds on
|
|
211
|
+
// long segments, and audio for the next one keeps arriving meanwhile.
|
|
205
212
|
this.previousSegmentId = segmentId;
|
|
206
213
|
this.currentSegmentId = randomUUID();
|
|
207
214
|
this.pcm16 = Buffer.alloc(0);
|
|
208
215
|
|
|
209
216
|
this.emit('committed', { segmentId, previousSegmentId });
|
|
210
217
|
|
|
218
|
+
if (pcm16.length === 0) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
return { segmentId, previousSegmentId, pcm16 };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Decode a segment previously returned by takePendingSegment() and emit its
|
|
226
|
+
* final transcript.
|
|
227
|
+
* @param {{ segmentId: string, pcm16: Buffer }} pending
|
|
228
|
+
*/
|
|
229
|
+
decodeSegment(pending) {
|
|
211
230
|
let transcript;
|
|
212
231
|
try {
|
|
213
|
-
transcript = this.engine.decodePcm16(pcm16);
|
|
232
|
+
transcript = this.engine.decodePcm16(pending.pcm16);
|
|
214
233
|
} catch (err) {
|
|
215
234
|
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
216
235
|
return;
|
|
217
236
|
}
|
|
218
|
-
this.emit('transcript', { segmentId, transcript, isFinal: true });
|
|
237
|
+
this.emit('transcript', { segmentId: pending.segmentId, transcript, isFinal: true });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
commit() {
|
|
241
|
+
const pending = this.takePendingSegment();
|
|
242
|
+
if (pending) {
|
|
243
|
+
this.decodeSegment(pending);
|
|
244
|
+
}
|
|
219
245
|
}
|
|
220
246
|
|
|
221
247
|
clear() {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
|
|
4
|
+
import { SherpaSegmentTranscriptionSession } from './sherpa-recognizer.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Regression guard for the dictation timeout bug:
|
|
8
|
+
* a segment's decode must NOT run inside the commit() call that the worker
|
|
9
|
+
* acks. worker-process.js acks `session.commit` BEFORE decoding, which is only
|
|
10
|
+
* correct if the session can hand the segment back without decoding it.
|
|
11
|
+
*
|
|
12
|
+
* If takePendingSegment() ever starts decoding inline again, a long segment
|
|
13
|
+
* would block the worker's IPC past the parent's request timeout again — the
|
|
14
|
+
* exact "Dictation worker request timed out: session.commit" failure.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class RecordingEngine {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.decoded = [];
|
|
20
|
+
this.decodeCalls = 0;
|
|
21
|
+
}
|
|
22
|
+
decodePcm16(pcm16) {
|
|
23
|
+
this.decodeCalls += 1;
|
|
24
|
+
this.decoded.push(pcm16);
|
|
25
|
+
return 'text';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pcm(seconds) {
|
|
30
|
+
return Buffer.alloc(seconds * 16000 * 2, 1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('SherpaSegmentTranscriptionSession', () => {
|
|
34
|
+
it('takePendingSegment does not decode; decodeSegment does', async () => {
|
|
35
|
+
const engine = new RecordingEngine();
|
|
36
|
+
const session = new SherpaSegmentTranscriptionSession({ engine });
|
|
37
|
+
await session.connect();
|
|
38
|
+
|
|
39
|
+
session.appendPcm16(pcm(5));
|
|
40
|
+
const pending = session.takePendingSegment();
|
|
41
|
+
|
|
42
|
+
// The whole point: handing back the segment must be decode-free.
|
|
43
|
+
expect(engine.decodeCalls).toBe(0);
|
|
44
|
+
expect(pending).not.toBeNull();
|
|
45
|
+
expect(pending.pcm16.length).toBe(pcm(5).length);
|
|
46
|
+
|
|
47
|
+
session.decodeSegment(pending);
|
|
48
|
+
expect(engine.decodeCalls).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('emits committed before the caller decodes', async () => {
|
|
52
|
+
const engine = new RecordingEngine();
|
|
53
|
+
const session = new SherpaSegmentTranscriptionSession({ engine });
|
|
54
|
+
await session.connect();
|
|
55
|
+
|
|
56
|
+
const events = [];
|
|
57
|
+
session.on('committed', () => events.push('committed'));
|
|
58
|
+
session.on('transcript', () => events.push('transcript'));
|
|
59
|
+
|
|
60
|
+
session.appendPcm16(pcm(5));
|
|
61
|
+
const pending = session.takePendingSegment();
|
|
62
|
+
expect(events).toEqual(['committed']);
|
|
63
|
+
expect(engine.decodeCalls).toBe(0);
|
|
64
|
+
|
|
65
|
+
session.decodeSegment(pending);
|
|
66
|
+
expect(events).toEqual(['committed', 'transcript']);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('takePendingSegment returns null for an empty segment', async () => {
|
|
70
|
+
const engine = new RecordingEngine();
|
|
71
|
+
const session = new SherpaSegmentTranscriptionSession({ engine });
|
|
72
|
+
await session.connect();
|
|
73
|
+
|
|
74
|
+
const pending = session.takePendingSegment();
|
|
75
|
+
expect(pending).toBeNull();
|
|
76
|
+
expect(engine.decodeCalls).toBe(0);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('starts a fresh segment so appended audio is not lost', async () => {
|
|
80
|
+
const engine = new RecordingEngine();
|
|
81
|
+
const session = new SherpaSegmentTranscriptionSession({ engine });
|
|
82
|
+
await session.connect();
|
|
83
|
+
|
|
84
|
+
session.appendPcm16(pcm(2));
|
|
85
|
+
const first = session.takePendingSegment();
|
|
86
|
+
|
|
87
|
+
session.appendPcm16(pcm(3));
|
|
88
|
+
const second = session.takePendingSegment();
|
|
89
|
+
|
|
90
|
+
expect(first.pcm16.length).toBe(pcm(2).length);
|
|
91
|
+
expect(second.pcm16.length).toBe(pcm(3).length);
|
|
92
|
+
expect(first.segmentId).not.toBe(second.segmentId);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -14,6 +14,10 @@ import { fileURLToPath } from 'url';
|
|
|
14
14
|
|
|
15
15
|
import { applySherpaLoaderEnv } from './sherpa-loader.js';
|
|
16
16
|
|
|
17
|
+
// Every request is answered by the worker on its next event-loop turn, so this
|
|
18
|
+
// only has to cover IPC latency, not inference time. `session.commit` acks
|
|
19
|
+
// BEFORE the segment is decoded (see worker-process.js) precisely so a long
|
|
20
|
+
// segment can no longer trip this timeout.
|
|
17
21
|
const DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
18
22
|
const DEFAULT_IDLE_TTL_MS = 5 * 60 * 1000;
|
|
19
23
|
const DEFAULT_LOCAL_SAMPLE_RATE = 16000;
|
|
@@ -88,26 +92,31 @@ export class DictationWorkerClient {
|
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
appendSessionAudio(sessionId, audio) {
|
|
91
|
-
|
|
95
|
+
// Fire-and-forget with no per-request timeout: audio queued behind a
|
|
96
|
+
// decode is accepted, just waiting its turn. A dead worker is caught by
|
|
97
|
+
// handleWorkerExit.
|
|
98
|
+
void this.sendRequest({ type: 'session.append', sessionId, audio }, { timeoutMs: 0 }).catch((err) => {
|
|
92
99
|
this.emitSessionError(sessionId, err);
|
|
93
100
|
});
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
commitSession(sessionId) {
|
|
97
|
-
|
|
104
|
+
// Fire-and-forget like appendSessionAudio: the committed/transcript events
|
|
105
|
+
// carry the result, and a dead worker is caught by handleWorkerExit.
|
|
106
|
+
void this.sendRequest({ type: 'session.commit', sessionId }, { timeoutMs: 0 }).catch((err) => {
|
|
98
107
|
this.emitSessionError(sessionId, err);
|
|
99
108
|
});
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
clearSession(sessionId) {
|
|
103
|
-
void this.sendRequest({ type: 'session.clear', sessionId }).catch((err) => {
|
|
112
|
+
void this.sendRequest({ type: 'session.clear', sessionId }, { timeoutMs: 0 }).catch((err) => {
|
|
104
113
|
this.emitSessionError(sessionId, err);
|
|
105
114
|
});
|
|
106
115
|
}
|
|
107
116
|
|
|
108
117
|
closeSession(sessionId) {
|
|
109
118
|
this.sessionEmitters.delete(sessionId);
|
|
110
|
-
void this.sendRequest({ type: 'session.close', sessionId }).catch(() => {
|
|
119
|
+
void this.sendRequest({ type: 'session.close', sessionId }, { timeoutMs: 0 }).catch(() => {
|
|
111
120
|
// Closing is best-effort; the parent already dropped the session.
|
|
112
121
|
});
|
|
113
122
|
this.scheduleIdleShutdownIfReady();
|
|
@@ -141,13 +150,22 @@ export class DictationWorkerClient {
|
|
|
141
150
|
this.inFlightRequests += 1;
|
|
142
151
|
this.clearIdleTimer();
|
|
143
152
|
|
|
153
|
+
const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;
|
|
154
|
+
|
|
144
155
|
return new Promise((resolve, reject) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
// timeoutMs === 0 means "no per-request timeout": used for fire-and-forget
|
|
157
|
+
// audio traffic whose result is discarded. A dead worker is still caught
|
|
158
|
+
// by the worker 'close' handler (handleWorkerExit), which rejects every
|
|
159
|
+
// pending request.
|
|
160
|
+
const timeout =
|
|
161
|
+
timeoutMs > 0
|
|
162
|
+
? setTimeout(() => {
|
|
163
|
+
this.pendingRequests.delete(requestId);
|
|
164
|
+
this.inFlightRequests = Math.max(0, this.inFlightRequests - 1);
|
|
165
|
+
this.scheduleIdleShutdownIfReady();
|
|
166
|
+
reject(new Error(`Dictation worker request timed out: ${input.type}`));
|
|
167
|
+
}, timeoutMs)
|
|
168
|
+
: null;
|
|
151
169
|
|
|
152
170
|
this.pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
153
171
|
|
|
@@ -153,8 +153,32 @@ async function handleRequest(message) {
|
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
155
|
case 'session.commit': {
|
|
156
|
-
sessions.get(message.sessionId)
|
|
156
|
+
const session = sessions.get(message.sessionId);
|
|
157
|
+
if (!session) {
|
|
158
|
+
sendOk(message.requestId);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// The segment's decode is synchronous. Acknowledging only after it made
|
|
162
|
+
// the parent's worker-request timeout fire on long segments and blocked
|
|
163
|
+
// every following IPC packet (session.append) behind the decode. So:
|
|
164
|
+
// take the segment, ack the commit immediately, and decode on the next
|
|
165
|
+
// turn of the event loop — the transcript still arrives as a
|
|
166
|
+
// session.transcript event.
|
|
167
|
+
const pending = session.takePendingSegment();
|
|
157
168
|
sendOk(message.requestId);
|
|
169
|
+
if (pending) {
|
|
170
|
+
setImmediate(() => {
|
|
171
|
+
try {
|
|
172
|
+
session.decodeSegment(pending);
|
|
173
|
+
} catch (err) {
|
|
174
|
+
sendToParent({
|
|
175
|
+
type: 'session.error',
|
|
176
|
+
sessionId: message.sessionId,
|
|
177
|
+
error: err instanceof Error ? err.message : String(err),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
158
182
|
return;
|
|
159
183
|
}
|
|
160
184
|
case 'session.clear': {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* - Reorders inbound chunks by `seq` and acks the highest contiguous seq.
|
|
9
9
|
* - Resamples client PCM (16 kHz by default) to the provider's required rate.
|
|
10
10
|
* - Segments long dictations at natural pauses: past `segmentMinSeconds` of
|
|
11
|
-
* audio it
|
|
12
|
-
* hard cap for speech with no pause in it. Silence-only segments are
|
|
11
|
+
* audio it cuts inside the first pause it finds, and `segmentMaxSeconds` is
|
|
12
|
+
* a hard cap for speech with no pause in it. Silence-only segments are
|
|
13
13
|
* cleared instead of committed.
|
|
14
14
|
* - Concatenates per-segment transcripts into live partials and emits the
|
|
15
15
|
* final text once every committed segment has a final transcript. The
|
|
@@ -19,40 +19,140 @@
|
|
|
19
19
|
* - Applies an adaptive finalization timeout budget based on pending work.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
Pcm16MonoResampler,
|
|
24
|
+
parsePcmRateFromFormat,
|
|
25
|
+
pcm16leFrameRms,
|
|
26
|
+
pcm16lePeakAbs,
|
|
27
|
+
} from './audio.js';
|
|
23
28
|
|
|
24
29
|
const DEFAULT_FINAL_TIMEOUT_MS = 10000;
|
|
25
|
-
// Parakeet
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
// Parakeet decode cost and peak memory grow quadratically with segment length,
|
|
31
|
+
// and a long enough segment aborts the worker inside the native runtime, not
|
|
32
|
+
// just slowly (the curve and the crash are in DOCUMENTATION.md#segmentation).
|
|
33
|
+
// Segmenting keeps a long dictation off that curve, and committed segments
|
|
34
|
+
// decode while the user is still speaking, so only the tail is left on stop.
|
|
35
|
+
//
|
|
36
|
+
// The minimum is low because a 15s segment decodes in well under a second.
|
|
37
|
+
// The hard cap stays small (25s) so even pauseless speech never piles up a
|
|
38
|
+
// segment that can hit the allocation abort.
|
|
39
|
+
const DEFAULT_SEGMENT_MIN_SECONDS = 15;
|
|
40
|
+
const DEFAULT_SEGMENT_MAX_SECONDS = 25;
|
|
33
41
|
const FINAL_TIMEOUT_MAX_MS = 5 * 60 * 1000;
|
|
34
42
|
const FINAL_TIMEOUT_PER_PENDING_SEGMENT_MS = 15 * 1000;
|
|
35
43
|
const FINAL_TIMEOUT_PER_PENDING_AUDIO_SECOND_MS = 1500;
|
|
36
44
|
const FINAL_TIMEOUT_PER_MISSING_SEQ_MS = 250;
|
|
37
45
|
const SILENCE_PEAK_THRESHOLD = 300;
|
|
46
|
+
// Pause detection looks at ~50 ms frames. A frame is quiet when its RMS sits
|
|
47
|
+
// within ~10 dB of the quietest frame in the last ~10 s of the stream (the
|
|
48
|
+
// noise floor), so a laptop fan or a boosted mic does not hide every pause,
|
|
49
|
+
// and at least ~15 dB below the loudest frame, so before the first real pause
|
|
50
|
+
// the softest bit of speech does not pass for one. The floor is a sliding
|
|
51
|
+
// window rather than an all-time minimum because a gated mic often opens with
|
|
52
|
+
// a second of digital zeros, and a floor pinned there would call room noise
|
|
53
|
+
// speech for the rest of the dictation. The absolute minimum keeps a
|
|
54
|
+
// digitally silent stream from needing exact zeros. A pause is a quiet run of
|
|
55
|
+
// at least 200 ms: longer than the closure inside a word, and a fast speaker's
|
|
56
|
+
// pause between sentences is barely longer (a synthesized voice pauses
|
|
57
|
+
// 200–350 ms at a period), so a cut lands between words.
|
|
58
|
+
const PAUSE_FRAME_MS = 50;
|
|
59
|
+
const PAUSE_MIN_FRAMES = 4;
|
|
60
|
+
const NOISE_FLOOR_WINDOW_CHUNKS = 10;
|
|
61
|
+
const QUIET_ABOVE_FLOOR_RATIO = 3;
|
|
62
|
+
const QUIET_BELOW_SPEECH_RATIO = 6;
|
|
63
|
+
const QUIET_RMS_MIN = 200;
|
|
38
64
|
|
|
39
65
|
const secondsToPcm16Bytes = (seconds, sampleRate) =>
|
|
40
66
|
seconds > 0 ? Math.max(1, Math.round(seconds * sampleRate * 2)) : 0;
|
|
41
67
|
|
|
42
68
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
69
|
+
* Byte offset inside `pcm16` where the current segment should end, or null to
|
|
70
|
+
* keep the whole chunk in it.
|
|
71
|
+
*
|
|
72
|
+
* Past `segmentMinBytes` the cut goes into the middle of the first pause; a
|
|
73
|
+
* pause may have started in the previous chunk, which `state.quietRunFrames`
|
|
74
|
+
* carries over (when its middle already went by, the cut is where this chunk
|
|
75
|
+
* starts, still inside the pause). At the hard cap the cut goes into the quietest frame of this
|
|
76
|
+
* chunk rather than at its boundary, so even pauseless speech is cut between
|
|
77
|
+
* words when it can be. Bytes before the cut belong to the segment being
|
|
78
|
+
* committed, bytes after it start the next one.
|
|
47
79
|
*/
|
|
48
|
-
function
|
|
49
|
-
if (state.
|
|
50
|
-
return
|
|
80
|
+
function findSegmentCut(state, pcm16) {
|
|
81
|
+
if (state.finishRequested) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const capReached =
|
|
85
|
+
state.segmentMaxBytes > 0 && state.bytesSinceCommit + pcm16.length >= state.segmentMaxBytes;
|
|
86
|
+
const frameSamples = state.pauseFrameSamples;
|
|
87
|
+
const frameBytes = frameSamples * 2;
|
|
88
|
+
const rms = pcm16leFrameRms(pcm16, frameSamples);
|
|
89
|
+
if (rms.length === 0) {
|
|
90
|
+
return capReached ? pcm16.length : null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let chunkFloor = Infinity;
|
|
94
|
+
for (const value of rms) {
|
|
95
|
+
if (value < chunkFloor) {
|
|
96
|
+
chunkFloor = value;
|
|
97
|
+
}
|
|
98
|
+
if (value > state.loudestRms) {
|
|
99
|
+
state.loudestRms = value;
|
|
100
|
+
}
|
|
51
101
|
}
|
|
52
|
-
|
|
53
|
-
|
|
102
|
+
state.recentChunkFloors.push(chunkFloor);
|
|
103
|
+
if (state.recentChunkFloors.length > NOISE_FLOOR_WINDOW_CHUNKS) {
|
|
104
|
+
state.recentChunkFloors.shift();
|
|
54
105
|
}
|
|
55
|
-
|
|
106
|
+
const noiseFloor = Math.min(...state.recentChunkFloors);
|
|
107
|
+
const quietBelow = Math.min(
|
|
108
|
+
Math.max(noiseFloor * QUIET_ABOVE_FLOOR_RATIO, QUIET_RMS_MIN),
|
|
109
|
+
state.loudestRms / QUIET_BELOW_SPEECH_RATIO,
|
|
110
|
+
);
|
|
111
|
+
const quiet = rms.map((value) => value <= quietBelow);
|
|
112
|
+
|
|
113
|
+
let cut = null;
|
|
114
|
+
if (state.segmentMinBytes > 0) {
|
|
115
|
+
let runStart = -state.quietRunFrames;
|
|
116
|
+
let inRun = state.quietRunFrames > 0;
|
|
117
|
+
for (let i = 0; i <= quiet.length; i += 1) {
|
|
118
|
+
if (i < quiet.length && quiet[i]) {
|
|
119
|
+
if (!inRun) {
|
|
120
|
+
inRun = true;
|
|
121
|
+
runStart = i;
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!inRun) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
inRun = false;
|
|
129
|
+
if (i - runStart < PAUSE_MIN_FRAMES) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const bytes = Math.max(0, Math.floor((runStart + i) / 2)) * frameBytes;
|
|
133
|
+
if (state.bytesSinceCommit + bytes >= state.segmentMinBytes) {
|
|
134
|
+
cut = bytes;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (cut === null && capReached) {
|
|
141
|
+
let quietest = 0;
|
|
142
|
+
for (let i = 1; i < rms.length; i += 1) {
|
|
143
|
+
if (rms[i] < rms[quietest]) {
|
|
144
|
+
quietest = i;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
cut = (quietest * frameSamples + (frameSamples >> 1)) * 2;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let trailing = 0;
|
|
151
|
+
while (trailing < quiet.length && quiet[quiet.length - 1 - trailing]) {
|
|
152
|
+
trailing += 1;
|
|
153
|
+
}
|
|
154
|
+
state.quietRunFrames = trailing;
|
|
155
|
+
return cut;
|
|
56
156
|
}
|
|
57
157
|
|
|
58
158
|
export class DictationStreamManager {
|
|
@@ -173,9 +273,12 @@ export class DictationStreamManager {
|
|
|
173
273
|
ackSeq: -1,
|
|
174
274
|
segmentMinBytes: secondsToPcm16Bytes(this.segmentMinSeconds, stt.requiredSampleRate),
|
|
175
275
|
segmentMaxBytes: secondsToPcm16Bytes(this.segmentMaxSeconds, stt.requiredSampleRate),
|
|
276
|
+
pauseFrameSamples: Math.max(1, Math.round((stt.requiredSampleRate * PAUSE_FRAME_MS) / 1000)),
|
|
277
|
+
recentChunkFloors: [],
|
|
278
|
+
loudestRms: 0,
|
|
279
|
+
quietRunFrames: 0,
|
|
176
280
|
bytesSinceCommit: 0,
|
|
177
281
|
peakSinceCommit: 0,
|
|
178
|
-
lastChunkPeak: 0,
|
|
179
282
|
committedSegmentIds: [],
|
|
180
283
|
transcriptsBySegmentId: new Map(),
|
|
181
284
|
finalTranscriptSegmentIds: new Set(),
|
|
@@ -228,12 +331,8 @@ export class DictationStreamManager {
|
|
|
228
331
|
|
|
229
332
|
const resampled = state.resampler ? state.resampler.processChunk(pcm16) : pcm16;
|
|
230
333
|
if (resampled.length > 0) {
|
|
231
|
-
state.stt.appendPcm16(resampled);
|
|
232
|
-
state.bytesSinceCommit += resampled.length;
|
|
233
|
-
state.lastChunkPeak = pcm16lePeakAbs(resampled);
|
|
234
|
-
state.peakSinceCommit = Math.max(state.peakSinceCommit, state.lastChunkPeak);
|
|
235
334
|
try {
|
|
236
|
-
this.
|
|
335
|
+
this.forwardAudio(state, resampled);
|
|
237
336
|
} catch (error) {
|
|
238
337
|
this.failAndCleanupStream(dictationId, error?.message || String(error), true);
|
|
239
338
|
return;
|
|
@@ -369,24 +468,39 @@ export class DictationStreamManager {
|
|
|
369
468
|
);
|
|
370
469
|
}
|
|
371
470
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
471
|
+
/**
|
|
472
|
+
* Append one chunk of provider-rate audio, ending the current segment inside
|
|
473
|
+
* the chunk when it holds a good place to cut.
|
|
474
|
+
*/
|
|
475
|
+
forwardAudio(state, pcm16) {
|
|
476
|
+
const cutAt = findSegmentCut(state, pcm16);
|
|
477
|
+
if (cutAt === null) {
|
|
478
|
+
this.appendToSegment(state, pcm16);
|
|
377
479
|
return;
|
|
378
480
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
481
|
+
this.appendToSegment(state, pcm16.subarray(0, cutAt));
|
|
482
|
+
this.endSegment(state);
|
|
483
|
+
this.appendToSegment(state, pcm16.subarray(cutAt));
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
appendToSegment(state, pcm16) {
|
|
487
|
+
if (pcm16.length === 0) {
|
|
384
488
|
return;
|
|
385
489
|
}
|
|
490
|
+
state.stt.appendPcm16(pcm16);
|
|
491
|
+
state.bytesSinceCommit += pcm16.length;
|
|
492
|
+
state.peakSinceCommit = Math.max(state.peakSinceCommit, pcm16lePeakAbs(pcm16));
|
|
493
|
+
}
|
|
386
494
|
|
|
495
|
+
/** Commit the current segment, or drop it when it holds only silence. */
|
|
496
|
+
endSegment(state) {
|
|
497
|
+
const silent = state.peakSinceCommit < SILENCE_PEAK_THRESHOLD;
|
|
387
498
|
state.bytesSinceCommit = 0;
|
|
388
499
|
state.peakSinceCommit = 0;
|
|
389
|
-
|
|
500
|
+
if (silent) {
|
|
501
|
+
state.stt.clear();
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
390
504
|
this.commitSegment(state);
|
|
391
505
|
}
|
|
392
506
|
|
|
@@ -421,22 +535,15 @@ export class DictationStreamManager {
|
|
|
421
535
|
}
|
|
422
536
|
|
|
423
537
|
if (state.bytesSinceCommit > 0) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
state
|
|
427
|
-
|
|
428
|
-
|
|
538
|
+
const silent = state.peakSinceCommit < SILENCE_PEAK_THRESHOLD;
|
|
539
|
+
try {
|
|
540
|
+
this.endSegment(state);
|
|
541
|
+
} catch (error) {
|
|
542
|
+
this.failAndCleanupStream(dictationId, error?.message || String(error), true);
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (silent) {
|
|
429
546
|
this.dropUncommittedNonFinalTranscripts(state);
|
|
430
|
-
} else {
|
|
431
|
-
state.bytesSinceCommit = 0;
|
|
432
|
-
state.peakSinceCommit = 0;
|
|
433
|
-
state.lastChunkPeak = 0;
|
|
434
|
-
try {
|
|
435
|
-
this.commitSegment(state);
|
|
436
|
-
} catch (error) {
|
|
437
|
-
this.failAndCleanupStream(dictationId, error?.message || String(error), true);
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
547
|
}
|
|
441
548
|
}
|
|
442
549
|
|