@moxxy/plugin-stt-local 0.47.1 → 0.48.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/MODEL_NOTICE.md +12 -0
- package/dist/audio.d.ts +7 -0
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +45 -0
- package/dist/audio.js.map +1 -1
- package/dist/host-protocol.d.ts +5 -3
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +20 -9
- package/dist/host-protocol.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/local-stt.d.ts +23 -12
- package/dist/local-stt.d.ts.map +1 -1
- package/dist/local-stt.js +76 -29
- package/dist/local-stt.js.map +1 -1
- package/dist/models.d.ts +34 -20
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +53 -12
- package/dist/models.js.map +1 -1
- package/package.json +7 -5
- package/src/audio.test.ts +35 -0
- package/src/audio.ts +46 -0
- package/src/host-protocol.test.ts +21 -0
- package/src/host-protocol.ts +26 -12
- package/src/index.ts +23 -13
- package/src/live.test.ts +12 -1
- package/src/local-stt.test.ts +128 -9
- package/src/local-stt.ts +90 -39
- package/src/models.test.ts +41 -4
- package/src/models.ts +73 -22
package/MODEL_NOTICE.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Dictation model notices
|
|
2
|
+
|
|
3
|
+
This package downloads a model only when someone chooses it.
|
|
4
|
+
|
|
5
|
+
**Parakeet TDT 0.6B v3**, by NVIDIA, is licensed under Creative Commons
|
|
6
|
+
Attribution 4.0 (https://creativecommons.org/licenses/by/4.0/). Source:
|
|
7
|
+
https://huggingface.co/nvidia/parakeet-tdt-0.6b-v3. Moxxy uses the int8 ONNX
|
|
8
|
+
export by the sherpa-onnx project, which converted and quantized the model.
|
|
9
|
+
|
|
10
|
+
**Whisper large-v3 turbo**, by OpenAI, is released under the MIT License. Source:
|
|
11
|
+
https://github.com/openai/whisper. Moxxy uses the int8 ONNX export by the
|
|
12
|
+
sherpa-onnx project.
|
package/dist/audio.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - `pcm16ToFloat32` int16 little-endian bytes → Float32 in [-1, 1]
|
|
8
8
|
* - `downmixToMono` interleaved N-channel Float32 → averaged mono
|
|
9
9
|
* - `resampleLinear` linear-interpolation resample between two rates
|
|
10
|
+
* - `splitAtSilence` long audio → pieces cut where the speaker paused
|
|
10
11
|
* - `parseWav` RIFF/WAVE header parse → PCM16 samples (float) + rate +
|
|
11
12
|
* channels; rejects non-PCM16 (float/compressed) WAV
|
|
12
13
|
*
|
|
@@ -52,4 +53,10 @@ export interface ParsedWav {
|
|
|
52
53
|
* 44-byte header, so files with extra chunks (`LIST`, `fact`, …) still parse.
|
|
53
54
|
*/
|
|
54
55
|
export declare function parseWav(bytes: Uint8Array): ParsedWav;
|
|
56
|
+
/**
|
|
57
|
+
* Cut audio into pieces of at most `maxSeconds`, at the quietest moment of the
|
|
58
|
+
* last seconds before each limit, so no word is split where the speaker paused.
|
|
59
|
+
* Pieces are copies: over IPC a view would drag the whole recording with it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function splitAtSilence(samples: Float32Array, sampleRate: number, maxSeconds: number): Float32Array[];
|
|
55
62
|
//# sourceMappingURL=audio.d.ts.map
|
package/dist/audio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../src/audio.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../src/audio.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,QAAS,CAAC;AAMzC;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAa1E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAiBvF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,YAAY,CA0Bd;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAYrD;AAED,MAAM,WAAW,SAAS;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAOD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAoErD;AAiCD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,YAAY,EAAE,CAe5G"}
|
package/dist/audio.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - `pcm16ToFloat32` int16 little-endian bytes → Float32 in [-1, 1]
|
|
8
8
|
* - `downmixToMono` interleaved N-channel Float32 → averaged mono
|
|
9
9
|
* - `resampleLinear` linear-interpolation resample between two rates
|
|
10
|
+
* - `splitAtSilence` long audio → pieces cut where the speaker paused
|
|
10
11
|
* - `parseWav` RIFF/WAVE header parse → PCM16 samples (float) + rate +
|
|
11
12
|
* channels; rejects non-PCM16 (float/compressed) WAV
|
|
12
13
|
*
|
|
@@ -194,4 +195,48 @@ function ascii4(bytes, off) {
|
|
|
194
195
|
function wavError(detail) {
|
|
195
196
|
return new MoxxyError({ code: 'CONFIG_INVALID', message: `Invalid WAV audio: ${detail}` });
|
|
196
197
|
}
|
|
198
|
+
/** Pauses are looked for this far before the limit, in frames this long. */
|
|
199
|
+
const CUT_SEARCH_SECONDS = 10;
|
|
200
|
+
const CUT_FRAME_SECONDS = 0.1;
|
|
201
|
+
/** The quietest moment between `from` and `to`; `to` itself when nothing is quieter. */
|
|
202
|
+
function quietestCut(samples, from, to, frame) {
|
|
203
|
+
const energy = (end) => {
|
|
204
|
+
let sum = 0;
|
|
205
|
+
for (let i = end - frame; i < end; i += 1)
|
|
206
|
+
sum += (samples[i] ?? 0) ** 2;
|
|
207
|
+
return sum;
|
|
208
|
+
};
|
|
209
|
+
let cut = to;
|
|
210
|
+
let quietest = energy(to);
|
|
211
|
+
for (let end = to - frame; end - frame >= from; end -= frame) {
|
|
212
|
+
const current = energy(end);
|
|
213
|
+
if (current < quietest) {
|
|
214
|
+
quietest = current;
|
|
215
|
+
cut = end - Math.floor(frame / 2);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return cut;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Cut audio into pieces of at most `maxSeconds`, at the quietest moment of the
|
|
222
|
+
* last seconds before each limit, so no word is split where the speaker paused.
|
|
223
|
+
* Pieces are copies: over IPC a view would drag the whole recording with it.
|
|
224
|
+
*/
|
|
225
|
+
export function splitAtSilence(samples, sampleRate, maxSeconds) {
|
|
226
|
+
const limit = Math.floor(maxSeconds * sampleRate);
|
|
227
|
+
if (samples.length <= limit)
|
|
228
|
+
return [samples];
|
|
229
|
+
const search = Math.min(limit, Math.floor(CUT_SEARCH_SECONDS * sampleRate));
|
|
230
|
+
const frame = Math.max(1, Math.floor(CUT_FRAME_SECONDS * sampleRate));
|
|
231
|
+
const parts = [];
|
|
232
|
+
let start = 0;
|
|
233
|
+
while (samples.length - start > limit) {
|
|
234
|
+
const to = start + limit;
|
|
235
|
+
const end = quietestCut(samples, to - search, to, frame);
|
|
236
|
+
parts.push(samples.slice(start, end));
|
|
237
|
+
start = end;
|
|
238
|
+
}
|
|
239
|
+
parts.push(samples.slice(start));
|
|
240
|
+
return parts;
|
|
241
|
+
}
|
|
197
242
|
//# sourceMappingURL=audio.js.map
|
package/dist/audio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio.js","sourceRoot":"","sources":["../src/audio.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"audio.js","sourceRoot":"","sources":["../src/audio.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,kEAAkE;AAClE,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC;gEACgE;AAChE,MAAM,WAAW,GAAG,MAAM,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAA6B;IAC1D,MAAM,KAAK,GAAG,GAAG,YAAY,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,2BAA2B;IACjE,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;IACzB,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;IACpC,2EAA2E;IAC3E,yEAAyE;IACzE,2BAA2B;IAC3B,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAClE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC;IACpD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAA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H,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAqB,EAAE,UAAkB,EAAE,UAAkB;IAC1F,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC;IAClD,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK;QAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,UAAU,CAAC,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,UAAU,CAAC,CAAC,CAAC;IACtE,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,OAAO,CAAC,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,CAAC;QACtC,MAAM,EAAE,GAAG,KAAK,GAAG,KAAK,CAAC;QACzB,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QACzD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QACtC,KAAK,GAAG,GAAG,CAAC;IACd,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/host-protocol.d.ts
CHANGED
|
@@ -19,11 +19,13 @@ export interface TranscribeRequest {
|
|
|
19
19
|
readonly type: 'transcribe';
|
|
20
20
|
/** Cache key for the loaded recognizer (the absolute encoder path). */
|
|
21
21
|
readonly modelKey: string;
|
|
22
|
-
/** Absolute path to the
|
|
22
|
+
/** Absolute path to the encoder `.onnx`. */
|
|
23
23
|
readonly encoder: string;
|
|
24
|
-
/** Absolute path to the
|
|
24
|
+
/** Absolute path to the decoder `.onnx`. */
|
|
25
25
|
readonly decoder: string;
|
|
26
|
-
/** Absolute path to
|
|
26
|
+
/** Absolute path to the joiner `.onnx`: set for a transducer, absent for Whisper. */
|
|
27
|
+
readonly joiner?: string;
|
|
28
|
+
/** Absolute path to the tokens file. */
|
|
27
29
|
readonly tokens: string;
|
|
28
30
|
/** Inference thread count. */
|
|
29
31
|
readonly numThreads: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-protocol.d.ts","sourceRoot":"","sources":["../src/host-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;wCAGwC;AACxC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,
|
|
1
|
+
{"version":3,"file":"host-protocol.d.ts","sourceRoot":"","sources":["../src/host-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;wCAGwC;AACxC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qFAAqF;IACrF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CA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C,IAAI,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,YAAY,IAAI,mBAAmB,CAAC;IACpC,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC1C,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,6BAA6B,CAAC;CACvE;AAED,MAAM,WAAW,YAAY;IAC3B,iBAAiB,EAAE,KAAK,MAAM,EAAE,OAAO,KAAK,uBAAuB,CAAC;CACrE;AAED;2CAC2C;AAC3C,MAAM,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,kBAAkB,CAwC/E"}
|
package/dist/host-protocol.js
CHANGED
|
@@ -27,15 +27,7 @@ export function createMessageHandler(loadSherpa) {
|
|
|
27
27
|
recognizer = new mod.OfflineRecognizer({
|
|
28
28
|
featConfig: { sampleRate: 16_000, featureDim: 80 },
|
|
29
29
|
modelConfig: {
|
|
30
|
-
|
|
31
|
-
encoder: req.encoder,
|
|
32
|
-
decoder: req.decoder,
|
|
33
|
-
// `language`/`task` are present in the OfflineWhisperModelConfig
|
|
34
|
-
// types but exercised by no upstream example — pass them through
|
|
35
|
-
// best-effort (empty language ⇒ Whisper auto-detects anyway).
|
|
36
|
-
language: req.language,
|
|
37
|
-
task: req.task,
|
|
38
|
-
},
|
|
30
|
+
...engineConfig(req),
|
|
39
31
|
tokens: req.tokens,
|
|
40
32
|
numThreads: req.numThreads,
|
|
41
33
|
provider: req.provider,
|
|
@@ -64,6 +56,25 @@ export function createMessageHandler(loadSherpa) {
|
|
|
64
56
|
}
|
|
65
57
|
};
|
|
66
58
|
}
|
|
59
|
+
function engineConfig(req) {
|
|
60
|
+
if (req.joiner) {
|
|
61
|
+
return {
|
|
62
|
+
transducer: { encoder: req.encoder, decoder: req.decoder, joiner: req.joiner },
|
|
63
|
+
modelType: 'nemo_transducer',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
whisper: {
|
|
68
|
+
encoder: req.encoder,
|
|
69
|
+
decoder: req.decoder,
|
|
70
|
+
// `language`/`task` are present in the OfflineWhisperModelConfig
|
|
71
|
+
// types but exercised by no upstream example — pass them through
|
|
72
|
+
// best-effort (empty language ⇒ Whisper auto-detects anyway).
|
|
73
|
+
language: req.language,
|
|
74
|
+
task: req.task,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
67
78
|
function errMsg(err) {
|
|
68
79
|
return err instanceof Error ? err.message : String(err);
|
|
69
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-protocol.js","sourceRoot":"","sources":["../src/host-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"host-protocol.js","sourceRoot":"","sources":["../src/host-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoFH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAsB;IACzD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmC,CAAC;IACzD,IAAI,GAAG,GAAwB,IAAI,CAAC;IAEpC,OAAO,KAAK,UAAU,MAAM,CAAC,GAAgB;QAC3C,IAAI,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,IAAI,CAAC;gBACH,GAAG,KAAK,UAAU,EAAE,CAAC;gBACrB,UAAU,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC;oBACrC,UAAU,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,E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AAE,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;QACrF,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAgB;IACpC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QACf,OAAO;YACL,UAAU,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE;YAC9E,SAAS,EAAE,iBAAiB;SAC7B,CAAC;IACJ,CAAC;IACD,OAAO;QACL,OAAO,EAAE;YACP,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,iEAAiE;YACjE,iEAAiE;YACjE,8DAA8D;YAC9D,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,IAAI,EAAE,GAAG,CAAC,IAAI;SACf;KACF,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,GAAY;IAC1B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Plugin } from '@moxxy/sdk';
|
|
2
|
-
import { type
|
|
3
|
-
export {
|
|
4
|
-
export { MODEL_CATALOG, DEFAULT_MODEL_ID, modelIds, findModel, requireModel, modelFiles, modelBytes, modelDir, defaultModelsDir, type
|
|
2
|
+
import { type LocalSttOptions } from './local-stt.js';
|
|
3
|
+
export { LocalSttTranscriber, createLocalParakeetTranscriber, createLocalWhisperTranscriber, shutdownLocalStt, LOCAL_PARAKEET_TRANSCRIBER_NAME, LOCAL_WHISPER_TRANSCRIBER_NAME, type LocalSttOptions, type LocalSttModelPaths, } from './local-stt.js';
|
|
4
|
+
export { MODEL_CATALOG, DEFAULT_MODEL_ID, modelIds, findModel, requireModel, modelFiles, modelBytes, modelDir, defaultModelsDir, type LocalSttModelEntry, type LocalSttModelId, } from './models.js';
|
|
5
5
|
export { pcm16ToFloat32, downmixToMono, resampleLinear, parseWav, isRiffWave, TARGET_SAMPLE_RATE, type ParsedWav, } from './audio.js';
|
|
6
6
|
export { decodeToMono16k, type DecodeOptions } from './decode.js';
|
|
7
7
|
export { decodeViaFfmpeg, missingFfmpegError, __resetFfmpegProbeForTest, } from './ffmpeg.js';
|
|
@@ -10,13 +10,13 @@ export { sherpaPlatformPackage, resolveSherpaLibDir, sherpaEnv, libraryPathVar,
|
|
|
10
10
|
export interface BuildLocalSttPluginOptions {
|
|
11
11
|
/** Build-time defaults / test seams for the transcriber (injected
|
|
12
12
|
* `ensureModelFilesImpl`, `hostFactory`, `fetchImpl`, `modelsDir`, `log`, …). */
|
|
13
|
-
readonly defaults?:
|
|
13
|
+
readonly defaults?: LocalSttOptions;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Build the @moxxy/plugin-stt-local plugin. Registers
|
|
17
|
-
* `local-whisper`, backed by sherpa-onnx
|
|
18
|
-
* sidecar. Side-effect free at load: no model is downloaded and no
|
|
19
|
-
* spawned until the first `transcribe`. Per-activation config
|
|
16
|
+
* Build the @moxxy/plugin-stt-local plugin. Registers two transcribers,
|
|
17
|
+
* `local-whisper` and `local-parakeet`, backed by sherpa-onnx models running in
|
|
18
|
+
* a forked sidecar. Side-effect free at load: no model is downloaded and no
|
|
19
|
+
* process is spawned until the first `transcribe`. Per-activation config
|
|
20
20
|
* (`session.transcribers.setActive('local-whisper', { model, language,
|
|
21
21
|
* numThreads })`) overrides the build-time defaults.
|
|
22
22
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAML,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,6BAA6B,EAC7B,gBAAgB,EAChB,+BAA+B,EAC/B,8BAA8B,EAC9B,KAAK,eAAe,EACpB,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,UAAU,EACV,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EACd,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,KAAK,SAAS,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,SAAS,EACT,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,0BAA0B;IACzC;sFACkF;IAClF,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;CACrC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,GAAE,0BAA+B,GAAG,MAAM,CAsBjF;;AAsBD,wBAAqC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { definePlugin, defineTranscriber } from '@moxxy/sdk';
|
|
2
|
-
import { createLocalWhisperTranscriber, LOCAL_WHISPER_TRANSCRIBER_NAME, shutdownLocalStt, } from './local-stt.js';
|
|
3
|
-
export {
|
|
2
|
+
import { createLocalParakeetTranscriber, createLocalWhisperTranscriber, LOCAL_PARAKEET_TRANSCRIBER_NAME, LOCAL_WHISPER_TRANSCRIBER_NAME, shutdownLocalStt, } from './local-stt.js';
|
|
3
|
+
export { LocalSttTranscriber, createLocalParakeetTranscriber, createLocalWhisperTranscriber, shutdownLocalStt, LOCAL_PARAKEET_TRANSCRIBER_NAME, LOCAL_WHISPER_TRANSCRIBER_NAME, } from './local-stt.js';
|
|
4
4
|
export { MODEL_CATALOG, DEFAULT_MODEL_ID, modelIds, findModel, requireModel, modelFiles, modelBytes, modelDir, defaultModelsDir, } from './models.js';
|
|
5
5
|
export { pcm16ToFloat32, downmixToMono, resampleLinear, parseWav, isRiffWave, TARGET_SAMPLE_RATE, } from './audio.js';
|
|
6
6
|
export { decodeToMono16k } from './decode.js';
|
|
@@ -8,10 +8,10 @@ export { decodeViaFfmpeg, missingFfmpegError, __resetFfmpegProbeForTest, } from
|
|
|
8
8
|
export { HostClient } from './host-client.js';
|
|
9
9
|
export { sherpaPlatformPackage, resolveSherpaLibDir, sherpaEnv, libraryPathVar, } from './platform.js';
|
|
10
10
|
/**
|
|
11
|
-
* Build the @moxxy/plugin-stt-local plugin. Registers
|
|
12
|
-
* `local-whisper`, backed by sherpa-onnx
|
|
13
|
-
* sidecar. Side-effect free at load: no model is downloaded and no
|
|
14
|
-
* spawned until the first `transcribe`. Per-activation config
|
|
11
|
+
* Build the @moxxy/plugin-stt-local plugin. Registers two transcribers,
|
|
12
|
+
* `local-whisper` and `local-parakeet`, backed by sherpa-onnx models running in
|
|
13
|
+
* a forked sidecar. Side-effect free at load: no model is downloaded and no
|
|
14
|
+
* process is spawned until the first `transcribe`. Per-activation config
|
|
15
15
|
* (`session.transcribers.setActive('local-whisper', { model, language,
|
|
16
16
|
* numThreads })`) overrides the build-time defaults.
|
|
17
17
|
*
|
|
@@ -32,6 +32,11 @@ export function buildLocalSttPlugin(opts = {}) {
|
|
|
32
32
|
displayName: 'Local Whisper (offline, multilingual)',
|
|
33
33
|
createClient: (config) => createLocalWhisperTranscriber({ ...defaults, ...configToOptions(config) }),
|
|
34
34
|
}),
|
|
35
|
+
defineTranscriber({
|
|
36
|
+
name: LOCAL_PARAKEET_TRANSCRIBER_NAME,
|
|
37
|
+
displayName: 'Local Parakeet (offline, 25 languages)',
|
|
38
|
+
createClient: (config) => createLocalParakeetTranscriber({ ...defaults, ...configToOptions(config) }),
|
|
39
|
+
}),
|
|
35
40
|
],
|
|
36
41
|
// Kill every spawned sidecar when the session/runner shuts down.
|
|
37
42
|
hooks: { onShutdown: () => shutdownLocalStt() },
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAe,MAAM,YAAY,CAAC;AAE1E,OAAO,EACL,6BAA6B,EAC7B,8BAA8B,EAC9B,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAe,MAAM,YAAY,CAAC;AA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differ only in the catalog entry they read.
|
|
3
4
|
*
|
|
4
5
|
* On the first transcription for a model it downloads + verifies that model's
|
|
5
|
-
*
|
|
6
|
+
* files (once, via @moxxy/model-fetch), then decodes the inbound audio
|
|
6
7
|
* to Float32 mono @ 16 kHz IN-PROCESS (raw PCM / WAV) or via ffmpeg (compressed
|
|
7
8
|
* containers) and hands the samples to the sherpa sidecar ({@link HostClient}).
|
|
8
9
|
* No key, no network at transcription time.
|
|
@@ -15,19 +16,20 @@ import type { spawn } from 'node:child_process';
|
|
|
15
16
|
import { type TranscribeOptions, type Transcriber, type TranscriptionResult } from '@moxxy/sdk';
|
|
16
17
|
import { ensureModelFiles, type FetchLike } from '@moxxy/model-fetch';
|
|
17
18
|
import { type HostClientLike } from './host-client.js';
|
|
18
|
-
|
|
19
|
-
export declare const LOCAL_WHISPER_TRANSCRIBER_NAME = "local-whisper";
|
|
19
|
+
export { LOCAL_PARAKEET_TRANSCRIBER_NAME, LOCAL_WHISPER_TRANSCRIBER_NAME } from './models.js';
|
|
20
20
|
/** Resolved on-disk paths sherpa needs for one model. */
|
|
21
|
-
export interface
|
|
21
|
+
export interface LocalSttModelPaths {
|
|
22
22
|
readonly encoder: string;
|
|
23
23
|
readonly decoder: string;
|
|
24
|
+
readonly joiner?: string;
|
|
24
25
|
readonly tokens: string;
|
|
25
26
|
}
|
|
26
|
-
export interface
|
|
27
|
-
/** Model id
|
|
27
|
+
export interface LocalSttOptions {
|
|
28
|
+
/** Model id, `turbo` by default. */
|
|
28
29
|
readonly model?: string;
|
|
29
30
|
/** Default Whisper language tag (BCP-47-ish, e.g. `en`, `pl`). Per-call
|
|
30
|
-
* `TranscribeOptions.language` overrides it; omit to let Whisper auto-detect.
|
|
31
|
+
* `TranscribeOptions.language` overrides it; omit to let Whisper auto-detect.
|
|
32
|
+
* Parakeet takes no hint: it works the language out itself. */
|
|
31
33
|
readonly language?: string;
|
|
32
34
|
/** Inference threads. Default 2. */
|
|
33
35
|
readonly numThreads?: number;
|
|
@@ -51,8 +53,8 @@ export interface LocalWhisperOptions {
|
|
|
51
53
|
}
|
|
52
54
|
/** Shut down every live local transcriber (kills their sidecars). */
|
|
53
55
|
export declare function shutdownLocalStt(): void;
|
|
54
|
-
export declare class
|
|
55
|
-
readonly name
|
|
56
|
+
export declare class LocalSttTranscriber implements Transcriber {
|
|
57
|
+
readonly name: string;
|
|
56
58
|
private readonly model;
|
|
57
59
|
private readonly defaultLanguage;
|
|
58
60
|
private readonly numThreads;
|
|
@@ -67,10 +69,18 @@ export declare class LocalWhisperTranscriber implements Transcriber {
|
|
|
67
69
|
private host;
|
|
68
70
|
/** In-flight model download promise — de-dupes concurrent first-use. */
|
|
69
71
|
private ensuring;
|
|
70
|
-
|
|
72
|
+
/** Transcriptions in flight: the model stays in memory while any is running. */
|
|
73
|
+
private running;
|
|
74
|
+
private idleTimer;
|
|
75
|
+
constructor(opts?: LocalSttOptions);
|
|
71
76
|
transcribe(audio: Uint8Array | ArrayBuffer, opts?: TranscribeOptions): Promise<TranscriptionResult>;
|
|
72
77
|
/** Kill this transcriber's sidecar (if any) and drop registration. */
|
|
73
78
|
shutdown(): void;
|
|
79
|
+
private holdModel;
|
|
80
|
+
/** The last transcription to finish starts the idle clock. Killing the sidecar
|
|
81
|
+
* is what frees the model's memory; the next call forks a new one. */
|
|
82
|
+
private letModelGo;
|
|
83
|
+
private cancelIdleRelease;
|
|
74
84
|
private getHost;
|
|
75
85
|
/** Resolve on-disk paths for the model, downloading its files once. */
|
|
76
86
|
private ensureModelFiles;
|
|
@@ -81,5 +91,6 @@ export declare class LocalWhisperTranscriber implements Transcriber {
|
|
|
81
91
|
* Fails clearly when no sherpa binary exists for this platform/arch. */
|
|
82
92
|
private defaultHost;
|
|
83
93
|
}
|
|
84
|
-
export declare function createLocalWhisperTranscriber(opts?:
|
|
94
|
+
export declare function createLocalWhisperTranscriber(opts?: LocalSttOptions): LocalSttTranscriber;
|
|
95
|
+
export declare function createLocalParakeetTranscriber(opts?: LocalSttOptions): LocalSttTranscriber;
|
|
85
96
|
//# sourceMappingURL=local-stt.d.ts.map
|
package/dist/local-stt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-stt.d.ts","sourceRoot":"","sources":["../src/local-stt.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"local-stt.d.ts","sourceRoot":"","sources":["../src/local-stt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAEhB,KAAK,SAAS,EAEf,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAYnE,OAAO,EAAE,+BAA+B,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAI9F,yDAAyD;AACzD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,oCAAoC;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;oEAEgE;IAChE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,oFAAoF;IACpF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;q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I,GAAE,eAAoB;IAqBhC,UAAU,CACd,KAAK,EAAE,UAAU,GAAG,WAAW,EAC/B,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IA4D/B,sEAAsE;IACtE,QAAQ,IAAI,IAAI;IAOhB,OAAO,CAAC,SAAS;IAKjB;2EACuE;IACvE,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,OAAO;IAKf,uEAAuE;YACzD,gBAAgB;IA0B9B;iFAC6E;IAC7E,OAAO,CAAC,kBAAkB;IAkB1B;6EACyE;IACzE,OAAO,CAAC,WAAW;CAqBpB;AAED,wBAAgB,6BAA6B,CAAC,IAAI,GAAE,eAAoB,GAAG,mBAAmB,CAE7F;AAED,wBAAgB,8BAA8B,CAAC,IAAI,GAAE,eAAoB,GAAG,mBAAmB,CAE9F"}
|
package/dist/local-stt.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `local-whisper`
|
|
2
|
+
* The `local-whisper` and `local-parakeet` Transcribers: fully local, on-device
|
|
3
|
+
* speech-to-text. They differ only in the catalog entry they read.
|
|
3
4
|
*
|
|
4
5
|
* On the first transcription for a model it downloads + verifies that model's
|
|
5
|
-
*
|
|
6
|
+
* files (once, via @moxxy/model-fetch), then decodes the inbound audio
|
|
6
7
|
* to Float32 mono @ 16 kHz IN-PROCESS (raw PCM / WAV) or via ffmpeg (compressed
|
|
7
8
|
* containers) and hands the samples to the sherpa sidecar ({@link HostClient}).
|
|
8
9
|
* No key, no network at transcription time.
|
|
@@ -15,13 +16,12 @@ import path from 'node:path';
|
|
|
15
16
|
import { fileURLToPath } from 'node:url';
|
|
16
17
|
import { MoxxyError, } from '@moxxy/sdk';
|
|
17
18
|
import { ensureModelFiles, } from '@moxxy/model-fetch';
|
|
18
|
-
import { TARGET_SAMPLE_RATE } from './audio.js';
|
|
19
|
+
import { splitAtSilence, TARGET_SAMPLE_RATE } from './audio.js';
|
|
19
20
|
import { decodeToMono16k } from './decode.js';
|
|
20
21
|
import { HostClient } from './host-client.js';
|
|
21
22
|
import { DEFAULT_MODEL_ID, defaultModelsDir, modelBytes, modelDir, modelFiles, requireModel, } from './models.js';
|
|
22
23
|
import { resolveSherpaLibDir, sherpaEnv, sherpaPlatformPackage } from './platform.js';
|
|
23
|
-
|
|
24
|
-
export const LOCAL_WHISPER_TRANSCRIBER_NAME = 'local-whisper';
|
|
24
|
+
export { LOCAL_PARAKEET_TRANSCRIBER_NAME, LOCAL_WHISPER_TRANSCRIBER_NAME } from './models.js';
|
|
25
25
|
const DEFAULT_NUM_THREADS = 2;
|
|
26
26
|
/** Process-wide set of live transcribers so the plugin's `onShutdown` hook can
|
|
27
27
|
* kill every sidecar it spawned. */
|
|
@@ -32,8 +32,8 @@ export function shutdownLocalStt() {
|
|
|
32
32
|
t.shutdown();
|
|
33
33
|
ACTIVE_STT.clear();
|
|
34
34
|
}
|
|
35
|
-
export class
|
|
36
|
-
name
|
|
35
|
+
export class LocalSttTranscriber {
|
|
36
|
+
name;
|
|
37
37
|
model;
|
|
38
38
|
defaultLanguage;
|
|
39
39
|
numThreads;
|
|
@@ -48,10 +48,14 @@ export class LocalWhisperTranscriber {
|
|
|
48
48
|
host = null;
|
|
49
49
|
/** In-flight model download promise — de-dupes concurrent first-use. */
|
|
50
50
|
ensuring = null;
|
|
51
|
+
/** Transcriptions in flight: the model stays in memory while any is running. */
|
|
52
|
+
running = 0;
|
|
53
|
+
idleTimer = null;
|
|
51
54
|
constructor(opts = {}) {
|
|
52
55
|
// Validate the configured model up front so a bad config fails clearly at
|
|
53
56
|
// construction rather than on the first (possibly channel-triggered) call.
|
|
54
57
|
this.model = requireModel(opts.model ?? DEFAULT_MODEL_ID, 'model');
|
|
58
|
+
this.name = this.model.transcriber;
|
|
55
59
|
this.defaultLanguage = typeof opts.language === 'string' ? opts.language.trim() : '';
|
|
56
60
|
this.numThreads =
|
|
57
61
|
opts.numThreads && Number.isInteger(opts.numThreads) && opts.numThreads > 0
|
|
@@ -80,35 +84,74 @@ export class LocalWhisperTranscriber {
|
|
|
80
84
|
}
|
|
81
85
|
const paths = await this.ensureModelFiles(opts.signal);
|
|
82
86
|
opts.signal?.throwIfAborted();
|
|
83
|
-
const language = ((opts.language ?? this.defaultLanguage) || '').trim();
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
const language = this.model.joiner ? '' : ((opts.language ?? this.defaultLanguage) || '').trim();
|
|
88
|
+
const { maxChunkSeconds } = this.model;
|
|
89
|
+
const parts = maxChunkSeconds ? splitAtSilence(samples, TARGET_SAMPLE_RATE, maxChunkSeconds) : [samples];
|
|
90
|
+
const texts = [];
|
|
91
|
+
let detected;
|
|
92
|
+
this.holdModel();
|
|
93
|
+
try {
|
|
94
|
+
for (const part of parts) {
|
|
95
|
+
opts.signal?.throwIfAborted();
|
|
96
|
+
const result = await this.getHost().transcribe({
|
|
97
|
+
modelKey: paths.encoder,
|
|
98
|
+
encoder: paths.encoder,
|
|
99
|
+
decoder: paths.decoder,
|
|
100
|
+
...(paths.joiner ? { joiner: paths.joiner } : {}),
|
|
101
|
+
tokens: paths.tokens,
|
|
102
|
+
numThreads: this.numThreads,
|
|
103
|
+
provider: this.provider,
|
|
104
|
+
language,
|
|
105
|
+
task: 'transcribe',
|
|
106
|
+
samples: part,
|
|
107
|
+
sampleRate: TARGET_SAMPLE_RATE,
|
|
108
|
+
});
|
|
109
|
+
texts.push(result.text.trim());
|
|
110
|
+
detected ??= result.language;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
this.letModelGo();
|
|
115
|
+
}
|
|
97
116
|
const durationSec = samples.length / TARGET_SAMPLE_RATE;
|
|
98
|
-
// Prefer
|
|
99
|
-
//
|
|
100
|
-
const reported =
|
|
101
|
-
const out = { text:
|
|
117
|
+
// Prefer the detected language; else the caller/default hint (when set) so
|
|
118
|
+
// downstream still gets a BCP-47 tag.
|
|
119
|
+
const reported = detected ?? (language || undefined);
|
|
120
|
+
const out = { text: texts.filter(Boolean).join(' '), durationSec };
|
|
102
121
|
if (reported)
|
|
103
122
|
out.language = reported;
|
|
104
123
|
return out;
|
|
105
124
|
}
|
|
106
125
|
/** Kill this transcriber's sidecar (if any) and drop registration. */
|
|
107
126
|
shutdown() {
|
|
127
|
+
this.cancelIdleRelease();
|
|
108
128
|
this.host?.shutdown();
|
|
109
129
|
this.host = null;
|
|
110
130
|
ACTIVE_STT.delete(this);
|
|
111
131
|
}
|
|
132
|
+
holdModel() {
|
|
133
|
+
this.running += 1;
|
|
134
|
+
this.cancelIdleRelease();
|
|
135
|
+
}
|
|
136
|
+
/** The last transcription to finish starts the idle clock. Killing the sidecar
|
|
137
|
+
* is what frees the model's memory; the next call forks a new one. */
|
|
138
|
+
letModelGo() {
|
|
139
|
+
this.running -= 1;
|
|
140
|
+
const { idleReleaseMs } = this.model;
|
|
141
|
+
if (!idleReleaseMs || this.running > 0)
|
|
142
|
+
return;
|
|
143
|
+
this.idleTimer = setTimeout(() => {
|
|
144
|
+
this.idleTimer = null;
|
|
145
|
+
this.host?.shutdown();
|
|
146
|
+
this.host = null;
|
|
147
|
+
}, idleReleaseMs);
|
|
148
|
+
this.idleTimer.unref?.();
|
|
149
|
+
}
|
|
150
|
+
cancelIdleRelease() {
|
|
151
|
+
if (this.idleTimer)
|
|
152
|
+
clearTimeout(this.idleTimer);
|
|
153
|
+
this.idleTimer = null;
|
|
154
|
+
}
|
|
112
155
|
getHost() {
|
|
113
156
|
this.host ??= this.hostFactory();
|
|
114
157
|
return this.host;
|
|
@@ -136,6 +179,7 @@ export class LocalWhisperTranscriber {
|
|
|
136
179
|
return {
|
|
137
180
|
encoder: path.join(dir, this.model.encoder.name),
|
|
138
181
|
decoder: path.join(dir, this.model.decoder.name),
|
|
182
|
+
...(this.model.joiner ? { joiner: path.join(dir, this.model.joiner.name) } : {}),
|
|
139
183
|
tokens: path.join(dir, this.model.tokens.name),
|
|
140
184
|
};
|
|
141
185
|
}
|
|
@@ -151,7 +195,7 @@ export class LocalWhisperTranscriber {
|
|
|
151
195
|
return;
|
|
152
196
|
started = true;
|
|
153
197
|
const mb = Math.round(modelBytes(this.model) / 1_000_000);
|
|
154
|
-
this.log(`stt-local: first use — downloading
|
|
198
|
+
this.log(`stt-local: first use — downloading ${this.model.label} (~${mb} MB) to ${this.modelsDir}, one-time`);
|
|
155
199
|
}
|
|
156
200
|
if (pct >= lastPct + 10) {
|
|
157
201
|
lastPct = pct - (pct % 10);
|
|
@@ -168,8 +212,8 @@ export class LocalWhisperTranscriber {
|
|
|
168
212
|
throw new MoxxyError({
|
|
169
213
|
code: 'PLUGIN_LOAD_FAILED',
|
|
170
214
|
message: pkg
|
|
171
|
-
? `Local
|
|
172
|
-
: `Local
|
|
215
|
+
? `Local transcription could not load the sherpa-onnx binary (${pkg}). Reinstall @moxxy/plugin-stt-local so its platform dependency is fetched.`
|
|
216
|
+
: `Local transcription has no sherpa-onnx binary for ${process.platform}-${process.arch}.`,
|
|
173
217
|
hint: 'Use the OpenAI Whisper backend instead, or run on a supported platform (macOS/Linux/Windows x64, macOS/Linux arm64).',
|
|
174
218
|
context: { platform: process.platform, arch: process.arch },
|
|
175
219
|
});
|
|
@@ -183,6 +227,9 @@ export class LocalWhisperTranscriber {
|
|
|
183
227
|
}
|
|
184
228
|
}
|
|
185
229
|
export function createLocalWhisperTranscriber(opts = {}) {
|
|
186
|
-
return new
|
|
230
|
+
return new LocalSttTranscriber(opts);
|
|
231
|
+
}
|
|
232
|
+
export function createLocalParakeetTranscriber(opts = {}) {
|
|
233
|
+
return new LocalSttTranscriber({ ...opts, model: 'parakeet' });
|
|
187
234
|
}
|
|
188
235
|
//# sourceMappingURL=local-stt.js.map
|