@howaboua/pi-durable-dictation 0.0.0-stage → 0.10.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 +21 -0
- package/NOTICE +4 -0
- package/README.md +67 -2
- package/dist/activation.js +983 -0
- package/dist/contracts.js +0 -0
- package/dist/helpers.js +44 -0
- package/dist/index.js +939 -0
- package/dist/models.js +53 -0
- package/dist/packages/dictation/src/activation.d.ts +14 -0
- package/dist/packages/dictation/src/contracts.d.ts +79 -0
- package/dist/packages/dictation/src/helpers.d.ts +14 -0
- package/dist/packages/dictation/src/index.d.ts +8 -0
- package/dist/packages/dictation/src/model-download.d.ts +16 -0
- package/dist/packages/dictation/src/model-files.d.ts +2 -0
- package/dist/packages/dictation/src/model-management.d.ts +8 -0
- package/dist/packages/dictation/src/model-resolution.d.ts +13 -0
- package/dist/packages/dictation/src/models.d.ts +16 -0
- package/dist/packages/dictation/src/sherpa-onnx.d.ts +7 -0
- package/dist/packages/dictation/src/sherpa-runtime.d.ts +28 -0
- package/package.json +71 -5
|
File without changes
|
package/dist/helpers.js
ADDED
|
@@ -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
|
+
};
|