@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.
@@ -0,0 +1,300 @@
1
+ # Module contracts (v0.1)
2
+
3
+ Implementation contract between the five packages. Names are exact: the same identifiers are
4
+ imported across packages and asserted by tests. Plain ESM, JSDoc only.
5
+
6
+ ## `@ds-hu/dsh-bvi-core` (library, host)
7
+
8
+ ```js
9
+ // lib/index.js re-exports the modules below.
10
+ export { CONFIG_VERSION, ConfigError, defaultConfig, resolveDataRoot, readConfig, writeConfig,
11
+ updateConfig, defaultPreferences, sanitizePreferences, maskSecret } from './config-store.js'
12
+ export { WavError, parseWav, validateWav, wavToFloat32, wavToPcm16, encodeWav, resampleLinear,
13
+ MAX_WAV_BYTES } from './wav.js'
14
+ export { PROVIDER_ERROR_CODES, ProviderError, fetchJson, postJson, postMultipart,
15
+ timeoutSignal } from './http.js'
16
+ export { createCloudProvider, readProviderSettings } from './cloud-provider.js'
17
+ export { CLOUD_CATALOG } from './catalog/cloud.js'
18
+ export { LOCAL_MODELS, SHARED_ASSETS } from './catalog/local.js'
19
+ ```
20
+
21
+ `core` is a library, never a Loader row: it declares neither `dsh.bundle` nor `dsh.client`.
22
+
23
+ ### config-store.js
24
+
25
+ One JSON document per data root (`<dataRoot>/config.json`):
26
+
27
+ ```js
28
+ {
29
+ version: 1,
30
+ providers: { 'bvi-cloud-openai': { apiKey: '…', baseURL: '…', model: '…' } },
31
+ local: { 'bvi-local-sensevoice': { variant: 'small-int8' } },
32
+ preferences: { releaseAction: 'insert', holdDelayMs: 280, cancelDistancePx: 72,
33
+ hintDismissed: false, composerHint: true },
34
+ }
35
+ ```
36
+
37
+ - `resolveDataRoot(input)` — accepts an explicit absolute/relative path or `{ dataRoot }` and
38
+ returns it resolved. The library **never guesses a home directory**: a missing root throws
39
+ `ConfigError('missing-data-root')`. The service row resolves the root before calling it
40
+ (`config.dataRoot`, else `ctx.get('dshHomePath')('better-voice-input')`).
41
+ - `defaultConfig()` — `{ version: 1, providers: {}, local: {}, preferences: defaultPreferences() }`.
42
+ - `defaultPreferences()` — the five keys above; `composerHint` defaults to `true` (the composer
43
+ shows the “发消息或按住说话” hint until the user hides it in the settings page).
44
+ - `readConfig(dataRoot)` — missing file → default config; unknown keys are dropped; each invalid
45
+ preference falls back to its default (tolerant read). A structurally corrupt document throws
46
+ `ConfigError` with code `invalid-json`, `invalid-config`, `unsupported-version` or
47
+ `read-failed` — it is never silently rewritten.
48
+ - `writeConfig(dataRoot, config)` — validates, writes atomically (`<pid>.<rand>.tmp` + `rename`),
49
+ directory `0700`, file `0600`; throws `ConfigError('write-failed')` on I/O errors.
50
+ - `updateConfig(dataRoot, mutate)` — serialized read-modify-write per data root (one promise
51
+ chain), passes a `structuredClone` to `mutate` (sync or async), persists the returned value and
52
+ returns the next document. A rejected mutation does not break the queue.
53
+ - `sanitizePreferences(patch, base)` — strict validation for the HTTP path: known keys only,
54
+ `releaseAction ∈ {'insert','send'}`, `holdDelayMs ∈ [150, 1000]`, `cancelDistancePx ∈ [40, 200]`,
55
+ `hintDismissed`/`composerHint` booleans; invalid known values throw
56
+ `ConfigError('invalid-preferences')`.
57
+ - `maskSecret(value)` — `''` for an empty value, `'…'` for short ones, otherwise
58
+ `first3…last4`; never returns the full value.
59
+
60
+ ### wav.js
61
+
62
+ Canonical intake is a 16 kHz mono PCM16 WAV written by the browser recorder.
63
+
64
+ - `MAX_WAV_BYTES = 4 * 1024 * 1024` (the service may lower it through `limits`).
65
+ - `parseWav(bytes)` → `{ sampleRate, channels, bitsPerSample, audioFormat, dataOffset,
66
+ dataBytes, byteLength }`; walks RIFF chunks (extra chunks and word padding are accepted) and
67
+ rejects a header whose declared sizes disagree with the bytes.
68
+ - `validateWav(bytes, { maxAudioBytes, maxDurationSeconds })` → `{ sampleRate, channels,
69
+ bitsPerSample, durationSeconds, dataBytes }`; `WavError.code ∈ {'empty','too-large','not-wav',
70
+ 'unsupported-format','too-long'}` (format must be PCM16 mono 16 kHz; max duration default 120 s).
71
+ - `wavToPcm16` / `wavToFloat32` (mono `[-1,1]`) / `encodeWav(samples, sampleRate)` /
72
+ `resampleLinear(samples, fromRate, toRate)` — pure typed-array helpers, no Node built-ins.
73
+
74
+ ### http.js
75
+
76
+ - `ProviderError extends Error` with `code ∈ PROVIDER_ERROR_CODES = ['missing-credential', 'http',
77
+ 'timeout', 'network', 'parse', 'unsupported']` and optional `status`.
78
+ - `fetchJson(url, init, { timeoutMs = 30_000, fetchImpl = fetch })` → `{ status,
79
+ headers /* lowercase plain object */, body /* parsed JSON or undefined */, text }`. A non-2xx
80
+ status is a normal result; the vendor adapter decides whether to parse the error body. Transport
81
+ failures become `ProviderError('network')`, a fired timeout becomes `ProviderError('timeout')`,
82
+ and the caller's own abort is rethrown unchanged.
83
+ - `postJson` / `postMultipart(url, fields, fileField, file, init)` — request envelopes; the
84
+ multipart helper never sets a manual `Content-Type` (the runtime owns the boundary).
85
+ - `timeoutSignal(signal, ms)` — merges the caller signal with `AbortSignal.timeout(ms)`.
86
+
87
+ ### cloud-provider.js
88
+
89
+ `createCloudProvider(descriptor, { readConfig, env, fetchImpl })` builds the official provider
90
+ object from a **runtime descriptor** (metadata + one of `buildRequest`/`parseResponse` or
91
+ `execute`, assembled by `packages/cloud`, never by `core`):
92
+
93
+ ```js
94
+ {
95
+ info: { id, name, location: 'cloud', languages, setupEstimate?, downloadSources? },
96
+ async transcribe({ audio, language }, signal) {
97
+ const config = await readConfig() // re-read per recording
98
+ const { settings, missing } = readProviderSettings(config, descriptor, env)
99
+ if (missing.length > 0) throw ProviderError('missing-credential', 'Missing required setting: …')
100
+ if (descriptor.execute) return await descriptor.execute({ settings, wav: audio, language, signal, fetchImpl })
101
+ const request = await descriptor.buildRequest({ settings, wav: audio, language })
102
+ const response = await fetchJson(request.url, { ...request.init, signal }, { fetchImpl })
103
+ return descriptor.parseResponse(response) // { text, audioSeconds?, inferenceSeconds? }
104
+ },
105
+ }
106
+ ```
107
+
108
+ - `readProviderSettings(config, descriptor, env)` is a pure helper. Priority (lowest first):
109
+ field `default`, then `env[field.env]`, then the saved `config.providers[descriptor.id]` value
110
+ (the user's saved value wins; an empty string counts as “not set” and falls back to the
111
+ environment again). Returns `{ settings, missing }` where `missing` lists required keys as
112
+ `{ key, env? }`. Saved keys without a field descriptor are kept for the adapter.
113
+ - The factory trims the transcript text, falls back to the WAV header for `audioSeconds` and to
114
+ the elapsed wall time for `inferenceSeconds`, and maps unexpected adapter errors to
115
+ `ProviderError('parse'|'unsupported')`; `ProviderError`s and caller aborts pass through
116
+ unchanged. The adapter owns the vendor wire format and the vendor error messages.
117
+ - The 13 single-request vendors use `buildRequest` + `parseResponse`. Soniox (`execute`) owns its
118
+ own upload → create → poll → transcript sequence, receives `signal`/`fetchImpl` and cleans up
119
+ remote resources best-effort.
120
+
121
+ ### catalog/cloud.js (metadata, owned by `packages/cloud`)
122
+
123
+ `CLOUD_CATALOG` exports **data only** — the single source of provider identity, settings form,
124
+ languages and docs. `core` must not import `packages/cloud` (one-way dependency) and a published
125
+ `core` tarball cannot resolve sibling workspace paths, so the request/response code stays in the
126
+ cloud package and is joined with these records there:
127
+
128
+ ```js
129
+ {
130
+ id: 'bvi-cloud-openai', vendor: 'openai', location: 'cloud',
131
+ name: { zh: 'OpenAI 语音识别', en: 'OpenAI speech recognition' },
132
+ languages: ['auto', 'zh', 'en', ...],
133
+ docs: 'https://platform.openai.com/docs/guides/speech-to-text',
134
+ env: ['OPENAI_API_KEY'],
135
+ fields: [
136
+ { key: 'apiKey', type: 'secret', required: true, env: 'OPENAI_API_KEY',
137
+ label: { zh: 'API Key', en: 'API key' } },
138
+ { key: 'baseURL', type: 'url', default: 'https://api.openai.com/v1', label: {...} },
139
+ { key: 'model', type: 'text', default: 'gpt-4o-transcribe', label: {...} },
140
+ { key: 'mode', type: 'select', default: 'fast', label: {...},
141
+ options: [{ value: 'fast', label: { zh: '快速', en: 'Fast' } }] },
142
+ ],
143
+ info: { id, name, location, languages }, // name is the zh display name
144
+ }
145
+ ```
146
+
147
+ The 14 vendors are the documented ones in `docs/research/cloud-providers.md`. The provider id is
148
+ `bvi-cloud-<vendor>`. `packages/cloud/lib/catalog.js` joins each record with its adapter
149
+ (`createCloudDescriptors()` / `CLOUD_DESCRIPTORS` / `getCloudDescriptor(id)`) to build the runtime
150
+ descriptors consumed by `createCloudProvider`.
151
+
152
+ ### catalog/local.js (metadata, owned by `packages/local`)
153
+
154
+ `LOCAL_MODELS` lists the seven sherpa-onnx families (11 variants) and `SHARED_ASSETS` the Silero
155
+ VAD / optional punctuation assets. The file is **data only** (no functions, no Node APIs) and
156
+ physically lives in `core` so the service can render the local-model settings page without
157
+ depending on the local row; its owner is `packages/local`, which turns `runtime` into the
158
+ sherpa-onnx configuration inside its worker:
159
+
160
+ ```js
161
+ {
162
+ id: 'bvi-local-sensevoice', family: 'sensevoice', location: 'host-local',
163
+ name: { zh, en }, languages: ['auto', 'zh', 'en', 'ja', 'ko', 'yue'],
164
+ docs: 'https://…',
165
+ downloadSources: ['https://huggingface.co', 'https://hf-mirror.com'],
166
+ defaultVariant: 'small-int8',
167
+ runtime: { kind: 'offline' | 'online', threads, vad, segmentation },
168
+ setupEstimate: { recommendedDiskBytes, expectedMemoryBytes, minimumMinutes, maximumMinutes },
169
+ variants: [{
170
+ id, label: { zh, en }, bytes,
171
+ files: [{ name, relativePath, bytes, sha256, url, mirrorURL? }],
172
+ }],
173
+ }
174
+ ```
175
+
176
+ `SHARED_ASSETS` carries the same `files`/`bytes`/`sha256` shape for the assets every family
177
+ shares. Variant selection is stored in `config.local[id].variant`; the service forwards it to the
178
+ local provider as `ctx.speechToText.prepare(id, { variant })` (the official seam passes the
179
+ options object through unchanged) so a custom data root cannot desynchronize the download from
180
+ the settings page.
181
+
182
+ ## `@ds-hu/dsh-bvi-service` (host + client)
183
+
184
+ ### Host (`lib/index.js`)
185
+
186
+ `name = 'bvi-service'`, `inject = ['connection']`; the speech registry is optional and read with
187
+ `ctx.get('speechToText')` so the settings page still loads while the official experimental voice
188
+ input bundle is disabled.
189
+
190
+ `apply(ctx, config)` resolves the data root (`config.dataRoot`, else
191
+ `ctx.get('dshHomePath')('better-voice-input')`; both go through `resolveDataRoot`), loads the two
192
+ catalogs tolerantly (`import.meta.resolve` + `existsSync`; a missing component package means an
193
+ empty list, a present-but-broken catalog rejects the row), then registers **seven exact Fetch
194
+ routes** with `ctx.connection.fetch.register({ path, methods, requestBody: 'buffered', fetch })`
195
+ inside `ctx.effect`. The Connection layer owns the Host/Origin fence and browser authentication
196
+ (the owner Peer), so the handlers contain no hand-written same-origin check.
197
+
198
+ | Method + path | Request | Purpose |
199
+ | --- | --- | --- |
200
+ | `GET /api/better-voice-input/state` | — | provider views, masked config, catalogs, install state, preferences, limits, dependency status |
201
+ | `POST /api/better-voice-input/config` | `{ providerId, values }` | validate against the catalog field descriptors and persist |
202
+ | `POST /api/better-voice-input/select` | `{ providerId, language }` | `ctx.speechToText.configure(patch)` |
203
+ | `POST /api/better-voice-input/prepare` | `{ providerId, downloadSource? }` | `ctx.speechToText.prepare(id, { variant?, downloadSource? })` |
204
+ | `POST /api/better-voice-input/cancel-preparation` | `{ providerId }` | `ctx.speechToText.cancelPreparation(id)` |
205
+ | `POST /api/better-voice-input/transcribe?language=…` | raw `audio/wav` (≤ 8 MiB) | validate canonical WAV, `ctx.speechToText.transcribe`, `{ ok: true, text, audioSeconds, inferenceSeconds }` |
206
+ | `POST /api/better-voice-input/preferences` | partial preferences | validate with `sanitizePreferences` and persist |
207
+
208
+ Body limits: JSON mutations 64 KiB (`MAX_JSON_BODY_BYTES`), transcribe 8 MiB
209
+ (`MAX_TRANSCRIBE_BODY_BYTES`), audio then capped by `limits.maxAudioBytes` after the WAV header is
210
+ checked. `/transcribe` also accepts the JSON compatibility form `{ audioBase64, language?,
211
+ providerId? }` for tests and non-browser callers.
212
+
213
+ Success is HTTP 2xx with `{ ok: true, ... }`; failure is a non-2xx with
214
+ `{ ok: false, code, message }`, where the code is stable (`audio-*`, `provider-*`,
215
+ `invalid-*`, `config-error`, `dependency-missing`, `unknown-provider`, `body-too-large`,
216
+ `unsupported-media-type`, `cancelled`, `internal`, …).
217
+
218
+ `GET /state` document (frozen; the settings page and the input component rely on it):
219
+
220
+ ```json
221
+ {
222
+ "ok": true,
223
+ "dependency": { "speechToText": true },
224
+ "providers": [{ "id": "bvi-cloud-openai", "name": "…", "location": "cloud",
225
+ "languages": ["auto", "zh"],
226
+ "preparation": { "phase": "ready" } }],
227
+ "selection": { "providerId": "bvi-cloud-openai", "language": "zh" },
228
+ "config": { "bvi-cloud-openai": { "configured": true,
229
+ "fields": { "apiKey": "sk-…4f2a", "baseURL": "…" } } },
230
+ "cloud": [{ "id": "bvi-cloud-openai", "name": { "zh": "…", "en": "…" },
231
+ "languages": [], "env": [], "fields": [], "docs": "…", "configured": true }],
232
+ "local": [{ "id": "bvi-local-sensevoice", "name": { "zh": "…", "en": "…" },
233
+ "languages": [], "variants": [], "defaultVariant": "…", "variant": "…",
234
+ "downloadSources": [], "install": { "phase": "unprepared" } }],
235
+ "preferences": { "releaseAction": "insert", "holdDelayMs": 280, "cancelDistancePx": 72,
236
+ "hintDismissed": false, "composerHint": true },
237
+ "limits": { "maxAudioBytes": 4194304, "maxDurationSeconds": 120 }
238
+ }
239
+ ```
240
+
241
+ `providers[].preparation` is normalized for the browser: in-flight official phases
242
+ (`downloading`, `checking`, `loading`, `cancelling`) become `preparing` with an integer
243
+ `progress` 0–100 when the download totals are known; `phase: 'failed'` carries `error`; other
244
+ phases pass through (`ready`, `standby`, `waking`, `unprepared`, `cancelled`). `local[].install`
245
+ uses the same normalization for the local provider's official preparation state
246
+ (`{ phase: 'unprepared' }` while the row is not registered). Secrets only ever appear masked.
247
+
248
+ `lib/api.js` is the testable half: `createApi({ store, catalogs, getSpeech, env, logger, limits })`
249
+ returns `state`, `saveConfig`, `select`, `prepare`, `cancelPreparation`, `transcribe` and
250
+ `savePreferences`; `toErrorPayload(error)` maps `ApiError` / `WavError` / `ProviderError` /
251
+ `ConfigError` / aborts to the HTTP status and envelope above. `lib/store.js` wraps the data root
252
+ in `read()`/`update()`.
253
+
254
+ ### Client (`lib/client.js`)
255
+
256
+ A classic lazy-CJS module (`window.__ModuleLoader__.load({ id, factory })`, `require('react')`
257
+ only). `apply(ctx)` registers the zh/en dictionaries (`ctx.locale.register(NS, …)`), a
258
+ module-owned `<style data-plugin="@ds-hu/dsh-better-voice-input">` using theme tokens only, and the
259
+ bundle configuration page:
260
+
261
+ ```js
262
+ ctx.slots.inject('plugins.bundle.config', () =>
263
+ ctx.slots.register({ name: 'plugins.bundle.config', key: '@ds-hu/dsh-better-voice-input',
264
+ locale: 'better-voice-input' }, SettingsPage))
265
+ ```
266
+
267
+ The owner passes `{ view: 'summary' | 'page' }` and no `form`, so the page draws its own form and
268
+ persists through the HTTP API above (`GET /state` once on open, then polls every 1.5 s while a
269
+ local model is preparing). Sections: dependency status, default provider/language, cloud vendor
270
+ cards (write-only + masked secrets, env fallback hint, docs link), local model cards (variant,
271
+ download/cancel/progress, estimate), composer preferences (`releaseAction`, `holdDelayMs`,
272
+ `cancelDistancePx`, `composerHint`, first-run hint reset) and a notes card. The summary view shows
273
+ the configured cloud/local counts.
274
+
275
+ ## `@ds-hu/dsh-bvi-input` (client)
276
+
277
+ `lib/client.js` registers the hold-to-talk component into `conversation.input.overlay`
278
+ (id `bvi-input`). It talks only to the service API (`GET /api/better-voice-input/state`,
279
+ `POST /api/better-voice-input/prepare`, `POST /api/better-voice-input/cancel-preparation`,
280
+ `POST /api/better-voice-input/transcribe?language=…`). Gesture, overlay and audio rules:
281
+ `docs/ARCHITECTURE.md` §4.
282
+
283
+ ## Testing seams
284
+
285
+ Every module is testable without native dependencies and without a host process:
286
+
287
+ - `core`: `node:test` with temporary data roots and fake `fetch` implementations; no native code.
288
+ - cloud adapters: `createCloudProvider` with a fake `fetchImpl` + `readConfig`/`env` fixtures;
289
+ `test/cloud-adapters.test.mjs` imports the adapter modules and the shared data catalog.
290
+ - local catalog: data-only invariants (paths, byte counts, digests); no model download.
291
+ - service logic: `createApi` with an in-memory store, fake catalog arrays and a fake
292
+ `ctx.speechToText` registry (`test/service-api.test.mjs`).
293
+ - service host: `apply(ctx, { dataRoot })` with a fake Cordis context whose
294
+ `connection.fetch.register` records the routes; the tests drive the handlers with Fetch
295
+ `Request`/`Response` objects (`test/service-host.test.mjs`).
296
+ - browser entries: `test/client-harness.mjs` evaluates the classic script in a `vm` context,
297
+ captures `window.__ModuleLoader__.load({ id, factory })`, calls `factory(require)` with a
298
+ minimal React hook runtime, a fake document, fake timers and a fetch stub, and exposes the
299
+ rendered tree plus the static contract (module id, required modules, dictionaries, styles,
300
+ slot registration). The settings page and the input component are covered this way.
package/docs/DETAIL.md ADDED
@@ -0,0 +1,64 @@
1
+ # Better voice input for DeepSeek Harness
2
+
3
+ **21 speech-recognition services and a DeepSeek-App-style hold-to-talk composer.**
4
+
5
+ ![Hold the composer to record, slide up to cancel, release to insert](https://raw.githubusercontent.com/ds-hu/dsh-better-voice-input/main/docs/preview-en.svg)
6
+
7
+ This bundle extends the official experimental voice input plugin
8
+ (`@deepseek-ai/dsh-experimental-voice-input-bundle`) in two directions.
9
+
10
+ ## 1 · More recognizers
11
+
12
+ The official bundle ships one host-local model. This bundle registers **21 services** on the same
13
+ `ctx.speechToText` seam and adds a settings page to the Plugins panel:
14
+
15
+ - **14 cloud providers** — SiliconFlow, Volcengine, ElevenLabs, OpenAI, OpenRouter, DashScope,
16
+ DeepSeek, Gemini, Xiaomi MiMo, Tencent Cloud, Soniox, StepAudio, Zhipu and Cohere. Each has its
17
+ own form for API key, base URL, model and vendor options; environment variables work as a
18
+ read-only fallback.
19
+ - **7 local model families** — SenseVoice, FunASR Nano, Qwen3-ASR, Parakeet, GigaAM, FireRedASR
20
+ and X-ASR, each with selectable variants. They run on this machine through `sherpa-onnx-node`,
21
+ downloaded on first use into `$DSH_HOME/better-voice-input/models` and verified file by file
22
+ against pinned SHA-256 digests. Local inference runs in a child process, so a model failure never
23
+ takes Harness down.
24
+
25
+ Components: **更多语音识别模型 · 云端**, **更多语音识别模型 · 本地**, and **语音识别服务**
26
+ (config store, the same-origin HTTP API, and this settings page).
27
+
28
+ ## 2 · A better composer interaction
29
+
30
+ The official voice UI is click-to-record. This bundle reproduces the DeepSeek App instead:
31
+
32
+ - **Press and hold the composer** (mouse, touch or pen — one gesture detector for desktop and
33
+ mobile). After a short hold the full-screen overlay appears with a live waveform.
34
+ - **Slide up to cancel.** The overlay turns from blue to red once you pass the cancel distance;
35
+ release there to discard the recording. Release anywhere else to transcribe. A small dead band
36
+ prevents accidental cancel/send toggling.
37
+ - **Release behavior is yours.** By default the transcript is inserted into the draft at the
38
+ caret; a setting switches release to *send*.
39
+ - **The composer hint reads “发消息或按住说话”** when the draft is empty, and the overlay wording
40
+ follows the release behavior (“松手插入,上滑取消” / “松手发送,上滑取消”).
41
+ - Escape, a hidden tab or a lost focus cancels the recording — the microphone never stays open in
42
+ the background.
43
+
44
+ Component: **更好的语音输入**.
45
+
46
+ ## Requirements
47
+
48
+ DeepSeek Harness **>= 0.2.2-rc.5 < 0.3.0** and Node.js **>= 20.19**. The official **Voice input**
49
+ bundle must stay enabled — it provides the speech-to-text registry this bundle extends; its own
50
+ mic UI may be disabled. Cloud providers need the vendor's API key; local models need disk space
51
+ and a CPU (no GPU required).
52
+
53
+ ## Privacy
54
+
55
+ Speech is sent only to the service you chose — your configured vendor endpoint, or this machine for
56
+ local models. There is no telemetry and no relay. API keys stay on the host (masked in the browser,
57
+ `0600` on disk). Model downloads come from the upstream sherpa-onnx repositories and are verified
58
+ against pinned digests.
59
+
60
+ ## Links
61
+
62
+ - [Source, documentation and full model tables](https://github.com/ds-hu/dsh-better-voice-input)
63
+ - [Architecture](https://github.com/ds-hu/dsh-better-voice-input/blob/main/docs/ARCHITECTURE.md)
64
+ - [NOTICE (third-party attribution)](https://github.com/ds-hu/dsh-better-voice-input/blob/main/NOTICE)
@@ -0,0 +1,55 @@
1
+ # 更好的语音输入
2
+
3
+ **21 个语音识别服务,以及与 DeepSeek App 一致的「按住说话」输入体验。**
4
+
5
+ ![按住输入框录音,上滑取消,松手插入](https://raw.githubusercontent.com/ds-hu/dsh-better-voice-input/main/docs/preview.svg)
6
+
7
+ 本 bundle 从两个方向扩展官方实验性语音输入插件
8
+ (`@deepseek-ai/dsh-experimental-voice-input-bundle`)。
9
+
10
+ ## 一 · 更多识别模型
11
+
12
+ 官方 bundle 只内置一个本地模型。本 bundle 在同一个 `ctx.speechToText` 接缝上注册 **21 个服务**,
13
+ 并在插件面板里增加自己的设置页:
14
+
15
+ - **14 家云端服务** —— 硅基流动、火山引擎、ElevenLabs、OpenAI、OpenRouter、阿里云百炼、
16
+ DeepSeek、Gemini、小米 MiMo、腾讯云、Soniox、阶跃星辰、智谱、Cohere。每家都有独立表单
17
+ (API Key、base URL、model、供应商选项),环境变量可作为只读兜底。
18
+ - **7 个本地模型系列** —— SenseVoice、FunASR Nano、Qwen3-ASR、Parakeet、GigaAM、FireRedASR、
19
+ X-ASR,每个系列可选不同变体。它们通过 `sherpa-onnx-node` 在本机运行,首次使用时下载到
20
+ `$DSH_HOME/better-voice-input/models`,逐文件校验固定的 SHA-256;推理在子进程中运行,
21
+ 单个模型崩溃不会影响 Harness。
22
+
23
+ 组件:**更多语音识别模型 · 云端**、**更多语音识别模型 · 本地**、**语音识别服务**
24
+ (配置存储、同源 HTTP API、本设置页)。
25
+
26
+ ## 二 · 更好的输入交互
27
+
28
+ 官方语音 UI 是点击录音。本 bundle 复刻 DeepSeek App 的交互:
29
+
30
+ - **按住输入框说话**(鼠标、触屏、手写笔共用同一套长按判定)。短暂按住后出现全屏浮层与实时波形。
31
+ - **上滑取消**:上滑超过取消距离后浮层由蓝变红,此时松手放弃录音;在其他位置松手则开始转写。
32
+ 一段回滞区间避免松手瞬间在「取消/发送」之间抖动。
33
+ - **松手行为可配置**:默认把识别结果插入草稿光标处;在设置里可改为松手直接发送。
34
+ - **草稿为空时组合框提示为「发消息或按住说话」**,浮层文案跟随松手行为(
35
+ 「松手插入,上滑取消」/「松手发送,上滑取消」)。
36
+ - Esc、切到后台标签页、窗口失焦都会取消录音——麦克风不会在后台保持开启。
37
+
38
+ 组件:**更好的语音输入**。
39
+
40
+ ## 环境要求
41
+
42
+ DeepSeek Harness **>= 0.2.2-rc.5 < 0.3.0**,Node.js **>= 20.19**。官方**语音输入** bundle 必须保持
43
+ 启用(它提供本 bundle 扩展的语音转写注册表),但它自带的麦克风 UI 可以关闭。云端服务需要供应商的
44
+ API Key;本地模型需要磁盘空间与 CPU,无需 GPU。
45
+
46
+ ## 隐私
47
+
48
+ 语音只会发送到你所选择的服务——你配置的云端接口,或本地模型(完全在本机)。没有遥测,没有中转。
49
+ API Key 保存在 host(浏览器只看掩码,磁盘权限 `0600`)。模型从 sherpa-onnx 上游仓库下载,并按固定摘要校验。
50
+
51
+ ## 链接
52
+
53
+ - [源码、文档与完整模型表](https://github.com/ds-hu/dsh-better-voice-input)
54
+ - [架构说明](https://github.com/ds-hu/dsh-better-voice-input/blob/main/docs/ARCHITECTURE.md)
55
+ - [NOTICE(第三方归属)](https://github.com/ds-hu/dsh-better-voice-input/blob/main/NOTICE)
@@ -0,0 +1,58 @@
1
+ # Verification record
2
+
3
+ This project never runs builds, tests, linters or browsers on a development laptop. CI is the
4
+ only verifier; this file records what the gates actually proved for the release, with links to the
5
+ workflow runs. The repository is public, so every link is reproducible.
6
+
7
+ ## Quality gate
8
+
9
+ `.github/workflows/ci.yml` runs `npm ci && npm run check` (eslint + `node --test`) on Node 20 and
10
+ Node 22, then verifies the exact file list each package would publish
11
+ (`scripts/verify-packages.mjs`). The release workflow repeats the gate on the tagged tree before
12
+ publishing.
13
+
14
+ - Latest green run on `main`: see the [CI runs](https://github.com/ds-hu/dsh-better-voice-input/actions/workflows/ci.yml).
15
+ - Test suites: core config store / WAV / HTTP / cloud provider factory, 14 cloud wire-format
16
+ adapters against recorded responses, service API and host routes against a fake speech registry,
17
+ local catalog / downloads / zip extraction / provider preparation / worker protocol, both
18
+ browser entries in a `vm` React harness, plus a cross-component test that holds the
19
+ 21-provider, release-order and documentation contracts together.
20
+
21
+ ## Local models — real download and inference
22
+
23
+ `.github/workflows/local-models-smoke.yml` is a manual workflow that downloads a pinned model,
24
+ spawns the real worker process with `sherpa-onnx-node`, and transcribes the same speech sample. It
25
+ is the acceptance test for everything the unit tests cannot cover. **All eleven catalog variants
26
+ passed** before `v0.1.0`:
27
+
28
+ | Variant | Workflow run | Transcript | Inference |
29
+ | --- | --- | --- | --- |
30
+ | sensevoice / small-int8 | [47617128571](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617128571) | 开放时间早上9点至下午5点。 | 0.73 s |
31
+ | sensevoice / small-full | [47617357697](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617357697) | 开放时间早上9点至下午5点。 | 0.56 s |
32
+ | funasr-nano / nano-int8 | [47617223657](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617223657) | 开放时间早上九点至下午五点 | 3.19 s |
33
+ | funasr-nano / mlt-int8 (zip source) | [47617347277](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617347277) | 开饭时间早上九点至下午五点。 | 4.48 s |
34
+ | qwen3-asr / qwen3-0.6b-int8 | [47617230146](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617230146) | 开放时间:早上九点至下午五点。 | 2.59 s |
35
+ | qwen3-asr / qwen3-1.7b-int8 (zip source) | [47617350807](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617350807) | 开饭时间早上九点至下午五点。 | 4.64 s |
36
+ | parakeet / 0.6b-v3-int8 | [47617236124](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617236124) | (English model on the Chinese sample — pipeline check) | 1.90 s |
37
+ | parakeet / 0.6b-v2-int8 | [47617354218](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617354218) | (English model on the Chinese sample — pipeline check) | 1.36 s |
38
+ | giga-am / giga-v3 | [47617241954](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617241954) | (Russian model on the Chinese sample — pipeline check) | 1.09 s |
39
+ | firered-asr / ctc-int8 | [47617247666](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617247666) | 开放时间早上九点至下午五点 | 2.37 s |
40
+ | x-asr / x-asr-480ms (streaming) | [47617254289](https://github.com/ds-hu/dsh-better-voice-input/actions/runs/47617254289) | 开放时间早上九点至下午五点 | 1.17 s |
41
+
42
+ Sample: the 5.59 s Chinese test clip shipped upstream with the SenseVoice model; a fresh cache
43
+ download was verified file by file against the pinned SHA-256 digests on each run (including the
44
+ zip-archive sources for `mlt-int8` and `qwen3-1.7b-int8`). The sensevoice run that first exercised
45
+ the download path also caught a real provisioning bug — a missing `Content-Length` header was
46
+ treated as zero — which is fixed and covered by a unit test.
47
+
48
+ ## What is not verified end-to-end
49
+
50
+ - **Cloud vendors** are implemented against their public HTTP APIs but were not called with real
51
+ credentials (no vendor account is part of this repository). Wire formats and response parsing are
52
+ unit-tested against documented response shapes; a live call is the first thing to try when a
53
+ vendor changes its API.
54
+ - **The Web GUI integration** (slot rendering, the overlay's real-browser visuals, and the
55
+ settings page styling) is exercised through a `vm` React harness and the official slot contract,
56
+ not in a browser session, because this repository does not run browsers in CI.
57
+ - **Real audio capture** (microphone → WAV → service) is covered by unit tests of the gesture,
58
+ encoder and HTTP layers; it needs a user's browser and microphone to be observed.
@@ -0,0 +1,97 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1280" height="800" viewBox="0 0 1280 800">
2
+ <defs>
3
+ <linearGradient id="blue" x1="0" y1="0" x2="0" y2="1">
4
+ <stop offset="0%" stop-color="#0f1112"/><stop offset="8%" stop-color="#0c141d"/>
5
+ <stop offset="18%" stop-color="#0b223d"/><stop offset="29%" stop-color="#04376a"/>
6
+ <stop offset="38%" stop-color="#004992"/><stop offset="50%" stop-color="#005ec0"/>
7
+ <stop offset="60%" stop-color="#0066d3"/><stop offset="70%" stop-color="#0169dc"/>
8
+ <stop offset="100%" stop-color="#006bd8"/>
9
+ </linearGradient>
10
+ <radialGradient id="blueglow" cx="50%" cy="74%" r="52%">
11
+ <stop offset="0%" stop-color="#0074eb" stop-opacity=".55"/><stop offset="70%" stop-color="#0074eb" stop-opacity="0"/>
12
+ </radialGradient>
13
+ <linearGradient id="red" x1="0" y1="0" x2="0" y2="1">
14
+ <stop offset="0%" stop-color="#0f0f0f"/><stop offset="12%" stop-color="#0f0f0f"/>
15
+ <stop offset="20%" stop-color="#151011"/><stop offset="30%" stop-color="#1d1314"/>
16
+ <stop offset="45%" stop-color="#391b1a"/><stop offset="61%" stop-color="#602728"/>
17
+ <stop offset="70%" stop-color="#772d31"/><stop offset="80%" stop-color="#873235"/>
18
+ <stop offset="90%" stop-color="#903538"/><stop offset="100%" stop-color="#953535"/>
19
+ </linearGradient>
20
+ <radialGradient id="redglow" cx="50%" cy="76%" r="50%">
21
+ <stop offset="0%" stop-color="#be2d32" stop-opacity=".45"/><stop offset="72%" stop-color="#be2d32" stop-opacity="0"/>
22
+ </radialGradient>
23
+ <radialGradient id="vig" cx="50%" cy="50%" r="72%">
24
+ <stop offset="42%" stop-color="#000" stop-opacity="0"/><stop offset="100%" stop-color="#000" stop-opacity=".34"/>
25
+ </radialGradient>
26
+ </defs>
27
+ <rect width="1280" height="800" fill="#0b0d10"/>
28
+ <text x="640" y="44" fill="#e8ecf6" font-size="22" font-family="Source Serif Pro, Georgia, serif" text-anchor="middle">Better voice input · hold to talk, release to write</text>
29
+ <rect x="40" y="80" width="360" height="640" rx="26" fill="#16181c"/><text x="220.0" y="754" fill="#8b90a0" font-size="17" text-anchor="middle" font-family="Source Serif Pro, Georgia, serif">Message, or hold to talk</text>
30
+ <rect x="40" y="500" width="360" height="220" fill="#16181c"/>
31
+ <rect x="64" y="540" width="312" height="150" rx="20" fill="#23262b" stroke="#34383f"/>
32
+ <text x="84" y="588" fill="#a7a8ba" font-size="16" font-family="Source Serif Pro, Georgia, serif">Message, or hold to talk</text>
33
+ <rect x="84" y="628" width="108" height="30" rx="15" fill="#1d2430" stroke="#3b5f9e"/>
34
+ <text x="98" y="648" fill="#8b9fe4" font-size="12" font-family="Source Serif Pro, Georgia, serif">Deep thinking</text>
35
+ <rect x="200" y="628" width="108" height="30" rx="15" fill="#1d2430" stroke="#3b5f9e"/>
36
+ <text x="214" y="648" fill="#8b9fe4" font-size="12" font-family="Source Serif Pro, Georgia, serif">Smart search</text>
37
+ <circle cx="298" cy="644" r="14" fill="none" stroke="#d7d9de" stroke-width="1.6"/>
38
+ <path d="M298 639v10M293 644h10" stroke="#d7d9de" stroke-width="1.6" stroke-linecap="round"/>
39
+ <circle cx="342" cy="644" r="14" fill="none" stroke="#d7d9de" stroke-width="1.6"/>
40
+ <rect x="339" y="638" width="5" height="8" rx="2.5" fill="#d7d9de"/>
41
+ <path d="M336 646a5.5 5.5 0 0 0 11 0M342 651v3" stroke="#d7d9de" stroke-width="1.4" stroke-linecap="round" fill="none"/>
42
+ <rect x="460" y="80" width="360" height="640" rx="26" fill="#0f1112"/><text x="640.0" y="754" fill="#8b90a0" font-size="17" text-anchor="middle" font-family="Source Serif Pro, Georgia, serif">Recording · slide up to cancel</text>
43
+ <rect x="460" y="80" width="360" height="640" rx="26" fill="url(#blue)"/>
44
+ <rect x="460" y="80" width="360" height="640" rx="26" fill="url(#blueglow)"/>
45
+ <rect x="460" y="80" width="360" height="640" rx="26" fill="url(#vig)"/>
46
+ <text x="640" y="322" fill="#cfe6ff" font-size="25" text-anchor="middle" font-family="Source Serif Pro, Georgia, serif" letter-spacing="3">Release to insert · slide up to cancel</text>
47
+ <rect x="491.0" y="466.0" width="4" height="8.0" rx="2" fill="#dde8ff" opacity="0.55" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
48
+ <rect x="505.0" y="463.8" width="4" height="12.3" rx="2" fill="#dde8ff" opacity="0.69" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
49
+ <rect x="519.0" y="461.5" width="4" height="16.9" rx="2" fill="#dde8ff" opacity="0.77" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
50
+ <rect x="533.0" y="462.1" width="4" height="15.8" rx="2" fill="#dde8ff" opacity="0.82" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
51
+ <rect x="547.0" y="459.8" width="4" height="20.3" rx="2" fill="#dde8ff" opacity="0.87" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
52
+ <rect x="561.0" y="459.8" width="4" height="20.5" rx="2" fill="#dde8ff" opacity="0.91" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
53
+ <rect x="575.0" y="460.5" width="4" height="18.9" rx="2" fill="#dde8ff" opacity="0.94" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
54
+ <rect x="589.0" y="458.1" width="4" height="23.7" rx="2" fill="#dde8ff" opacity="0.96" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
55
+ <rect x="603.0" y="460.0" width="4" height="19.9" rx="2" fill="#dde8ff" opacity="0.98" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
56
+ <rect x="617.0" y="457.9" width="4" height="24.1" rx="2" fill="#dde8ff" opacity="0.99" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
57
+ <rect x="631.0" y="459.6" width="4" height="20.8" rx="2" fill="#dde8ff" opacity="1.00" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
58
+ <rect x="645.0" y="459.5" width="4" height="21.0" rx="2" fill="#dde8ff" opacity="1.00" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
59
+ <rect x="659.0" y="458.0" width="4" height="24.1" rx="2" fill="#dde8ff" opacity="0.99" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
60
+ <rect x="673.0" y="456.3" width="4" height="27.4" rx="2" fill="#dde8ff" opacity="0.98" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
61
+ <rect x="687.0" y="459.9" width="4" height="20.2" rx="2" fill="#dde8ff" opacity="0.96" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
62
+ <rect x="701.0" y="459.8" width="4" height="20.3" rx="2" fill="#dde8ff" opacity="0.94" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
63
+ <rect x="715.0" y="458.7" width="4" height="22.5" rx="2" fill="#dde8ff" opacity="0.91" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
64
+ <rect x="729.0" y="458.4" width="4" height="23.2" rx="2" fill="#dde8ff" opacity="0.87" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
65
+ <rect x="743.0" y="460.6" width="4" height="18.8" rx="2" fill="#dde8ff" opacity="0.82" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
66
+ <rect x="757.0" y="462.1" width="4" height="15.7" rx="2" fill="#dde8ff" opacity="0.77" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
67
+ <rect x="771.0" y="462.5" width="4" height="14.9" rx="2" fill="#dde8ff" opacity="0.69" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
68
+ <rect x="785.0" y="466.0" width="4" height="8.0" rx="2" fill="#dde8ff" opacity="0.55" style="filter:drop-shadow(0 0 6px #9fc8ff)"/>
69
+ <rect x="880" y="80" width="360" height="640" rx="26" fill="#0f0f0f"/><text x="1060.0" y="754" fill="#8b90a0" font-size="17" text-anchor="middle" font-family="Source Serif Pro, Georgia, serif">Cancel zone · release to cancel</text>
70
+ <rect x="880" y="80" width="360" height="640" rx="26" fill="url(#red)"/>
71
+ <rect x="880" y="80" width="360" height="640" rx="26" fill="url(#redglow)"/>
72
+ <rect x="880" y="80" width="360" height="640" rx="26" fill="url(#vig)"/>
73
+ <text x="1060" y="322" fill="#d4525e" font-size="25" text-anchor="middle" font-family="Source Serif Pro, Georgia, serif" letter-spacing="3">Release to cancel</text>
74
+ <rect x="911.0" y="466.0" width="4" height="8.0" rx="2" fill="#e06770" opacity="0.55" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
75
+ <rect x="925.0" y="463.8" width="4" height="12.3" rx="2" fill="#e06770" opacity="0.69" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
76
+ <rect x="939.0" y="461.5" width="4" height="16.9" rx="2" fill="#e06770" opacity="0.77" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
77
+ <rect x="953.0" y="462.1" width="4" height="15.8" rx="2" fill="#e06770" opacity="0.82" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
78
+ <rect x="967.0" y="459.8" width="4" height="20.3" rx="2" fill="#e06770" opacity="0.87" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
79
+ <rect x="981.0" y="459.8" width="4" height="20.5" rx="2" fill="#e06770" opacity="0.91" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
80
+ <rect x="995.0" y="460.5" width="4" height="18.9" rx="2" fill="#e06770" opacity="0.94" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
81
+ <rect x="1009.0" y="458.1" width="4" height="23.7" rx="2" fill="#e06770" opacity="0.96" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
82
+ <rect x="1023.0" y="460.0" width="4" height="19.9" rx="2" fill="#e06770" opacity="0.98" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
83
+ <rect x="1037.0" y="457.9" width="4" height="24.1" rx="2" fill="#e06770" opacity="0.99" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
84
+ <rect x="1051.0" y="459.6" width="4" height="20.8" rx="2" fill="#e06770" opacity="1.00" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
85
+ <rect x="1065.0" y="459.5" width="4" height="21.0" rx="2" fill="#e06770" opacity="1.00" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
86
+ <rect x="1079.0" y="458.0" width="4" height="24.1" rx="2" fill="#e06770" opacity="0.99" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
87
+ <rect x="1093.0" y="456.3" width="4" height="27.4" rx="2" fill="#e06770" opacity="0.98" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
88
+ <rect x="1107.0" y="459.9" width="4" height="20.2" rx="2" fill="#e06770" opacity="0.96" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
89
+ <rect x="1121.0" y="459.8" width="4" height="20.3" rx="2" fill="#e06770" opacity="0.94" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
90
+ <rect x="1135.0" y="458.7" width="4" height="22.5" rx="2" fill="#e06770" opacity="0.91" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
91
+ <rect x="1149.0" y="458.4" width="4" height="23.2" rx="2" fill="#e06770" opacity="0.87" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
92
+ <rect x="1163.0" y="460.6" width="4" height="18.8" rx="2" fill="#e06770" opacity="0.82" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
93
+ <rect x="1177.0" y="462.1" width="4" height="15.7" rx="2" fill="#e06770" opacity="0.77" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
94
+ <rect x="1191.0" y="462.5" width="4" height="14.9" rx="2" fill="#e06770" opacity="0.69" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
95
+ <rect x="1205.0" y="466.0" width="4" height="8.0" rx="2" fill="#e06770" opacity="0.55" style="filter:drop-shadow(0 0 6px #ff5f69)"/>
96
+ <text x="640" y="770" fill="#6f7688" font-size="14" font-family="-apple-system, Segoe UI, sans-serif" text-anchor="middle">Hold the composer to talk: the overlay mirrors the DeepSeek App. Insert-draft is the default release action; send is one setting away.</text>
97
+ </svg>