@ds-hu/dsh-better-voice-input 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 the dsh-better-voice-input authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,31 @@
1
+ dsh-better-voice-input
2
+ Copyright (c) 2026 the dsh-better-voice-input authors
3
+
4
+ The `icon.svg` and `docs/preview*.svg` artwork is original to this project and is
5
+ distributed under the same MIT license as the rest of the package.
6
+
7
+ This project is a plugin for DeepSeek Harness and extends the official
8
+ experimental voice input bundle. The DeepSeek Harness packages it integrates
9
+ with are licensed under the MIT License:
10
+ https://github.com/deepseek-ai/deepseek-harness
11
+
12
+ The local-model runtime uses sherpa-onnx through the `sherpa-onnx-node` npm
13
+ package. sherpa-onnx is Copyright (c) 2023-2026 k2-fsa and is licensed under the
14
+ Apache License, Version 2.0:
15
+ https://github.com/k2-fsa/sherpa-onnx
16
+
17
+ Local speech models are downloaded by the user's explicit request from the
18
+ upstream sherpa-onnx model releases on Hugging Face, not redistributed in this
19
+ package. Each model keeps its own license and attribution, which the settings
20
+ page links to:
21
+ https://huggingface.co/csukuangfj
22
+
23
+ The provider/model list follows BryceWG/BiBi-Keyboard ("说点啥"), an Android
24
+ voice-input project licensed under the Apache License, Version 2.0. Only its
25
+ public model/provider list and public vendor API facts were used as a reference;
26
+ no Android implementation or user-interface code was copied:
27
+ https://github.com/BryceWG/BiBi-Keyboard
28
+
29
+ Cloud providers are implemented against each vendor's public HTTP API; their
30
+ names and trademarks belong to their owners. No endorsement by any vendor is
31
+ implied.
package/README.en.md ADDED
@@ -0,0 +1,113 @@
1
+ # Better voice input
2
+
3
+ [中文 →](README.md)
4
+
5
+ **21 speech-recognition services for the DeepSeek Harness Web GUI, plus a DeepSeek-App-style
6
+ hold-to-talk composer.**
7
+
8
+ ![Hold the composer to talk: blue recording overlay and red cancel overlay](https://raw.githubusercontent.com/ds-hu/dsh-better-voice-input/main/docs/preview-en.svg)
9
+
10
+ ## What you get
11
+
12
+ - **21 speech-recognition services.** 14 cloud APIs (OpenAI, Volcengine, DashScope, Tencent Cloud,
13
+ Zhipu, ElevenLabs, Gemini, SiliconFlow, Soniox, StepAudio, Cohere, OpenRouter, Xiaomi MiMo,
14
+ DeepSeek) and 7 model families that run on your machine (SenseVoice, FunASR Nano, Qwen3-ASR,
15
+ Parakeet, GigaAM, FireRedASR, X-ASR). Pick one in the Plugins settings page and switch whenever
16
+ you like.
17
+ - **Hold the composer to talk.** Desktop and touch share one hold detector: hold the input box to
18
+ get a full-screen recording overlay with a live waveform; slide up into the cancel zone and
19
+ release to discard, release anywhere else to transcribe.
20
+ - **Your choice on release.** The transcript is inserted into the draft by default; a setting makes
21
+ release send the message instead.
22
+ - **Offline local models.** The 7 local families run entirely on this machine once downloaded —
23
+ audio never leaves it, and no GPU is required.
24
+ - **Keys stay on the host.** API keys entered in the settings page are written to the local config
25
+ file and only ever shown masked.
26
+
27
+ ## Settings
28
+
29
+ ![Settings page: pick a speech service, download a local model, choose the release behavior](https://raw.githubusercontent.com/ds-hu/dsh-better-voice-input/main/docs/preview-settings.svg)
30
+
31
+ 1. After installing, enable this plugin in **Plugins** and open its detail page → **Settings**.
32
+ 2. Pick a cloud service and paste its API key (environment variables work as a fallback), or
33
+ download a local model.
34
+ 3. Optionally change *on release* from **insert draft** to **send**.
35
+ 4. Back in a conversation, put the caret where the text should go and hold the composer.
36
+
37
+ ## Cloud services
38
+
39
+ | Provider | Default model | Environment variable |
40
+ | --- | --- | --- |
41
+ | SiliconFlow | `FunAudioLLM/SenseVoiceSmall` | `SILICONFLOW_API_KEY` |
42
+ | Volcengine | `bigmodel` (flash) | `VOLCENGINE_API_KEY` |
43
+ | ElevenLabs | `scribe_v3` | `ELEVENLABS_API_KEY` |
44
+ | OpenAI | `gpt-transcribe` | `OPENAI_API_KEY` |
45
+ | OpenRouter | `qwen/qwen3-asr-1.7b` | `OPENROUTER_API_KEY` |
46
+ | DashScope (Alibaba Cloud) | `qwen-audio-3.1-asr-flash` | `DASHSCOPE_API_KEY` |
47
+ | DeepSeek | service default | `DEEPSEEK_API_KEY` |
48
+ | Google Gemini | `gemini-3.5-transcribe` | `GEMINI_API_KEY` |
49
+ | Xiaomi MiMo | `mimo-v2.5-asr` | `MIMO_API_KEY` |
50
+ | Tencent Cloud | engine `16k_zh` | `TENCENT_ASR_APP_ID` / `TENCENT_ASR_SECRET_ID` / `TENCENT_ASR_SECRET_KEY` |
51
+ | Soniox | `stt-async-v6` | `SONIOX_API_KEY` |
52
+ | StepAudio | `stepaudio-2.5-asr` | `STEPFUN_API_KEY` |
53
+ | Zhipu GLM | `glm-asr-2512` | `ZHIPU_API_KEY` |
54
+ | Cohere | `cohere-transcribe-03-2026` | `COHERE_API_KEY` |
55
+
56
+ Every service accepts a custom base URL (proxies, regional endpoints) and its documented model,
57
+ language-hint and hotword options.
58
+
59
+ ## Local models
60
+
61
+ | Family | Languages | Variants |
62
+ | --- | --- | --- |
63
+ | SenseVoice | auto, zh, en, ja, ko, yue | small int8 / small full |
64
+ | FunASR Nano | auto, zh, en | nano int8 / multilingual int8 |
65
+ | Qwen3-ASR | auto, zh, en, and more | 0.6B int8 / 1.7B int8 |
66
+ | Parakeet | en | 0.6B v2 int8 / v3 int8 |
67
+ | GigaAM | ru | v3 Russian |
68
+ | FireRedASR | zh, en | FireRedASR2 CTC int8 |
69
+ | X-ASR | zh, en | streaming 480 ms |
70
+
71
+ Models are downloaded on first use and verified file by file; the settings page shows each
72
+ variant's download size and links its upstream license.
73
+
74
+ ## Install
75
+
76
+ ```sh
77
+ dsh plugin --profile <profile> add @ds-hu/dsh-better-voice-input
78
+ ```
79
+
80
+ Then add the bundle to that profile's `dsh.profile.bundles` and restart `dsh web`:
81
+
82
+ ```json
83
+ { "dsh": { "profile": { "bundles": ["…", "@ds-hu/dsh-better-voice-input"] } } }
84
+ ```
85
+
86
+ Keep the official **Voice input** bundle enabled (this plugin extends its speech-to-text registry)
87
+ and enable **Better voice input**. The official mic button can be disabled; the two recording
88
+ entries do not interfere with each other.
89
+
90
+ ## Requirements
91
+
92
+ - DeepSeek Harness **>= 0.2.2-rc.5 < 0.3.0**, Node.js **>= 20.19**.
93
+ - A browser with `getUserMedia` (the DSH Web GUI) for hold-to-talk.
94
+ - Local models need disk space (a few hundred MB up to ~2 GB depending on the variant) and a CPU;
95
+ no GPU required.
96
+
97
+ ## Privacy
98
+
99
+ Speech is sent only to the service you selected: the cloud endpoint you configured, or a local
100
+ model running on your own machine. There is no telemetry and no third-party relay. API keys live in
101
+ the host config file (`0600`) and the browser only sees masks. Local models come from the upstream
102
+ sherpa-onnx repositories and are verified against pinned digests.
103
+
104
+ ## Documentation
105
+
106
+ - [Architecture](docs/ARCHITECTURE.md) — technical design, component boundaries, HTTP API
107
+ - [Module contracts](docs/CONTRACTS.md)
108
+ - [Verification record](docs/VERIFICATION.md) — CI gates and the real download + inference runs for all 11 local variants
109
+ - [NOTICE](NOTICE) — third-party attribution and model licenses
110
+
111
+ ## License
112
+
113
+ MIT.
package/README.md CHANGED
@@ -1,3 +1,102 @@
1
- # Temporary Holding Version
1
+ # 更好的语音输入
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [English →](README.en.md)
4
+
5
+ 为 DeepSeek Harness 的 Web GUI 增加 **21 个语音识别服务**,并把输入框变成 DeepSeek App 那样
6
+ **按住说话**的录音入口。
7
+
8
+ ![按住输入框说话:蓝色录音浮层与上滑取消的红色浮层](https://raw.githubusercontent.com/ds-hu/dsh-better-voice-input/main/docs/preview.svg)
9
+
10
+ ## 功能
11
+
12
+ - **21 个语音识别服务。** 14 家云端接口(OpenAI、火山引擎、阿里云百炼、腾讯云、智谱、
13
+ ElevenLabs、Gemini、SiliconFlow、Soniox、阶跃星辰、Cohere、OpenRouter、小米 MiMo、
14
+ DeepSeek),加上 7 个在本机运行的模型系列(SenseVoice、FunASR Nano、Qwen3-ASR、Parakeet、
15
+ GigaAM、FireRedASR、X-ASR)。在插件面板里选中即用,随时切换。
16
+ - **按住输入框说话。** 桌面与触屏共用同一套长按判定:按住输入框出现全屏录音浮层与实时波形,
17
+ 上滑离开取消区、松手取消,其他位置松手开始转写。
18
+ - **松手之后由你决定。** 默认把识别结果插入草稿光标处,也可以在设置里改成松手直接发送。
19
+ - **本地模型可离线。** 7 个本地系列下载后完全在本机推理,音频不出机器;不需要 GPU。
20
+ - **密钥留在本机。** 设置页里填写的 API Key 只写到本机配置文件,界面始终只显示掩码。
21
+
22
+ ## 设置
23
+
24
+ ![设置页:选择语音服务、下载本地模型、选择松手行为](https://raw.githubusercontent.com/ds-hu/dsh-better-voice-input/main/docs/preview-settings.svg)
25
+
26
+ 1. 安装后在 **Plugins** 面板启用本插件,打开详情页 → **设置**。
27
+ 2. 选择云端服务并填写 API Key(也支持环境变量兜底),或下载一个本地模型。
28
+ 3. 需要的话,把「松手之后」从 **插入草稿** 改为 **直接发送**。
29
+ 4. 回到对话,把光标放到要插入文字的位置,按住输入框说话。
30
+
31
+ ## 云端服务
32
+
33
+ | 供应商 | 默认模型 | 环境变量 |
34
+ | --- | --- | --- |
35
+ | SiliconFlow 硅基流动 | `FunAudioLLM/SenseVoiceSmall` | `SILICONFLOW_API_KEY` |
36
+ | 火山引擎 | `bigmodel`(flash) | `VOLCENGINE_API_KEY` |
37
+ | ElevenLabs | `scribe_v3` | `ELEVENLABS_API_KEY` |
38
+ | OpenAI | `gpt-transcribe` | `OPENAI_API_KEY` |
39
+ | OpenRouter | `qwen/qwen3-asr-1.7b` | `OPENROUTER_API_KEY` |
40
+ | 阿里云百炼 | `qwen-audio-3.1-asr-flash` | `DASHSCOPE_API_KEY` |
41
+ | DeepSeek | 服务默认 | `DEEPSEEK_API_KEY` |
42
+ | Google Gemini | `gemini-3.5-transcribe` | `GEMINI_API_KEY` |
43
+ | 小米 MiMo | `mimo-v2.5-asr` | `MIMO_API_KEY` |
44
+ | 腾讯云 | 引擎 `16k_zh` | `TENCENT_ASR_APP_ID` / `TENCENT_ASR_SECRET_ID` / `TENCENT_ASR_SECRET_KEY` |
45
+ | Soniox | `stt-async-v6` | `SONIOX_API_KEY` |
46
+ | 阶跃星辰 | `stepaudio-2.5-asr` | `STEPFUN_API_KEY` |
47
+ | 智谱 GLM | `glm-asr-2512` | `ZHIPU_API_KEY` |
48
+ | Cohere | `cohere-transcribe-03-2026` | `COHERE_API_KEY` |
49
+
50
+ 所有服务都支持自定义 base URL(代理、区域端点),以及各家文档化的 model、语言提示、热词等选项。
51
+
52
+ ## 本地模型
53
+
54
+ | 系列 | 语言 | 变体 |
55
+ | --- | --- | --- |
56
+ | SenseVoice | auto、zh、en、ja、ko、yue | small int8 / small full |
57
+ | FunASR Nano | auto、zh、en | nano int8 / 多语 int8 |
58
+ | Qwen3-ASR | auto、zh、en 等 | 0.6B int8 / 1.7B int8 |
59
+ | Parakeet | en | 0.6B v2 int8 / v3 int8 |
60
+ | GigaAM | ru | v3 Russian |
61
+ | FireRedASR | zh、en | FireRedASR2 CTC int8 |
62
+ | X-ASR | zh、en | 流式 480 ms |
63
+
64
+ 模型首次使用时下载到本机并逐文件校验,设置页会给出下载体积与上游许可证链接。
65
+
66
+ ## 安装
67
+
68
+ ```sh
69
+ dsh plugin --profile <profile> add @ds-hu/dsh-better-voice-input
70
+ ```
71
+
72
+ 把 bundle 加入该 profile 的 `dsh.profile.bundles`,重启 `dsh web`:
73
+
74
+ ```json
75
+ { "dsh": { "profile": { "bundles": ["…", "@ds-hu/dsh-better-voice-input"] } } }
76
+ ```
77
+
78
+ 保持官方**语音输入** bundle 启用(本插件扩展它的语音识别注册表),再启用**更好的语音输入**。
79
+ 官方的麦克风按钮可以关闭,两者的录音入口互不影响。
80
+
81
+ ## 环境要求
82
+
83
+ - DeepSeek Harness **>= 0.2.2-rc.5 < 0.3.0**,Node.js **>= 20.19**。
84
+ - 使用按住说话需要支持 `getUserMedia` 的浏览器(DSH Web GUI)。
85
+ - 本地模型需要磁盘空间(视变体约几百 MB 到 2 GB)与 CPU,无需 GPU。
86
+
87
+ ## 隐私
88
+
89
+ 语音只会发送到你选中的服务:你配置的云端接口,或本地模型(完全在本机)。插件没有遥测,也没有
90
+ 第三方中转。API Key 保存在本机配置文件(权限 `0600`),浏览器只看到掩码。本地模型从 sherpa-onnx
91
+ 上游仓库下载,并按固定摘要校验。
92
+
93
+ ## 文档
94
+
95
+ - [架构说明](docs/ARCHITECTURE.md)(技术路线、组件边界、HTTP 接口)
96
+ - [模块契约](docs/CONTRACTS.md)
97
+ - [验证记录](docs/VERIFICATION.md):CI 门禁、11 个本地变体的真实下载+推理运行记录
98
+ - [NOTICE](NOTICE):第三方归属与模型许可证
99
+
100
+ ## 许可证
101
+
102
+ MIT。
@@ -0,0 +1,34 @@
1
+ # The @ds-hu/dsh-better-voice-input bundle patch: four independently switchable components.
2
+ #
3
+ # Component rows (each one is a switch on the bundle's page in the Plugins panel):
4
+ # bvi-service shared service + settings page: provider config store, same-origin API,
5
+ # provider catalog / selection / preparation relay, preferences
6
+ # bvi-cloud more speech models · cloud: 14 cloud ASR providers registered into ctx.speechToText
7
+ # bvi-local more speech models · local: 7 downloadable sherpa-onnx models on the same seam
8
+ # bvi-input better voice input: DeepSeek-App-style hold-to-talk composer interaction
9
+ #
10
+ # Dependency: this bundle EXTENDS the official experimental voice input bundle
11
+ # (@deepseek-ai/dsh-experimental-voice-input-bundle). Keep that bundle enabled: its
12
+ # `speech-to-text` row supplies ctx.speechToText, the registry every model row here
13
+ # registers into, and our service relays selection/preparation through it. We
14
+ # deliberately do not insert those rows again (a second service instance would fail).
15
+ #
16
+ # Row config:
17
+ # bvi-service dataRoot absolute state directory (config.json, preferences)
18
+ # bvi-local dataRoot absolute model directory (downloaded sherpa-onnx models)
19
+ - insert:
20
+ - id: bvi-service
21
+ name: '@ds-hu/dsh-bvi-service'
22
+ config:
23
+ dataRoot: !!js dshHomePath('better-voice-input')
24
+
25
+ - id: bvi-cloud
26
+ name: '@ds-hu/dsh-bvi-cloud'
27
+
28
+ - id: bvi-local
29
+ name: '@ds-hu/dsh-bvi-local'
30
+ config:
31
+ dataRoot: !!js dshHomePath('better-voice-input', 'models')
32
+
33
+ - id: bvi-input
34
+ name: '@ds-hu/dsh-bvi-input'
@@ -0,0 +1,270 @@
1
+ # Architecture — better voice input for DSH
2
+
3
+ Status: design of record for v0.1. Everything here is plain ESM JavaScript, no build step.
4
+
5
+ ## 1. Product
6
+
7
+ The official experimental voice input bundle (`@deepseek-ai/dsh-experimental-voice-input-bundle`,
8
+ v0.2.2-rc.5) exposes one speech-to-text provider ("SenseVoice 本地识别") and one recorder UI.
9
+ This bundle extends exactly those two seams:
10
+
11
+ 1. **组件一 · 更多语音识别模型** — 21 providers registered into the official
12
+ `ctx.speechToText` registry: 14 cloud APIs plus 7 local sherpa-onnx models. The list follows
13
+ `BryceWG/BiBi-Keyboard` ("说点啥"); only its model/provider list is used as a reference, its
14
+ Android implementation and UI are not copied.
15
+ 2. **组件二 · 更好的语音输入** — a DeepSeek-App-style hold-to-talk composer: long-press the
16
+ input box (one pointer-based hold detection for mouse, touch and pen), a full-screen
17
+ recording overlay, slide up to cancel, release to transcribe and insert (default) or send.
18
+
19
+ The bundle **depends on** the official bundle. It never inserts the official rows: a second
20
+ `speech-to-text` row would create a second `ctx.speechToText` service instance and fail. Our
21
+ settings page says so explicitly when the service is missing.
22
+
23
+ ## 2. Components (one switch each in the Plugins panel)
24
+
25
+ | Row id | Package | Kind | Responsibility |
26
+ | --- | --- | --- | --- |
27
+ | `bvi-service` | `@ds-hu/dsh-bvi-service` | host + client | Config store, same-origin HTTP API (catalog, selection, preparation, transcription, preferences), the bundle's own settings page in Plugins |
28
+ | `bvi-cloud` | `@ds-hu/dsh-bvi-cloud` | host | 14 cloud providers on `ctx.speechToText` |
29
+ | `bvi-local` | `@ds-hu/dsh-bvi-local` | host | 7 sherpa-onnx providers with managed model download + worker process |
30
+ | `bvi-input` | `@ds-hu/dsh-bvi-input` | client (+ no-op host) | Long-press gesture, full-screen overlay, audio capture, transcript insertion |
31
+
32
+ `@ds-hu/dsh-bvi-core` is a library dependency of `service`, `cloud` and `local` (never a row):
33
+ domain catalogs, config store primitives, WAV utilities, request builders.
34
+
35
+ Dependency direction: `bundle -> {service, cloud, local, input}`, `{service, cloud, local} -> core`.
36
+ `input` talks to `service` over the same-origin HTTP API, so it does not depend on the official
37
+ client UI being enabled.
38
+
39
+ The two model catalogs ship as **data-only** modules inside core (`core/lib/catalog/cloud.js` and
40
+ `core/lib/catalog/local.js`): the service renders its settings page from that metadata without
41
+ depending on either row package, while the request code (cloud adapters) and recognizer
42
+ configuration (local worker adapters) stay in their owning packages. All packages are released at
43
+ one version, so catalog edits and their adapters ship together.
44
+
45
+ ## 3. Host design
46
+
47
+ ### 3.1 Speech provider contract (official seam)
48
+
49
+ Each provider implements the official interface, unchanged:
50
+
51
+ ```js
52
+ {
53
+ info: { id, name, location: 'cloud' | 'host-local', languages: [...], setupEstimate?, downloadSources? },
54
+ preparation?: { snapshot(), subscribe(fn), prepare(options), cancel() }, // local models only
55
+ transcribe({ audio: Uint8Array, language }, signal) -> { text, audioSeconds, inferenceSeconds },
56
+ }
57
+ ```
58
+
59
+ `ctx.speechToText.register(provider)` is called inside `apply()` and cleaned up by `ctx.effect`.
60
+ Provider rows inject `speechToText`; while absent the row stays inactive (not failed), and the
61
+ settings page reports the missing official dependency.
62
+
63
+ ### 3.2 Config store (`core`)
64
+
65
+ - Location: `<dataRoot>/config.json` (`dataRoot` comes from the row config, default
66
+ `$DSH_HOME/better-voice-input`). Directory `0700`, file `0600`, atomic write
67
+ (`.tmp` + `rename`), JSON schema version field.
68
+ - Shape:
69
+
70
+ ```json
71
+ {
72
+ "version": 1,
73
+ "providers": {
74
+ "bvi-cloud-openai": { "apiKey": "...", "baseURL": "https://api.openai.com/v1", "model": "gpt-4o-transcribe" }
75
+ },
76
+ "local": { "bvi-local-funasr-nano": { "variant": "nano-int8" } },
77
+ "preferences": { "releaseAction": "insert", "holdDelayMs": 280, "cancelDistancePx": 72, "hintDismissed": false }
78
+ }
79
+ ```
80
+
81
+ - Providers read their own entry at transcription time (`readConfig()`); env fallback names are
82
+ part of each provider descriptor (e.g. `OPENAI_API_KEY`). Config changes apply to the next
83
+ recording without a plugin restart.
84
+ - Seconds never leak: `GET /state` returns masked keys (`sk-…4f2a`) only; updates accept a new
85
+ value or `{ "clear": true }`.
86
+
87
+ ### 3.3 Cloud providers (`cloud`)
88
+
89
+ - One provider per vendor, id `bvi-cloud-<vendor>`, `location: 'cloud'`.
90
+ - A vendor descriptor in `core` (id, names, languages, default endpoint/model, credential fields,
91
+ env names, docs URL) is the single source for both the provider implementation and the
92
+ settings page.
93
+ - Audio: recordings arrive as canonical 16 kHz mono PCM16 WAV. The WAV -> PCM conversion and
94
+ provider-specific container/base64 handling live in the request builder of each adapter.
95
+ Providers that need a different container get an adapter-specific conversion path documented
96
+ in `docs/research/cloud-providers.md`.
97
+ - Failures throw `Error` messages that the service relays to the UI (no secrets, bounded length).
98
+
99
+ ### 3.4 Local providers (`local`)
100
+
101
+ - One provider per model family (id `bvi-local-<family>`), `location: 'host-local'`;
102
+ `preparation.snapshot()/subscribe()` drive the download UI through the official shape
103
+ (`phase: unprepared | downloading | checking | loading | ready | standby | failed | ...`).
104
+ - Model catalog in `core`: per family the variants, file list (name/bytes/sha256), pinned
105
+ upstream URLs (HuggingFace revision URLs), language set, setup estimate, and a
106
+ `downloadSources` origin list (`https://huggingface.co`, `https://hf-mirror.com`).
107
+ - Download: streaming fetch -> sha256 -> atomic rename, cancelled through `AbortSignal`,
108
+ progress throttled; verified files are reused.
109
+ - Inference runs in a **child process** (`packages/local/lib/worker/entry.js`, one per family
110
+ variant), which loads `sherpa-onnx-node`, owns that family's recognizer configuration
111
+ (`worker/adapters.js`) and speaks a private loopback HTTP protocol (ephemeral port bound to
112
+ `127.0.0.1`, a per-worker 64-hex bearer token passed through the child environment, JSON
113
+ envelopes) like the official SenseVoice provider. `worker/runtime.js` in the parent owns the
114
+ handshake, a serial decode queue, inference/idle timeouts, crash restart and termination on
115
+ plugin unload or variant switch. Switching variants stops the old worker before starting the new
116
+ one; only the selected family is resident at a time.
117
+ - VAD: the shared Silero VAD asset is downloaded alongside the model and used to cut long
118
+ recordings into 15–24 s segments for the families that truncate long inputs (FunASR Nano,
119
+ Qwen3-ASR); the others decode the whole utterance. Exact per-family configuration, language
120
+ mapping and streaming tail protocol: `docs/research/local-models.md`.
121
+ - Provisioning: `lib/provision/{download,archive,install}.js` implement source fallback, `.part`
122
+ files, streaming SHA-256, atomic renames, zip extraction (no new dependency) with a
123
+ path-traversal whitelist, and per-variant install state. Model data lives in
124
+ `core/lib/catalog/local.js`.
125
+
126
+ ### 3.5 Service HTTP API (`service`)
127
+
128
+ Registered as seven exact Fetch routes through `ctx.connection.fetch.register({ path, methods,
129
+ requestBody: 'buffered', fetch })` (`inject = ['connection']`), each under
130
+ `/api/better-voice-input/`. The connection layer owns the Host/Origin fence and browser
131
+ authentication (owner Peer only), so the handlers carry no hand-written same-origin check; the
132
+ WAV body is still capped before decoding. Success is HTTP 2xx with `{ ok: true, ... }`; failure is
133
+ a 4xx/5xx with `{ ok: false, code, message }`.
134
+
135
+ | Method + path | Purpose |
136
+ | --- | --- |
137
+ | `GET /state` | provider views from `ctx.speechToText.snapshot()`, masked config, cloud metadata, local install state, preferences, limits, dependency status |
138
+ | `POST /config` | `{ providerId, values }` — validate against the field descriptor and persist |
139
+ | `POST /select` | `{ providerId, language }` — `ctx.speechToText.configure(patch)` |
140
+ | `POST /prepare` | `{ providerId, downloadSource? }` — `ctx.speechToText.prepare(...)` |
141
+ | `POST /cancel-preparation` | `{ providerId }` |
142
+ | `POST /transcribe?language=auto` | raw `audio/wav` body (≤ `limits.maxAudioBytes`) — canonical WAV validation then `ctx.speechToText.transcribe`, returns `{ ok: true, text, audioSeconds, inferenceSeconds }` |
143
+ | `POST /preferences` | `{ releaseAction?, holdDelayMs?, cancelDistancePx?, hintDismissed?, composerHint? }` |
144
+
145
+ A JSON `{ audioBase64 }` body is also accepted on `/transcribe` for tests and as a fallback
146
+ carrier; base64 is decoded and validated the same way. `GET /state` is polled by the settings page
147
+ (1.5 s) while a preparation is running and once on open. It is cheap: in-memory snapshot + one
148
+ small file read.
149
+
150
+ ### 3.6 Settings page (`service` client half)
151
+
152
+ Registered into `plugins.bundle.config` keyed by `@ds-hu/dsh-better-voice-input`, following the
153
+ official `VoicePreparation` page pattern. Sections:
154
+
155
+ 1. **依赖状态** — official speech-to-text service present? selected provider + language.
156
+ 2. **云端服务** — one card per vendor: configured/unconfigured badge, API key (write-only +
157
+ masked display), base URL, model, vendor-specific fields, env fallback hint, docs link.
158
+ 3. **本地模型** — one card per family: variant selector, download / cancel / progress, runtime
159
+ readiness, languages and disk/memory estimate.
160
+ 4. **交互** — release action (insert draft / send, default insert), hold delay, slide-up cancel
161
+ distance, composer placeholder hint (`composerHint`, default on: “发消息或按住说话”), first-run
162
+ hint reset.
163
+ 5. **说明** — audio destination per provider (cloud upload vs local), dependency on the
164
+ official plugin, where data is written.
165
+
166
+ Only theme tokens (`--dsw-*`) are used; controls are written locally (no Harness client imports).
167
+
168
+ ## 4. Browser design — hold to talk (`input` client half)
169
+
170
+ ### 4.1 Registration
171
+
172
+ `lib/client.js` is a lazy-CJS module. Inside `apply(ctx)`, after `ctx.inject(['slots','locale'])`:
173
+
174
+ - register locale dictionaries (zh/en) via `ctx.locale.register(NS, ...)`;
175
+ - `ctx.slots.inject('conversation.input.overlay', () => ctx.slots.register({ name: 'conversation.input.overlay', id: 'bvi-input', locale: NS }, VoiceGesture))`.
176
+
177
+ `conversation.input.overlay` is a session-scoped list slot rendered inside the composer card, so
178
+ the component receives `inputActions` (captureInsertion/insertText/setDraft/submit) and renders a
179
+ zero-size anchor. The overlay itself portals to `document.body` (fixed overlay; sanctioned by the
180
+ slot contract). The slot id is stable, so re-registration on graph updates is idempotent.
181
+
182
+ ### 4.2 Gesture detection (unified desktop + touch)
183
+
184
+ - A capture-phase `pointerdown` on the composer card (`[data-composer-card]`) starts a hold
185
+ candidate. Pointer events cover mouse, touch and pen with one code path.
186
+ - Start conditions: primary button only; not inside an interactive control (`button`, `a`,
187
+ `input`, `select`, `[role=button]`, `[contenteditable=false]`); composer editable and not
188
+ disabled; no active session; not while a transcript is being inserted.
189
+ - Hold window: default 280 ms (`preferences.holdDelayMs`), movement <= 8 px, pointer not
190
+ released/cancelled, window not blurred.
191
+ - On hold commit: suppress `contextmenu`/`selectstart`, clear the text selection, add a
192
+ `user-select: none` / `touch-action: none` class to the editor for the session, start the
193
+ microphone pipeline, show the overlay.
194
+ - While recording: `pointermove` drives the slide-up distance; release -> finish, slide-up past
195
+ `cancelDistancePx` -> cancel state (with hysteresis: re-arm below 60 %), `pointercancel`,
196
+ Escape, window blur and tab hide cancel. Page scroll is prevented during the session.
197
+ - Desktop and mobile share this exact state machine; the only platform-specific inputs are the
198
+ pointer events themselves and optional `navigator.vibrate(10)`.
199
+
200
+ ### 4.3 Overlay states (DeepSeek App replication)
201
+
202
+ Full-screen (100dvh, safe-area aware), portal to body:
203
+
204
+ | State | Background | Status text | Visual |
205
+ | --- | --- | --- | --- |
206
+ | preparing | blue gradient | `正在准备麦克风…` | dim waveform placeholder |
207
+ | recording | deep navy -> electric blue gradient | `松手插入,上滑取消` (or `松手发送,…`) | live waveform bars |
208
+ | cancel-armed | deep maroon -> red gradient | `松手取消` | waveform bars in red |
209
+ | transcribing | last gradient | `正在识别…` | soft pulsing dots |
210
+ | error | last gradient | failure sentence | dismiss on tap/release |
211
+
212
+ Motion: 160 ms fade in, 200 ms gradient crossfade, waveform driven by a 60 fps meter from the
213
+ audio worklet. Typography: system UI for chrome, a serif stack for the status line to match the
214
+ reference; text is centered around 38 % of the viewport height, waveform band around 62 %.
215
+
216
+ ### 4.4 Audio pipeline
217
+
218
+ - `getUserMedia({ audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true,
219
+ autoGainControl: true } })`; AudioContext kept alive (unlocked from the initial pointer gesture
220
+ so iOS/desktop autoplay policies are satisfied), AudioWorklet (inline blob module) captures
221
+ Float32 frames and posts RMS/peak meter values at ~30 Hz.
222
+ - Stop: disconnect tracks, resample to 16 kHz linear interpolation, encode canonical mono PCM16
223
+ WAV (44-byte header), enforce `limits.maxAudioBytes`/`maxDurationSeconds`.
224
+ - The recording limit auto-finishes the take instead of dropping it.
225
+ - Permission errors and pipeline failures close the overlay and show a localized inline notice
226
+ above the composer; one sentence, no modal.
227
+
228
+ ### 4.5 Result handling
229
+
230
+ - `insert` (default): `inputActions.insertText(text, inputActions.captureInsertion())`; if the
231
+ draft moved concurrently, fall back to `setDraft(current + text)`; empty/whitespace -> notice.
232
+ - `send`: insert with the same guards, then `inputActions.submit()` on the next microtask.
233
+ - Cancel: abort fetch + stop capture, no text.
234
+ - While a take is running, a second long-press is ignored.
235
+
236
+ ## 5. Data, privacy, security
237
+
238
+ - Audio leaves the host only if the selected provider is a cloud provider, sent by that
239
+ provider's own request; local models keep audio in the worker process. The settings page states
240
+ this per provider (`location`).
241
+ - API keys live in `<dataRoot>/config.json` (0600) and are never returned unmasked; environment
242
+ fallbacks are read-only.
243
+ - The HTTP API is same-origin only, validates content type/length, caps base64 audio to the
244
+ provider-neutral WAV limit, and does not accept provider selection outside the registry.
245
+ - No model-facing tools, no session events, no changes to the user's profile outside
246
+ `ctx.speechToText.configure()` (the documented seam for selection).
247
+
248
+ ## 6. Testing and release
249
+
250
+ - `npm test` runs `node --test`: core store/WAV/HTTP/provider-factory invariants, per-provider
251
+ request/response adapters against a local mock HTTP server, service API/host against a fake
252
+ `speechToText` service, local catalog/provision/worker protocol and recognizer-config builders
253
+ (no native load), both browser entries loaded in a `vm` harness (factory contract, placement,
254
+ gesture state machine, WAV encoder, preference handling), and one cross-component test that
255
+ holds the 21-provider and release/documentation contracts together.
256
+ - `npm run lint` is part of `npm run check`; CI (`.github/workflows/ci.yml`) is the only place
257
+ these run, on Node 20 and 22.
258
+ - `.github/workflows/release.yml` publishes core -> service/cloud/local/input -> bundle on a `v*`
259
+ tag, then creates the GitHub release.
260
+ - Optional `workflow_dispatch` smoke workflow (`local-models-smoke.yml`) downloads a pinned model
261
+ (or every family, one dispatch at a time) and runs one real transcription; it never runs on PRs.
262
+ Evidence for every catalog variant is recorded in `docs/VERIFICATION.md`.
263
+
264
+ ## 7. Non-goals for v0.1
265
+
266
+ - Streaming/partial transcripts (the reference app also shows no partial text).
267
+ - Selecting a browser microphone device (system default only).
268
+ - Downloading models in the browser; all model I/O stays on the host.
269
+ - Replacing the official recording component (both can coexist; keep the official bundle's
270
+ `ui-voice-input` row on when you want its microphone picker and setup dialog).