parakeet.ts 1.0.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.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +286 -0
  3. package/dist/alignment.d.ts +36 -0
  4. package/dist/alignment.d.ts.map +1 -0
  5. package/dist/alignment.js +202 -0
  6. package/dist/alignment.js.map +1 -0
  7. package/dist/audio.d.ts +59 -0
  8. package/dist/audio.d.ts.map +1 -0
  9. package/dist/audio.js +324 -0
  10. package/dist/audio.js.map +1 -0
  11. package/dist/backend.d.ts +61 -0
  12. package/dist/backend.d.ts.map +1 -0
  13. package/dist/backend.js +14 -0
  14. package/dist/backend.js.map +1 -0
  15. package/dist/decode.d.ts +38 -0
  16. package/dist/decode.d.ts.map +1 -0
  17. package/dist/decode.js +124 -0
  18. package/dist/decode.js.map +1 -0
  19. package/dist/hub.d.ts +18 -0
  20. package/dist/hub.d.ts.map +1 -0
  21. package/dist/hub.js +86 -0
  22. package/dist/hub.js.map +1 -0
  23. package/dist/index.d.ts +13 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +19 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/load.d.ts +51 -0
  28. package/dist/load.d.ts.map +1 -0
  29. package/dist/load.js +34 -0
  30. package/dist/load.js.map +1 -0
  31. package/dist/mlx/attention.d.ts +61 -0
  32. package/dist/mlx/attention.d.ts.map +1 -0
  33. package/dist/mlx/attention.js +330 -0
  34. package/dist/mlx/attention.js.map +1 -0
  35. package/dist/mlx/audio.d.ts +46 -0
  36. package/dist/mlx/audio.d.ts.map +1 -0
  37. package/dist/mlx/audio.js +309 -0
  38. package/dist/mlx/audio.js.map +1 -0
  39. package/dist/mlx/backend.d.ts +22 -0
  40. package/dist/mlx/backend.d.ts.map +1 -0
  41. package/dist/mlx/backend.js +67 -0
  42. package/dist/mlx/backend.js.map +1 -0
  43. package/dist/mlx/cache.d.ts +23 -0
  44. package/dist/mlx/cache.d.ts.map +1 -0
  45. package/dist/mlx/cache.js +98 -0
  46. package/dist/mlx/cache.js.map +1 -0
  47. package/dist/mlx/cli.d.ts +12 -0
  48. package/dist/mlx/cli.d.ts.map +1 -0
  49. package/dist/mlx/cli.js +145 -0
  50. package/dist/mlx/cli.js.map +1 -0
  51. package/dist/mlx/conformer.d.ts +81 -0
  52. package/dist/mlx/conformer.d.ts.map +1 -0
  53. package/dist/mlx/conformer.js +315 -0
  54. package/dist/mlx/conformer.js.map +1 -0
  55. package/dist/mlx/index.d.ts +6 -0
  56. package/dist/mlx/index.d.ts.map +1 -0
  57. package/dist/mlx/index.js +9 -0
  58. package/dist/mlx/index.js.map +1 -0
  59. package/dist/mlx/load.d.ts +27 -0
  60. package/dist/mlx/load.d.ts.map +1 -0
  61. package/dist/mlx/load.js +161 -0
  62. package/dist/mlx/load.js.map +1 -0
  63. package/dist/mlx/nn.d.ts +121 -0
  64. package/dist/mlx/nn.d.ts.map +1 -0
  65. package/dist/mlx/nn.js +511 -0
  66. package/dist/mlx/nn.js.map +1 -0
  67. package/dist/mlx/rnnt.d.ts +59 -0
  68. package/dist/mlx/rnnt.d.ts.map +1 -0
  69. package/dist/mlx/rnnt.js +233 -0
  70. package/dist/mlx/rnnt.js.map +1 -0
  71. package/dist/mlx/server.d.ts +34 -0
  72. package/dist/mlx/server.d.ts.map +1 -0
  73. package/dist/mlx/server.js +115 -0
  74. package/dist/mlx/server.js.map +1 -0
  75. package/dist/mlx/utils.d.ts +19 -0
  76. package/dist/mlx/utils.d.ts.map +1 -0
  77. package/dist/mlx/utils.js +103 -0
  78. package/dist/mlx/utils.js.map +1 -0
  79. package/dist/model.d.ts +112 -0
  80. package/dist/model.d.ts.map +1 -0
  81. package/dist/model.js +196 -0
  82. package/dist/model.js.map +1 -0
  83. package/dist/onnx/backend.d.ts +55 -0
  84. package/dist/onnx/backend.d.ts.map +1 -0
  85. package/dist/onnx/backend.js +111 -0
  86. package/dist/onnx/backend.js.map +1 -0
  87. package/dist/onnx/index.d.ts +7 -0
  88. package/dist/onnx/index.d.ts.map +1 -0
  89. package/dist/onnx/index.js +6 -0
  90. package/dist/onnx/index.js.map +1 -0
  91. package/dist/onnx/parakeet.d.ts +44 -0
  92. package/dist/onnx/parakeet.d.ts.map +1 -0
  93. package/dist/onnx/parakeet.js +135 -0
  94. package/dist/onnx/parakeet.js.map +1 -0
  95. package/dist/tokenizer.d.ts +6 -0
  96. package/dist/tokenizer.d.ts.map +1 -0
  97. package/dist/tokenizer.js +8 -0
  98. package/dist/tokenizer.js.map +1 -0
  99. package/package.json +85 -0
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Low-level model-loading helpers for the MLX backend.
3
+ *
4
+ * - `loadSafetensors` parses a SafeTensors weight file into a WeightMap.
5
+ * - `downloadFromHub` is re-exported from `../hub.ts` for backwards
6
+ * compatibility; the implementation is backend-agnostic.
7
+ *
8
+ * The public loaders (`fromLocal` / `fromPretrained`) live in `./load.ts`, which
9
+ * builds a backend-agnostic `ParakeetModel` from these pieces.
10
+ */
11
+ import fs from 'node:fs';
12
+ /**
13
+ * Parse a safetensors file and return a WeightMap.
14
+ * The safetensors format: 8 bytes (header length LE uint64) + JSON header + data.
15
+ * Uses fd-based random access to support files larger than the 2 GiB Buffer limit.
16
+ */
17
+ export function loadSafetensors(filePath) {
18
+ const fd = fs.openSync(filePath, 'r');
19
+ try {
20
+ // Read the 8-byte header length
21
+ const lenBuf = Buffer.allocUnsafe(8);
22
+ fs.readSync(fd, lenBuf, 0, 8, 0);
23
+ const headerLen = Number(new DataView(lenBuf.buffer, lenBuf.byteOffset, 8).getBigUint64(0, true));
24
+ // Read the JSON header
25
+ const headerBuf = Buffer.allocUnsafe(headerLen);
26
+ fs.readSync(fd, headerBuf, 0, headerLen, 8);
27
+ const header = JSON.parse(headerBuf.toString('utf8'));
28
+ const dataStart = 8 + headerLen;
29
+ const map = new Map();
30
+ for (const [name, meta] of Object.entries(header)) {
31
+ if (name === '__metadata__')
32
+ continue;
33
+ const [start, end] = meta.data_offsets;
34
+ const byteLen = end - start;
35
+ const rawSlice = Buffer.allocUnsafe(byteLen);
36
+ fs.readSync(fd, rawSlice, 0, byteLen, dataStart + start);
37
+ const shape = meta.shape;
38
+ let data;
39
+ switch (meta.dtype) {
40
+ case 'F32':
41
+ data = new Float32Array(rawSlice.buffer, rawSlice.byteOffset, byteLen / 4);
42
+ break;
43
+ case 'BF16':
44
+ data = bf16ToF32(rawSlice);
45
+ break;
46
+ case 'F16':
47
+ data = f16ToF32(rawSlice);
48
+ break;
49
+ case 'I32':
50
+ data = new Float32Array(new Int32Array(rawSlice.buffer, rawSlice.byteOffset, byteLen / 4));
51
+ break;
52
+ default:
53
+ continue;
54
+ }
55
+ map.set(name, { data: new Float32Array(data), shape });
56
+ }
57
+ return map;
58
+ }
59
+ finally {
60
+ fs.closeSync(fd);
61
+ }
62
+ }
63
+ function bf16ToF32(buf) {
64
+ const n = buf.byteLength / 2;
65
+ const out = new Float32Array(n);
66
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
67
+ for (let i = 0; i < n; i++) {
68
+ const bits = view.getUint16(i * 2, true);
69
+ // BF16: sign[1] + exponent[8] + mantissa[7] → F32: shift mantissa left by 16
70
+ const f32bits = bits << 16;
71
+ const f32view = new DataView(new ArrayBuffer(4));
72
+ f32view.setInt32(0, f32bits, true);
73
+ out[i] = f32view.getFloat32(0, true);
74
+ }
75
+ return out;
76
+ }
77
+ function f16ToF32(buf) {
78
+ const n = buf.byteLength / 2;
79
+ const out = new Float32Array(n);
80
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
81
+ for (let i = 0; i < n; i++) {
82
+ const h = view.getUint16(i * 2, true);
83
+ const sign = (h >> 15) & 1;
84
+ const exp = (h >> 10) & 0x1f;
85
+ const mant = h & 0x3ff;
86
+ if (exp === 0) {
87
+ out[i] = sign ? -0 : 0;
88
+ }
89
+ else if (exp === 0x1f) {
90
+ out[i] = mant ? NaN : sign ? -Infinity : Infinity;
91
+ }
92
+ else {
93
+ const f = (1 + mant / 1024) * Math.pow(2, exp - 15);
94
+ out[i] = sign ? -f : f;
95
+ }
96
+ }
97
+ return out;
98
+ }
99
+ // ---------------------------------------------------------------------------
100
+ // HuggingFace Hub download — implementation lives in ../hub.ts (backend-agnostic)
101
+ // ---------------------------------------------------------------------------
102
+ export { downloadFromHub } from '../hub.js';
103
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/mlx/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AAgBzB;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAEtC,IAAI,CAAC;QACH,gCAAgC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACrC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACjC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;QAElG,uBAAuB;QACvB,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAChD,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAqB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAExE,MAAM,SAAS,GAAG,CAAC,GAAG,SAAS,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all. It owns the shared audio
5
+ * front-end, the greedy decode loops, chunking and streaming, and drives
6
+ * whatever `ParakeetBackend` it is given — MLX on Apple Silicon, ONNX Runtime
7
+ * with the CUDA execution provider on Linux/Nvidia.
8
+ */
9
+ import type { ParakeetBackend, EncoderOutput } from './backend.js';
10
+ import { PreprocessArgs } from './audio.js';
11
+ import { DecoderState } from './decode.js';
12
+ import { AlignedToken, AlignedResult, SentenceConfig } from './alignment.js';
13
+ export interface TranscribeOptions {
14
+ /** Split audio into chunks of this many seconds. Unset = single pass. */
15
+ chunkDuration?: number;
16
+ /** Overlap between chunks, seconds. Default 15. */
17
+ overlapDuration?: number;
18
+ onChunk?: (processed: number, total: number) => void;
19
+ sentence?: SentenceConfig;
20
+ }
21
+ export interface ParakeetModelArgs {
22
+ backend: ParakeetBackend;
23
+ preprocessor: PreprocessArgs;
24
+ vocabulary: string[];
25
+ /** TDT duration table, or null for plain RNN-T. */
26
+ durations: number[] | null;
27
+ maxSymbols: number | null;
28
+ subsamplingFactor: number;
29
+ }
30
+ export declare class ParakeetModel {
31
+ readonly backend: ParakeetBackend;
32
+ readonly preprocessorConfig: PreprocessArgs;
33
+ readonly vocabulary: string[];
34
+ readonly durations: number[] | null;
35
+ readonly maxSymbols: number | null;
36
+ readonly subsamplingFactor: number;
37
+ constructor(args: ParakeetModelArgs);
38
+ /** Seconds of audio per encoder frame. */
39
+ get timeRatio(): number;
40
+ /** Run the shared mel front-end and the backend encoder. */
41
+ encodePcm(pcm: Float32Array): Promise<EncoderOutput>;
42
+ /** Greedy-decode an encoder output, threading decoder state. */
43
+ decode(enc: EncoderOutput, state?: DecoderState, range?: {
44
+ from?: number;
45
+ to?: number;
46
+ timeOffset?: number;
47
+ }): Promise<{
48
+ tokens: AlignedToken[];
49
+ state: DecoderState;
50
+ }>;
51
+ transcribe(file: string, options?: TranscribeOptions): Promise<AlignedResult>;
52
+ /** Transcribe raw mono float32 PCM at the model's sample rate. */
53
+ transcribePcm(pcm: Float32Array, options?: TranscribeOptions): Promise<AlignedResult>;
54
+ transcribeStream(options?: StreamOptions): StreamingParakeet;
55
+ dispose(): Promise<void>;
56
+ }
57
+ export interface StreamOptions {
58
+ /** Max seconds of audio re-encoded per update. Default 12. */
59
+ windowSeconds?: number;
60
+ /**
61
+ * Encoder frames at the tail left uncommitted (revisable). Larger = better
62
+ * quality at the edge, more churn in `draftTokens`. Default 12.
63
+ */
64
+ dropFrames?: number;
65
+ sentence?: SentenceConfig;
66
+ }
67
+ /**
68
+ * Streaming transcription by sliding-window re-encode.
69
+ *
70
+ * No encoder cache is involved: a bounded window of recent audio is re-encoded
71
+ * on each update and re-decoded from the last committed frame. Tokens older
72
+ * than `dropFrames` from the window end are finalized; the tail is draft and
73
+ * may be revised. This keeps the encoder's full bidirectional context inside
74
+ * the window, which suits an offline-trained checkpoint better than limited
75
+ * left/right context, and it needs nothing from the backend beyond `encode`
76
+ * and `decodeStep` — so it works identically on MLX and ONNX.
77
+ */
78
+ export declare class StreamingParakeet {
79
+ private readonly model;
80
+ private readonly windowSamples;
81
+ private readonly dropFrames;
82
+ private readonly sentence?;
83
+ private audio;
84
+ /** Absolute encoder-frame index corresponding to `audio[0]`. */
85
+ private windowStartFrame;
86
+ /** Absolute encoder frame already committed. */
87
+ private finalizedUpTo;
88
+ private state;
89
+ private _finalized;
90
+ private _draft;
91
+ constructor(model: ParakeetModel, options?: StreamOptions);
92
+ private get samplesPerFrame();
93
+ /** Committed tokens — will not be revised. */
94
+ get finalizedTokens(): AlignedToken[];
95
+ /** Tokens in the revisable tail. */
96
+ get draftTokens(): AlignedToken[];
97
+ get finalizedResult(): AlignedResult;
98
+ /** Best current guess: committed + draft. */
99
+ get result(): AlignedResult;
100
+ addAudio(pcm: Float32Array): Promise<void>;
101
+ /** Commit the remaining draft. Call once the audio stream ends. */
102
+ finish(): AlignedResult;
103
+ }
104
+ /**
105
+ * Feed an async iterable of raw PCM frames (Float32Array, mono at the model's
106
+ * sample rate) into a streaming session and return the final AlignedResult.
107
+ *
108
+ * The common "consume and wait" pattern behind the CLI `--stream` flag and the
109
+ * HTTP server's transcribe endpoint.
110
+ */
111
+ export declare function consumePcmStream(stream: StreamingParakeet, source: AsyncIterable<Float32Array>): Promise<AlignedResult>;
112
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAA2B,cAAc,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAqC,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EACL,YAAY,EAAE,aAAa,EAAE,cAAc,EAE5C,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,eAAe,CAAC;IACzB,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,mDAAmD;IACnD,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,aAAa;IACxB,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,kBAAkB,EAAE,cAAc,CAAC;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,SAAS,E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AO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAiB;IAE3C,OAAO,CAAC,KAAK,CAAqC;IAClD,gEAAgE;IAChE,OAAO,CAAC,gBAAgB,CAAK;IAC7B,gDAAgD;IAChD,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,KAAK,CAAwD;IACrE,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,MAAM,CAAsB;gBAExB,KAAK,EAAE,aAAa,EAAE,OAAO,GAAE,aAAkB;IAQ7D,OAAO,KAAK,eAAe,GAE1B;IAED,8CAA8C;IAC9C,IAAI,eAAe,IAAI,YAAY,EAAE,CAAiC;IACtE,oCAAoC;IACpC,IAAI,WAAW,IAAI,YAAY,EAAE,CAA6B;IAE9D,IAAI,eAAe,IAAI,aAAa,CAEnC;IAED,6CAA6C;IAC7C,IAAI,MAAM,IAAI,aAAa,CAI1B;IAEK,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAgDhD,mEAAmE;IACnE,MAAM,IAAI,aAAa;CAKxB;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,GAClC,OAAO,CAAC,aAAa,CAAC,CAKxB"}
package/dist/model.js ADDED
@@ -0,0 +1,196 @@
1
+ import { getLogMel, loadAudioRaw } from './audio.js';
2
+ import { decodeTDTGreedy, decodeRNNTGreedy } from './decode.js';
3
+ import { tokensToSentences, sentencesToResult, mergeLongestContiguous, mergeLongestCommonSubsequence, } from './alignment.js';
4
+ export class ParakeetModel {
5
+ backend;
6
+ preprocessorConfig;
7
+ vocabulary;
8
+ durations;
9
+ maxSymbols;
10
+ subsamplingFactor;
11
+ constructor(args) {
12
+ this.backend = args.backend;
13
+ this.preprocessorConfig = args.preprocessor;
14
+ this.vocabulary = args.vocabulary;
15
+ this.durations = args.durations;
16
+ this.maxSymbols = args.maxSymbols;
17
+ this.subsamplingFactor = args.subsamplingFactor;
18
+ }
19
+ /** Seconds of audio per encoder frame. */
20
+ get timeRatio() {
21
+ return (this.subsamplingFactor / this.preprocessorConfig.sampleRate)
22
+ * this.preprocessorConfig.hopLength;
23
+ }
24
+ /** Run the shared mel front-end and the backend encoder. */
25
+ async encodePcm(pcm) {
26
+ const { data, nMels, numFrames } = getLogMel(pcm, this.preprocessorConfig);
27
+ return this.backend.encode(data, nMels, numFrames);
28
+ }
29
+ /** Greedy-decode an encoder output, threading decoder state. */
30
+ async decode(enc, state = { lastToken: null, hiddenState: null }, range) {
31
+ const opts = {
32
+ vocabulary: this.vocabulary,
33
+ maxSymbols: this.maxSymbols,
34
+ timeRatio: this.timeRatio,
35
+ ...range,
36
+ };
37
+ return this.durations
38
+ ? decodeTDTGreedy(this.backend, enc, this.durations, state, opts)
39
+ : decodeRNNTGreedy(this.backend, enc, state, opts);
40
+ }
41
+ async transcribe(file, options = {}) {
42
+ const { chunkDuration, overlapDuration = 15.0, onChunk, sentence } = options;
43
+ const sr = this.preprocessorConfig.sampleRate;
44
+ const pcm = loadAudioRaw(file, sr);
45
+ return this.transcribePcm(pcm, options);
46
+ }
47
+ /** Transcribe raw mono float32 PCM at the model's sample rate. */
48
+ async transcribePcm(pcm, options = {}) {
49
+ const { chunkDuration, overlapDuration = 15.0, onChunk, sentence } = options;
50
+ const sr = this.preprocessorConfig.sampleRate;
51
+ if (chunkDuration === undefined || pcm.length / sr <= chunkDuration) {
52
+ const enc = await this.encodePcm(pcm);
53
+ const { tokens } = await this.decode(enc);
54
+ return sentencesToResult(tokensToSentences(tokens, sentence));
55
+ }
56
+ const chunkSamples = Math.floor(chunkDuration * sr);
57
+ const overlapSamples = Math.floor(overlapDuration * sr);
58
+ let allTokens = [];
59
+ for (let start = 0; start < pcm.length; start += chunkSamples - overlapSamples) {
60
+ const end = Math.min(start + chunkSamples, pcm.length);
61
+ if (onChunk)
62
+ onChunk(end, pcm.length);
63
+ if (end - start < this.preprocessorConfig.hopLength)
64
+ break;
65
+ const enc = await this.encodePcm(pcm.subarray(start, end));
66
+ const { tokens } = await this.decode(enc, { lastToken: null, hiddenState: null }, { timeOffset: start / sr });
67
+ if (allTokens.length > 0) {
68
+ try {
69
+ allTokens = mergeLongestContiguous(allTokens, tokens, overlapDuration);
70
+ }
71
+ catch {
72
+ allTokens = mergeLongestCommonSubsequence(allTokens, tokens, overlapDuration);
73
+ }
74
+ }
75
+ else {
76
+ allTokens = tokens;
77
+ }
78
+ }
79
+ return sentencesToResult(tokensToSentences(allTokens, sentence));
80
+ }
81
+ transcribeStream(options = {}) {
82
+ return new StreamingParakeet(this, options);
83
+ }
84
+ async dispose() {
85
+ await this.backend.dispose?.();
86
+ }
87
+ }
88
+ /**
89
+ * Streaming transcription by sliding-window re-encode.
90
+ *
91
+ * No encoder cache is involved: a bounded window of recent audio is re-encoded
92
+ * on each update and re-decoded from the last committed frame. Tokens older
93
+ * than `dropFrames` from the window end are finalized; the tail is draft and
94
+ * may be revised. This keeps the encoder's full bidirectional context inside
95
+ * the window, which suits an offline-trained checkpoint better than limited
96
+ * left/right context, and it needs nothing from the backend beyond `encode`
97
+ * and `decodeStep` — so it works identically on MLX and ONNX.
98
+ */
99
+ export class StreamingParakeet {
100
+ model;
101
+ windowSamples;
102
+ dropFrames;
103
+ sentence;
104
+ audio = new Float32Array(0);
105
+ /** Absolute encoder-frame index corresponding to `audio[0]`. */
106
+ windowStartFrame = 0;
107
+ /** Absolute encoder frame already committed. */
108
+ finalizedUpTo = 0;
109
+ state = { lastToken: null, hiddenState: null };
110
+ _finalized = [];
111
+ _draft = [];
112
+ constructor(model, options = {}) {
113
+ this.model = model;
114
+ const sr = model.preprocessorConfig.sampleRate;
115
+ this.windowSamples = Math.floor((options.windowSeconds ?? 12.0) * sr);
116
+ this.dropFrames = options.dropFrames ?? 12;
117
+ this.sentence = options.sentence;
118
+ }
119
+ get samplesPerFrame() {
120
+ return this.model.preprocessorConfig.hopLength * this.model.subsamplingFactor;
121
+ }
122
+ /** Committed tokens — will not be revised. */
123
+ get finalizedTokens() { return [...this._finalized]; }
124
+ /** Tokens in the revisable tail. */
125
+ get draftTokens() { return [...this._draft]; }
126
+ get finalizedResult() {
127
+ return sentencesToResult(tokensToSentences(this._finalized, this.sentence));
128
+ }
129
+ /** Best current guess: committed + draft. */
130
+ get result() {
131
+ return sentencesToResult(tokensToSentences([...this._finalized, ...this._draft], this.sentence));
132
+ }
133
+ async addAudio(pcm) {
134
+ const combined = new Float32Array(this.audio.length + pcm.length);
135
+ combined.set(this.audio);
136
+ combined.set(pcm, this.audio.length);
137
+ this.audio = combined;
138
+ // Not enough audio yet for a single subsampled encoder frame. Running the
139
+ // front-end / encoder on a sub-frame window aborts natively (e.g. "[squeeze]
140
+ // Cannot squeeze axis 1 with size 0") and cannot be caught in JS — keep
141
+ // buffering until a later call has enough. Harmless for normal chunk sizes.
142
+ const minSamples = this.model.preprocessorConfig.nFft + this.samplesPerFrame;
143
+ if (this.audio.length < minSamples)
144
+ return;
145
+ // Trim in whole encoder frames so absolute frame accounting stays exact.
146
+ const spf = this.samplesPerFrame;
147
+ if (this.audio.length > this.windowSamples) {
148
+ const dropSamples = Math.floor((this.audio.length - this.windowSamples) / spf) * spf;
149
+ if (dropSamples > 0) {
150
+ this.audio = this.audio.slice(dropSamples);
151
+ this.windowStartFrame += dropSamples / spf;
152
+ }
153
+ }
154
+ const enc = await this.model.encodePcm(this.audio);
155
+ const absEnd = this.windowStartFrame + enc.frames;
156
+ const commitUntil = Math.max(this.finalizedUpTo, absEnd - this.dropFrames);
157
+ const timeOffset = this.windowStartFrame * this.model.timeRatio;
158
+ if (commitUntil > this.finalizedUpTo) {
159
+ const { tokens, state } = await this.model.decode(enc, this.state, {
160
+ from: this.finalizedUpTo - this.windowStartFrame,
161
+ to: commitUntil - this.windowStartFrame,
162
+ timeOffset,
163
+ });
164
+ this._finalized.push(...tokens);
165
+ this.state = state;
166
+ this.finalizedUpTo = commitUntil;
167
+ }
168
+ // Speculative tail; its state is intentionally discarded.
169
+ const { tokens: draft } = await this.model.decode(enc, this.state, {
170
+ from: commitUntil - this.windowStartFrame,
171
+ to: enc.frames,
172
+ timeOffset,
173
+ });
174
+ this._draft = draft;
175
+ }
176
+ /** Commit the remaining draft. Call once the audio stream ends. */
177
+ finish() {
178
+ this._finalized.push(...this._draft);
179
+ this._draft = [];
180
+ return this.finalizedResult;
181
+ }
182
+ }
183
+ /**
184
+ * Feed an async iterable of raw PCM frames (Float32Array, mono at the model's
185
+ * sample rate) into a streaming session and return the final AlignedResult.
186
+ *
187
+ * The common "consume and wait" pattern behind the CLI `--stream` flag and the
188
+ * HTTP server's transcribe endpoint.
189
+ */
190
+ export async function consumePcmStream(stream, source) {
191
+ for await (const chunk of source) {
192
+ await stream.addAudio(chunk);
193
+ }
194
+ return stream.finish();
195
+ }
196
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAkB,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AAC9E,OAAO,EACwC,iBAAiB,EAAE,iBAAiB,EACjF,sBAAsB,EAAE,6BAA6B,GACtD,MAAM,gBAAgB,CAAC;AAqBxB,MAAM,OAAO,aAAa;IACf,OAAO,CAAkB;IACzB,kBAAkB,CAAiB;IACnC,UAAU,CAAW;IACrB,SAAS,CAAkB;IAC3B,UAAU,CAAgB;IAC1B,iBAAiB,CAAS;IAEnC,YAAY,IAAuB;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC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UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAyB,EACzB,MAAmC;IAEnC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * ONNX Runtime backend — CUDA execution provider on Linux/Nvidia.
3
+ *
4
+ * Two sessions: the conformer encoder, and the fused prediction+joint
5
+ * `decoder_joint` graph. `onnxruntime-node` is loaded lazily so that a
6
+ * Mac-only install never has to resolve it.
7
+ *
8
+ * Graph contract (parakeet-tdt-0.6b-v3 exports):
9
+ * encoder : audio_signal [1,nMels,T_mel], length [1]
10
+ * -> outputs [1,D,T], encoded_lengths [1]
11
+ * decoder_joint : encoder_outputs [1,D,1], targets [1,1], target_length [1],
12
+ * input_states_1 [L,1,H], input_states_2 [L,1,H]
13
+ * -> outputs [1,1,1,C], output_states_1, output_states_2
14
+ */
15
+ import type { ParakeetBackend, EncoderOutput, DecodeStepResult, DecoderStateHandle } from '../backend.js';
16
+ export type ExecutionProvider = 'cuda' | 'cpu' | 'tensorrt' | 'coreml' | 'dml';
17
+ export interface OnnxBackendOptions {
18
+ encoderPath: string;
19
+ decoderJointPath: string;
20
+ /** Execution provider for the encoder. Default: 'cuda' on linux/win x64, else 'cpu'. */
21
+ executionProvider?: ExecutionProvider;
22
+ /**
23
+ * Execution provider for the autoregressive decode step. Defaults to the same
24
+ * as `executionProvider`. CPU is a reasonable choice — the step is small
25
+ * (~0.5 ms) and CPU avoids per-step device round trips.
26
+ */
27
+ decoderExecutionProvider?: ExecutionProvider;
28
+ /** LSTM layers in the prediction network (state dim 0). Default 2. */
29
+ predRnnLayers?: number;
30
+ /** LSTM hidden size (state dim 2). Default 640. */
31
+ predHidden?: number;
32
+ /** ORT log severity: 0 verbose .. 4 fatal. Default 3 (error). */
33
+ logSeverityLevel?: number;
34
+ }
35
+ export declare function defaultExecutionProvider(): ExecutionProvider;
36
+ export declare class OnnxBackend implements ParakeetBackend {
37
+ readonly name: string;
38
+ readonly encoderDim: number;
39
+ private readonly ort;
40
+ private readonly encoder;
41
+ private readonly decoderJoint;
42
+ private readonly predRnnLayers;
43
+ private readonly predHidden;
44
+ private readonly zeroState;
45
+ /** Reused scratch for the single-element int32 inputs. */
46
+ private readonly targetLength;
47
+ private constructor();
48
+ static create(opts: OnnxBackendOptions): Promise<OnnxBackend>;
49
+ encode(mel: Float32Array, nMels: number, numFrames: number): Promise<EncoderOutput>;
50
+ decodeStep(encFrame: Float32Array, token: number | null, state: DecoderStateHandle | null): Promise<DecodeStepResult>;
51
+ /** Blank/padding token id, set by the model wrapper (vocabulary length). */
52
+ blankId: number;
53
+ dispose(): Promise<void>;
54
+ }
55
+ //# sourceMappingURL=backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/onnx/backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAe1G,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE/E,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;;;OAIG;IACH,wBAAwB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= (mod.default ?? mod);
8
+ return ortModule;
9
+ }
10
+ catch (err) {
11
+ throw new Error('The ONNX backend requires the optional dependency "onnxruntime-node". ' +
12
+ 'Install it with `npm install onnxruntime-node`. ' +
13
+ `Original error: ${err.message}`);
14
+ }
15
+ }
16
+ export function defaultExecutionProvider() {
17
+ if (process.platform === 'darwin')
18
+ return 'cpu';
19
+ if (process.arch === 'x64' && (process.platform === 'linux' || process.platform === 'win32')) {
20
+ return 'cuda';
21
+ }
22
+ return 'cpu';
23
+ }
24
+ export class OnnxBackend {
25
+ name;
26
+ encoderDim;
27
+ ort;
28
+ encoder;
29
+ decoderJoint;
30
+ predRnnLayers;
31
+ predHidden;
32
+ zeroState;
33
+ /** Reused scratch for the single-element int32 inputs. */
34
+ targetLength;
35
+ constructor(ort, encoder, decoderJoint, encoderDim, predRnnLayers, predHidden, name) {
36
+ this.ort = ort;
37
+ this.encoder = encoder;
38
+ this.decoderJoint = decoderJoint;
39
+ this.encoderDim = encoderDim;
40
+ this.predRnnLayers = predRnnLayers;
41
+ this.predHidden = predHidden;
42
+ this.name = name;
43
+ const size = predRnnLayers * predHidden;
44
+ this.zeroState = {
45
+ s1: new ort.Tensor('float32', new Float32Array(size), [predRnnLayers, 1, predHidden]),
46
+ s2: new ort.Tensor('float32', new Float32Array(size), [predRnnLayers, 1, predHidden]),
47
+ };
48
+ this.targetLength = new ort.Tensor('int32', Int32Array.from([1]), [1]);
49
+ }
50
+ static async create(opts) {
51
+ const ort = await loadOrt();
52
+ const ep = opts.executionProvider ?? defaultExecutionProvider();
53
+ const decEp = opts.decoderExecutionProvider ?? ep;
54
+ const sev = opts.logSeverityLevel ?? 3;
55
+ const encoder = await ort.InferenceSession.create(opts.encoderPath, {
56
+ executionProviders: [ep], logSeverityLevel: sev,
57
+ });
58
+ const decoderJoint = await ort.InferenceSession.create(opts.decoderJointPath, {
59
+ executionProviders: [decEp], logSeverityLevel: sev,
60
+ });
61
+ // encoderDim is discovered on first encode; probe it cheaply from the
62
+ // decoder_joint graph instead by running a 1-frame step is overkill, so we
63
+ // take it from options-free defaults and correct it after the first encode.
64
+ const backend = new OnnxBackend(ort, encoder, decoderJoint, 0, opts.predRnnLayers ?? 2, opts.predHidden ?? 640, decEp === ep ? `onnx-${ep}` : `onnx-${ep}/${decEp}`);
65
+ return backend;
66
+ }
67
+ async encode(mel, nMels, numFrames) {
68
+ const feeds = {
69
+ audio_signal: new this.ort.Tensor('float32', mel, [1, nMels, numFrames]),
70
+ length: new this.ort.Tensor('int64', BigInt64Array.from([BigInt(numFrames)]), [1]),
71
+ };
72
+ const out = await this.encoder.run(feeds);
73
+ const encoded = out['outputs'];
74
+ const frames = Number(out['encoded_lengths'].data[0]);
75
+ const dim = encoded.dims[1];
76
+ // `encoderDim` is readonly to callers but discovered here on first use.
77
+ this.encoderDim = dim;
78
+ return {
79
+ data: encoded.data,
80
+ dim,
81
+ frames,
82
+ stride: encoded.dims[2],
83
+ layout: 'dim-major',
84
+ };
85
+ }
86
+ async decodeStep(encFrame, token, state) {
87
+ const st = state ?? this.zeroState;
88
+ // The blank id doubles as the prediction network's padding_idx, whose
89
+ // embedding row is zero — this is the "start of sequence" input.
90
+ const tokenId = token ?? this.blankId;
91
+ const feeds = {
92
+ encoder_outputs: new this.ort.Tensor('float32', encFrame, [1, encFrame.length, 1]),
93
+ targets: new this.ort.Tensor('int32', Int32Array.from([tokenId]), [1, 1]),
94
+ target_length: this.targetLength,
95
+ input_states_1: st.s1,
96
+ input_states_2: st.s2,
97
+ };
98
+ const r = await this.decoderJoint.run(feeds);
99
+ return {
100
+ logits: r['outputs'].data,
101
+ state: { s1: r['output_states_1'], s2: r['output_states_2'] },
102
+ };
103
+ }
104
+ /** Blank/padding token id, set by the model wrapper (vocabulary length). */
105
+ blankId = 0;
106
+ async dispose() {
107
+ await this.encoder.release?.();
108
+ await this.decoderJoint.release?.();
109
+ }
110
+ }
111
+ //# sourceMappingURL=backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.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I,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export { fromLocal } from './parakeet.js';
2
+ export type { OnnxModelOptions } from './parakeet.js';
3
+ export { OnnxBackend, defaultExecutionProvider } from './backend.js';
4
+ export type { OnnxBackendOptions, ExecutionProvider } from './backend.js';
5
+ export { ParakeetModel, StreamingParakeet, consumePcmStream, decodeTDTGreedy, decodeRNNTGreedy, getLogMel, loadAudioRaw, makePreprocessArgs, computeMelFilterbanks, computeMelFilterbanksInterpolated, tokensToSentences, sentencesToResult, decode, } from '../index.js';
6
+ export type { ParakeetBackend, EncoderOutput, TranscribeOptions, StreamOptions, DecoderState, PreprocessArgs, LogMel, AlignedToken, AlignedSentence, AlignedResult, SentenceConfig, } from '../index.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/onnx/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACrE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,iCAAiC,EACjC,iBAAiB,EACjB,iBAAiB,EACjB,MAAM,GACP,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,MAAM,EACN,YAAY,EACZ,eAAe,EACf,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ // parakeet.ts/onnx — ONNX Runtime backend (CUDA on Linux/Nvidia, CPU elsewhere)
2
+ export { fromLocal } from './parakeet.js';
3
+ export { OnnxBackend, defaultExecutionProvider } from './backend.js';
4
+ // Shared API, re-exported for convenience
5
+ export { ParakeetModel, StreamingParakeet, consumePcmStream, decodeTDTGreedy, decodeRNNTGreedy, getLogMel, loadAudioRaw, makePreprocessArgs, computeMelFilterbanks, computeMelFilterbanksInterpolated, tokensToSentences, sentencesToResult, decode, } from '../index.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/onnx/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAGrE,0CAA0C;AAC1C,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,iCAAiC,EACjC,iBAAiB,EACjB,iBAAiB,EACjB,MAAM,GACP,MAAM,aAAa,CAAC"}