@howaboua/pi-durable-dictation 0.0.0-stage → 0.9.1

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 Igor Warzocha
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,4 @@
1
+ Dictation implementation extracted from Howcode by Igor Warzocha (MIT).
2
+ Source revision: 85db20ee1f156ad3543a8893d46c40e4a0bc5c65
3
+ Source paths: components/dictation/service, shared/desktop-dictation-contracts.ts, shared/dictation-{models,helpers,settings}.ts.
4
+ Native sherpa-onnx-node is an external Apache-2.0 dependency.
package/README.md CHANGED
@@ -1,3 +1,68 @@
1
- # Temporary Holding Version
1
+ # Pi Durable Dictation
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
+ Local Whisper dictation for Node.js 22.19 or later, using the native
4
+ `sherpa-onnx-node` runtime. The consuming app supplies model storage and selection.
5
+ This package does not capture microphone audio or register agent tools.
6
+
7
+ ```sh
8
+ npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.9.1/howaboua-pi-durable-dictation-0.9.1.tgz
9
+ ```
10
+
11
+ ```ts
12
+ import { createDictationService } from '@howaboua/pi-durable-dictation'
13
+
14
+ const dictation = createDictationService({
15
+ modelDirectory: '/absolute/path/to/models/whisper',
16
+ getSelectedModelId: () => 'tiny.en',
17
+ onDownloadLog: (event) => console.log(event.message),
18
+ })
19
+
20
+ const install = await dictation.service.installDictationModel({ modelId: 'tiny.en' })
21
+ if (!install.ok) throw new Error(install.error ?? 'Model installation failed')
22
+
23
+ // Supply base64-encoded little-endian PCM16 mono audio, not a WAV container.
24
+ const result = await dictation.service.transcribeDictation({
25
+ audioBase64,
26
+ sampleRate: 16_000,
27
+ language: 'en',
28
+ })
29
+
30
+ await dictation.dispose()
31
+ ```
32
+
33
+ The service also exposes `getDictationState()`, `listDictationModels()` and
34
+ `removeDictationModel({modelId})`. Model presets are `tiny.en`, `base.en` and
35
+ `small.en`. Installation and transcription return structured results with an
36
+ `ok` flag and an `error` field. Calls after disposal reject.
37
+
38
+ `isBusy()` reports admitted work. Disposal aborts downloads, rejects queued
39
+ native operations and waits for active work. Native recognizer handles are
40
+ garbage-collected because sherpa provides no supported close operation.
41
+
42
+ Import browser-safe types from `@howaboua/pi-durable-dictation/contracts`, model
43
+ definitions from `/models`, and language, PCM and duration helpers from
44
+ `/helpers`. Keep the main entry and native dependency on the server.
45
+
46
+ ## Configuration
47
+
48
+ Managed downloads use `modelDirectory`. Pass `modelSearchDirectories` for an
49
+ ordered list of additional discovery roots. If omitted, discovery uses
50
+ `PI_SHERPA_ONNX_MODEL_DIR` followed by `PI_DICTATION_MODEL_DIR`. An explicit
51
+ empty list disables those environment roots. The managed directory is appended
52
+ and duplicate roots are removed. Selected managed models retain their existing
53
+ priority over additional roots.
54
+
55
+ Pass `language`, `numThreads` or `provider` to override
56
+ `PI_SHERPA_ONNX_LANGUAGE`, `PI_SHERPA_ONNX_NUM_THREADS` or
57
+ `PI_SHERPA_ONNX_PROVIDER`. Explicit thread counts must be positive safe integers.
58
+ Without a thread setting, recognition uses available parallelism capped at four.
59
+ The default provider is `cpu`. Language falls back to the resolved model's
60
+ language, then the transcription request. Explicit blank language or provider
61
+ values skip their environment setting and use those defaults.
62
+
63
+ App-specific configuration names belong in the consuming adapter. Translate them
64
+ to these options rather than relying on app environment aliases in this package.
65
+
66
+ Supported native platforms are macOS arm64 and x64, Linux arm64 and x64, and
67
+ Windows ia32 and x64. Missing models, unsupported platforms and native loading
68
+ errors are reported by `getDictationState()`.
File without changes
@@ -0,0 +1,44 @@
1
+ // packages/dictation/src/helpers.ts
2
+ var englishWhisperModelPattern = /(^|[._-])en($|[._-])/;
3
+ var languageSubtagSeparatorPattern = /[-_]/;
4
+ function inferWhisperLanguage(modelId) {
5
+ return englishWhisperModelPattern.test(modelId) ? "en" : null;
6
+ }
7
+ function normalizeWhisperLanguage(language) {
8
+ if (!language) {
9
+ return null;
10
+ }
11
+ const normalized = language.trim().toLowerCase();
12
+ if (!normalized) {
13
+ return null;
14
+ }
15
+ const primarySubtag = normalized.split(languageSubtagSeparatorPattern)[0]?.trim();
16
+ return primarySubtag || null;
17
+ }
18
+ function decodePcm16MonoBytes(bytes) {
19
+ const sampleCount = Math.floor(bytes.byteLength / 2);
20
+ const samples = new Float32Array(sampleCount);
21
+ for (let index = 0;index < sampleCount; index += 1) {
22
+ const lowByte = bytes[index * 2] ?? 0;
23
+ const highByte = bytes[index * 2 + 1] ?? 0;
24
+ let sample = highByte << 8 | lowByte;
25
+ if (sample & 32768) {
26
+ sample -= 65536;
27
+ }
28
+ samples[index] = sample === -32768 ? -1 : sample / 32767;
29
+ }
30
+ return samples;
31
+ }
32
+ var DEFAULT_DICTATION_MAX_DURATION_SECONDS = 180;
33
+ var DICTATION_MAX_DURATION_OPTIONS = [60, 180, 300, 600];
34
+ function normalizeDictationMaxDurationSeconds(value) {
35
+ return DICTATION_MAX_DURATION_OPTIONS.find((option) => option === value) ?? null;
36
+ }
37
+ export {
38
+ DEFAULT_DICTATION_MAX_DURATION_SECONDS,
39
+ DICTATION_MAX_DURATION_OPTIONS,
40
+ decodePcm16MonoBytes,
41
+ inferWhisperLanguage,
42
+ normalizeDictationMaxDurationSeconds,
43
+ normalizeWhisperLanguage
44
+ };