@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 +21 -0
- package/NOTICE +4 -0
- package/README.md +67 -2
- 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/contracts.d.ts +77 -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 +48 -5
package/dist/models.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// packages/dictation/src/models.ts
|
|
2
|
+
function formatDownloadSize(bytes) {
|
|
3
|
+
return `${(bytes / 1e6).toFixed(1)} MB`;
|
|
4
|
+
}
|
|
5
|
+
var dictationModelDefinitions = [
|
|
6
|
+
{
|
|
7
|
+
id: "tiny.en",
|
|
8
|
+
name: "Tiny English",
|
|
9
|
+
description: "Fastest and smallest Whisper model for quick dictation.",
|
|
10
|
+
huggingFaceRepo: "csukuangfj/sherpa-onnx-whisper-tiny.en",
|
|
11
|
+
downloadSizeBytes: 103627191,
|
|
12
|
+
files: {
|
|
13
|
+
encoder: "tiny.en-encoder.int8.onnx",
|
|
14
|
+
decoder: "tiny.en-decoder.int8.onnx",
|
|
15
|
+
tokens: "tiny.en-tokens.txt"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "base.en",
|
|
20
|
+
name: "Base English",
|
|
21
|
+
description: "Balanced default with better accuracy at moderate download size.",
|
|
22
|
+
huggingFaceRepo: "csukuangfj/sherpa-onnx-whisper-base.en",
|
|
23
|
+
downloadSizeBytes: 160626066,
|
|
24
|
+
files: {
|
|
25
|
+
encoder: "base.en-encoder.int8.onnx",
|
|
26
|
+
decoder: "base.en-decoder.int8.onnx",
|
|
27
|
+
tokens: "base.en-tokens.txt"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "small.en",
|
|
32
|
+
name: "Small English",
|
|
33
|
+
description: "Highest accuracy of the initial presets, with the biggest download.",
|
|
34
|
+
huggingFaceRepo: "csukuangfj/sherpa-onnx-whisper-small.en",
|
|
35
|
+
downloadSizeBytes: 375501079,
|
|
36
|
+
files: {
|
|
37
|
+
encoder: "small.en-encoder.int8.onnx",
|
|
38
|
+
decoder: "small.en-decoder.int8.onnx",
|
|
39
|
+
tokens: "small.en-tokens.txt"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
function getDictationModelDefinition(modelId) {
|
|
44
|
+
return dictationModelDefinitions.find((model) => model.id === modelId) ?? null;
|
|
45
|
+
}
|
|
46
|
+
function getDictationModelDownloadSizeLabel(bytes) {
|
|
47
|
+
return formatDownloadSize(bytes);
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
dictationModelDefinitions,
|
|
51
|
+
getDictationModelDefinition,
|
|
52
|
+
getDictationModelDownloadSizeLabel
|
|
53
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export type DictationState = {
|
|
2
|
+
available: boolean;
|
|
3
|
+
reason: "missing-model" | "runtime-error" | "unsupported-platform" | null;
|
|
4
|
+
runtime: "sherpa-onnx-node" | null;
|
|
5
|
+
modelDirectory: string | null;
|
|
6
|
+
modelId: string | null;
|
|
7
|
+
language: string | null;
|
|
8
|
+
error: string | null;
|
|
9
|
+
};
|
|
10
|
+
export type DictationModelId = "tiny.en" | "base.en" | "small.en";
|
|
11
|
+
export type DictationModelSummary = {
|
|
12
|
+
id: DictationModelId;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
downloadSizeBytes: number;
|
|
16
|
+
downloadSizeLabel: string;
|
|
17
|
+
installed: boolean;
|
|
18
|
+
managed: boolean;
|
|
19
|
+
selected: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type DictationModelInstallResult = {
|
|
22
|
+
ok: boolean;
|
|
23
|
+
modelId: DictationModelId;
|
|
24
|
+
error: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type DictationModelRemoveResult = {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
modelId: DictationModelId;
|
|
29
|
+
error: string | null;
|
|
30
|
+
};
|
|
31
|
+
export type DictationTranscriptionRequest = {
|
|
32
|
+
audioBase64: string;
|
|
33
|
+
sampleRate: number;
|
|
34
|
+
language?: string | null | undefined;
|
|
35
|
+
};
|
|
36
|
+
export type DictationTranscriptionResult = {
|
|
37
|
+
ok: boolean;
|
|
38
|
+
text: string;
|
|
39
|
+
runtime: "sherpa-onnx-node" | null;
|
|
40
|
+
modelDirectory: string | null;
|
|
41
|
+
modelId: string | null;
|
|
42
|
+
language: string | null;
|
|
43
|
+
error: string | null;
|
|
44
|
+
};
|
|
45
|
+
export type DictationDownloadEvent = {
|
|
46
|
+
type: "dictation-download-log";
|
|
47
|
+
modelId: DictationModelId;
|
|
48
|
+
message: string;
|
|
49
|
+
at: string;
|
|
50
|
+
done: boolean;
|
|
51
|
+
isError: boolean;
|
|
52
|
+
};
|
|
53
|
+
export type DictationService = {
|
|
54
|
+
getDictationState(): Promise<DictationState>;
|
|
55
|
+
listDictationModels(): Promise<DictationModelSummary[]>;
|
|
56
|
+
installDictationModel(request: {
|
|
57
|
+
modelId: DictationModelId;
|
|
58
|
+
}): Promise<DictationModelInstallResult>;
|
|
59
|
+
removeDictationModel(request: {
|
|
60
|
+
modelId: DictationModelId;
|
|
61
|
+
}): Promise<DictationModelRemoveResult>;
|
|
62
|
+
transcribeDictation(request: DictationTranscriptionRequest): Promise<DictationTranscriptionResult>;
|
|
63
|
+
};
|
|
64
|
+
export type DictationServiceOptions = {
|
|
65
|
+
/** Native filesystem directory owned by this service for managed Whisper models. */
|
|
66
|
+
modelDirectory: string;
|
|
67
|
+
/** Ordered discovery roots, replacing PI_* model directories when supplied. The managed root is appended. */
|
|
68
|
+
modelSearchDirectories?: readonly string[];
|
|
69
|
+
/** Overrides PI_SHERPA_ONNX_LANGUAGE. Blank uses the model or request language. */
|
|
70
|
+
language?: string;
|
|
71
|
+
/** Positive integer overriding PI_SHERPA_ONNX_NUM_THREADS. */
|
|
72
|
+
numThreads?: number;
|
|
73
|
+
/** Overrides PI_SHERPA_ONNX_PROVIDER. Blank uses cpu. */
|
|
74
|
+
provider?: string;
|
|
75
|
+
getSelectedModelId: () => DictationModelId | null;
|
|
76
|
+
onDownloadLog?: (event: DictationDownloadEvent) => void;
|
|
77
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ResolvedWhisperModelFiles = {
|
|
2
|
+
modelDirectory: string;
|
|
3
|
+
encoderPath: string;
|
|
4
|
+
decoderPath: string;
|
|
5
|
+
tokensPath: string;
|
|
6
|
+
modelId: string;
|
|
7
|
+
language: string | null;
|
|
8
|
+
};
|
|
9
|
+
export declare function inferWhisperLanguage(modelId: string): "en" | null;
|
|
10
|
+
export declare function normalizeWhisperLanguage(language: string | null | undefined): string | null;
|
|
11
|
+
export declare function decodePcm16MonoBytes(bytes: Uint8Array): Float32Array<ArrayBuffer>;
|
|
12
|
+
export declare const DEFAULT_DICTATION_MAX_DURATION_SECONDS = 180;
|
|
13
|
+
export declare const DICTATION_MAX_DURATION_OPTIONS: readonly [60, 180, 300, 600];
|
|
14
|
+
export declare function normalizeDictationMaxDurationSeconds(value: number | null | undefined): 60 | 180 | 300 | 600 | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DictationService, DictationServiceOptions } from "./contracts.ts";
|
|
2
|
+
export type * from "./contracts.ts";
|
|
3
|
+
/** Owns native recognizers, model operations and their shutdown within one instance. */
|
|
4
|
+
export declare function createDictationService(options: DictationServiceOptions): {
|
|
5
|
+
service: DictationService;
|
|
6
|
+
isBusy: () => boolean;
|
|
7
|
+
dispose(): Promise<void>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
export type DownloadMetadata = {
|
|
3
|
+
contentLength: number | null;
|
|
4
|
+
etag: string | null;
|
|
5
|
+
etagSource: "etag" | "x-linked-etag" | null;
|
|
6
|
+
};
|
|
7
|
+
export type DownloadChecksumExpectation = {
|
|
8
|
+
algorithm: "sha1" | "sha256";
|
|
9
|
+
expected: string;
|
|
10
|
+
prefix: Buffer | null;
|
|
11
|
+
};
|
|
12
|
+
export declare function getDownloadChecksumExpectations(etag: string | null, contentLength: number): DownloadChecksumExpectation[];
|
|
13
|
+
export declare function fetchDownloadResponse(url: string, signal?: AbortSignal): Promise<{
|
|
14
|
+
response: Response;
|
|
15
|
+
metadata: DownloadMetadata;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DictationModelId, DictationModelInstallResult, DictationModelRemoveResult, DictationModelSummary, DictationServiceOptions } from "./contracts.ts";
|
|
2
|
+
import type { createModelResolution } from "./model-resolution.ts";
|
|
3
|
+
import type { createSherpaRuntime } from "./sherpa-runtime.ts";
|
|
4
|
+
export declare function createModelManagement(config: DictationServiceOptions, resolution: ReturnType<typeof createModelResolution>, runtime: ReturnType<typeof createSherpaRuntime>): {
|
|
5
|
+
listManagedAndConfiguredDictationModels: () => Promise<DictationModelSummary[]>;
|
|
6
|
+
installManagedDictationModel: (modelId: DictationModelId, signal?: AbortSignal) => Promise<DictationModelInstallResult>;
|
|
7
|
+
removeManagedDictationModel: (modelId: DictationModelId) => Promise<DictationModelRemoveResult>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DictationModelId, DictationServiceOptions } from "./contracts.ts";
|
|
2
|
+
import { type ResolvedWhisperModelFiles } from "./helpers.ts";
|
|
3
|
+
export type DictationModelFiles = ResolvedWhisperModelFiles;
|
|
4
|
+
export declare function createModelResolution(options: DictationServiceOptions): {
|
|
5
|
+
DEFAULT_DICTATION_MODEL_DIRECTORY: string;
|
|
6
|
+
getDictationModelDirectories: () => string[];
|
|
7
|
+
getDictationModelsRootDirectory: () => string;
|
|
8
|
+
getDictationModelDirectory: (modelId: DictationModelId) => string;
|
|
9
|
+
getManagedDictationModelFiles: (modelId: DictationModelId) => DictationModelFiles | null;
|
|
10
|
+
findConfiguredDictationModelFiles: (modelId?: DictationModelId) => ResolvedWhisperModelFiles | null;
|
|
11
|
+
getResolvedDictationModelFiles: () => ResolvedWhisperModelFiles | null;
|
|
12
|
+
getInstalledManagedDictationModelDirectory: (modelId: DictationModelId) => string | null;
|
|
13
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DictationModelId } from "./contracts.ts";
|
|
2
|
+
export type DictationModelDefinition = {
|
|
3
|
+
id: DictationModelId;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
huggingFaceRepo: string;
|
|
7
|
+
downloadSizeBytes: number;
|
|
8
|
+
files: {
|
|
9
|
+
encoder: string;
|
|
10
|
+
decoder: string;
|
|
11
|
+
tokens: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const dictationModelDefinitions: DictationModelDefinition[];
|
|
15
|
+
export declare function getDictationModelDefinition(modelId: DictationModelId): DictationModelDefinition | null;
|
|
16
|
+
export declare function getDictationModelDownloadSizeLabel(bytes: number): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DictationServiceOptions, DictationState, DictationTranscriptionRequest, DictationTranscriptionResult } from "./contracts.ts";
|
|
2
|
+
import type { createModelResolution } from "./model-resolution.ts";
|
|
3
|
+
import type { createSherpaRuntime } from "./sherpa-runtime.ts";
|
|
4
|
+
export declare function createTranscriptionService(resolution: ReturnType<typeof createModelResolution>, runtime: ReturnType<typeof createSherpaRuntime>, options: Pick<DictationServiceOptions, "language">): {
|
|
5
|
+
getDictationState: () => Promise<DictationState>;
|
|
6
|
+
transcribeDictation: (request: DictationTranscriptionRequest) => Promise<DictationTranscriptionResult>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DictationServiceOptions } from "./contracts.ts";
|
|
2
|
+
import type { DictationModelFiles } from "./model-resolution.ts";
|
|
3
|
+
type SherpaOfflineStream = {
|
|
4
|
+
acceptWaveform: (input: {
|
|
5
|
+
samples: Float32Array;
|
|
6
|
+
sampleRate: number;
|
|
7
|
+
}) => void;
|
|
8
|
+
};
|
|
9
|
+
type SherpaOfflineRecognizerResult = {
|
|
10
|
+
lang?: string | undefined;
|
|
11
|
+
text?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
type SherpaOfflineRecognizer = {
|
|
14
|
+
createStream: () => SherpaOfflineStream;
|
|
15
|
+
decodeAsync: (stream: SherpaOfflineStream) => Promise<SherpaOfflineRecognizerResult>;
|
|
16
|
+
};
|
|
17
|
+
type SherpaOnnxModule = {
|
|
18
|
+
OfflineRecognizer: {
|
|
19
|
+
createAsync: (config: Record<string, unknown>) => Promise<SherpaOfflineRecognizer>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare function createSherpaRuntime(options: Pick<DictationServiceOptions, "numThreads" | "provider">): {
|
|
23
|
+
getRecognizer: (modelFiles: DictationModelFiles, language: string | null) => Promise<SherpaOfflineRecognizer>;
|
|
24
|
+
getSherpaPlatformPackageName: () => "sherpa-onnx-darwin-arm64" | "sherpa-onnx-darwin-x64" | "sherpa-onnx-linux-arm64" | "sherpa-onnx-linux-x64" | "sherpa-onnx-win-ia32" | "sherpa-onnx-win-x64" | null;
|
|
25
|
+
loadSherpaOnnxModule: () => Promise<SherpaOnnxModule>;
|
|
26
|
+
resetRecognizerCache: () => void;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@howaboua/pi-durable-dictation",
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "Portable local Whisper dictation with the sherpa-onnx native runtime",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IgorWarzocha/pi-durable-components.git",
|
|
10
|
+
"directory": "packages/dictation"
|
|
11
|
+
},
|
|
12
|
+
"author": "Igor Warzocha",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.19.0"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/packages/dictation/src/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/packages/dictation/src/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./contracts": {
|
|
24
|
+
"types": "./dist/packages/dictation/src/contracts.d.ts",
|
|
25
|
+
"import": "./dist/contracts.js"
|
|
26
|
+
},
|
|
27
|
+
"./models": {
|
|
28
|
+
"types": "./dist/packages/dictation/src/models.d.ts",
|
|
29
|
+
"import": "./dist/models.js"
|
|
30
|
+
},
|
|
31
|
+
"./helpers": {
|
|
32
|
+
"types": "./dist/packages/dictation/src/helpers.d.ts",
|
|
33
|
+
"import": "./dist/helpers.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"NOTICE"
|
|
41
|
+
],
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"sherpa-onnx-node": "1.13.8"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|