transcribe-cpp 0.3.1 → 0.4.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/README.md CHANGED
@@ -109,10 +109,73 @@ const stream = await session.stream({ family: { kind: "moonshine" } });
109
109
  model.accepts({ kind: "whisper" }); // does this model take that extension?
110
110
  ```
111
111
 
112
+ ### Diarization (DIARIZE role)
113
+
114
+ `model.roles` lists what a model serves (`"asr"`, `"diarize"`, `"langid"`,
115
+ `"vad"`; Sortformer is diarize-only). Calls for a role the model lacks throw
116
+ `UnsupportedRole`.
117
+
118
+ ```ts
119
+ const { sampleRate, maxSpeakers } = model.diarizeInfo;
120
+ using diarizer = model.createDiarizeSession();
121
+ const turns = await diarizer.run(pcm, {
122
+ family: { kind: "sortformer_diarize", preset: "very_high_latency" },
123
+ });
124
+ for (const t of turns) console.log(t.speakerId, t.t0Ms, t.t1Ms);
125
+ ```
126
+
127
+ `run` accepts a `signal`; cancelling throws `Aborted` (with no partial result).
128
+ `diarizer.timings` reports the last run. Diarize runs wait on the same
129
+ model-wide lock as other compute calls (see below).
130
+
131
+ ### Language ID (LANGID role)
132
+
133
+ A `"langid"` model (VoxLingua107 ECAPA-TDNN) ranks its own label codes; match
134
+ `result.code` against an ASR model's `capabilities.languages` yourself.
135
+ Every allowed label is returned, ranked by `p`. Omitting `allowed` scores every
136
+ label, `[]` throws `InvalidArgument`, clips under `model.langidInfo.minAudioMs`
137
+ throw `InputTooShort`, and input longer than `maxAudioMs` is scored on its first `maxAudioMs`.
138
+
139
+ ```ts
140
+ using lid = model.createLangIdSession();
141
+ const result = await lid.run(pcm, { allowed: ["en", "de", "fr"] });
142
+ console.log(result.code, result.candidates[0].p, result.allowedMass);
143
+ ```
144
+
145
+ ### Voice activity detection (VAD role)
146
+
147
+ A `"vad"` model (Silero VAD) scores `model.vadInfo.frameSamples`-sample frames
148
+ (512 = 32 ms at 16 kHz) with a speech probability. `run` scores a whole clip
149
+ and segments it with Silero's `get_speech_timestamps` rules (options such as
150
+ `threshold`, `minSilenceMs` and `maxSpeechMs`; samples are 16 kHz indices):
151
+
152
+ ```ts
153
+ using vad = model.createVadSession();
154
+ const { segments, probs } = await vad.run(pcm, { threshold: 0.5 });
155
+ for (const s of segments) console.log(s.startSample, s.endSample);
156
+ ```
157
+
158
+ For live audio, `streamFeed(chunk)` returns the probabilities of the frames
159
+ each chunk completes (`firstFrame` is the index of `probs[0]`), `streamFlush()`
160
+ scores the zero-padded remainder and ends the stream, and `streamReset()` drops
161
+ it. The next feed after either starts at frame 0, as does the next feed after an
162
+ abort or processing error.
163
+
164
+ ```ts
165
+ for await (const chunk of mic) {
166
+ const { firstFrame, probs } = await vad.streamFeed(chunk);
167
+ probs.forEach((p, i) => console.log(firstFrame + i, p));
168
+ }
169
+ const tail = await vad.streamFlush();
170
+ ```
171
+
172
+ A VAD stream is session state, not a stream lease: VAD calls raise `Busy` only
173
+ while an ASR stream on the same model holds the lease.
174
+
112
175
  ### Resource management
113
176
 
114
- `TranscribeModel`, `Session`, and `Stream` all implement `Symbol.dispose`, so
115
- `using` works (TypeScript 5.2+ / Node 22+):
177
+ `TranscribeModel`, `Session`, `DiarizeSession`, `LangIdSession`, `VadSession`, and `Stream` all implement
178
+ `Symbol.dispose`, so `using` works (TypeScript 5.2+ / Node 22+):
116
179
 
117
180
  ```ts
118
181
  using model = await TranscribeModel.load("model.gguf");
@@ -123,13 +186,26 @@ using session = model.createSession();
123
186
  Disposing a model disposes its sessions; disposing a stream resets it (releasing
124
187
  the model lease). Disposal is idempotent and order-independent.
125
188
 
189
+ ## Startup and UI responsiveness
190
+
191
+ Initializing compute backends can take seconds (on Metal it compiles the GPU
192
+ shader library). `TranscribeModel.load()` does this on a worker thread, so the
193
+ event loop keeps running. To pay the cost up front, call `await initialize()`
194
+ at startup; `backendState()` reports its progress.
195
+
196
+ Use `getAvailableBackendsAsync()` / `backendAvailableAsync()` in UI processes.
197
+ The sync variants initialize backends on the calling thread if needed, and
198
+ throw `BackendInitializing` while `initialize()` is running. A failed backend
199
+ initialization is permanent for the process; later calls rethrow its
200
+ `BackendError`.
201
+
126
202
  ## Backend selection
127
203
 
128
204
  ```ts
129
- import { getAvailableBackends, backendAvailable } from "transcribe-cpp";
205
+ import { getAvailableBackendsAsync, backendAvailableAsync } from "transcribe-cpp";
130
206
 
131
- const devices = getAvailableBackends();
132
- backendAvailable("rocm"); // boolean — never throws
207
+ const devices = await getAvailableBackendsAsync();
208
+ await backendAvailableAsync("rocm"); // boolean
133
209
 
134
210
  // Policy selection: first matching ROCm device.
135
211
  const automatic = await TranscribeModel.load("model.gguf", { backend: "rocm" });
@@ -150,14 +226,14 @@ native compute to a **libuv worker thread** (via koffi's async calls), so the
150
226
  event loop stays responsive while inference runs.
151
227
 
152
228
  The C library allows **one compute in flight per model** — a `run`, a `runBatch`,
153
- or an *active stream* — across all of its sessions. The binding enforces this:
154
- every compute call serializes through an internal model-wide mutex, and an active
155
- stream holds a model-wide lease for its whole lifetime. While a stream is active
156
- (after `stream()`, before `finalize()`/`reset()`), a `run`/`runBatch`/`stream` on
157
- any session of that model is refused with a `Busy` error rather than allowed to
158
- race. So to parallelize, load one model per worker; to share a model, finalize or
159
- reset the stream first. A single `Session` is single-use-at-a-time — don't call
160
- `run`/`feed` on the same session concurrently.
229
+ a diarize `run`, or an *active stream* — across all of its sessions. The binding
230
+ enforces this: every compute call serializes through an internal model-wide
231
+ mutex, and an active stream holds a model-wide lease for its whole lifetime.
232
+ While a stream is active (after `stream()`, before `finalize()`/`reset()`), a
233
+ `run`/`runBatch`/`stream` on any session of that model is refused with a `Busy`
234
+ error rather than allowed to race. So to parallelize, load one model per worker;
235
+ to share a model, finalize or reset the stream first. A single `Session` is
236
+ single-use-at-a-time — don't call `run`/`feed` on the same session concurrently.
161
237
 
162
238
  Hand-offs are ordered, not racy: `finalize()`/`reset()`/`dispose()` release the
163
239
  lease only after the native teardown runs on the shared queue, so the slot is
@@ -166,20 +242,24 @@ is correctly serialized — `stream.reset(); const next = await session.stream()
166
242
  works without awaiting the (void) `reset()`. The reverse order — beginning before
167
243
  the teardown — is refused with `Busy`, by design.
168
244
 
245
+ A `feed()` rejected up front (e.g. NaN samples) leaves the stream `"active"` and
246
+ the lease held; a failure inside the model makes it `"failed"` and frees the lease.
247
+
169
248
  Because the compute is genuinely on another thread, **do not touch a session
170
249
  while a call against it is in flight** — it is single-threaded in the C library:
171
250
 
172
- - Reading a stream's `text`/`snapshot`/`state`/`revision`/`lastStatus`, or a
173
- session's `limits`/`wasAborted`, during an un-awaited
174
- `feed`/`finalize`/`run`/`runBatch` **throws**.
251
+ - Reading a stream's `text`/`snapshot`/`state`/`revision`/`lastStatus`, a
252
+ session's `limits`/`wasAborted`, or a `DiarizeSession`'s `timings`, during an
253
+ un-awaited `feed`/`finalize`/`run`/`runBatch` **throws**.
175
254
  - `reset()` and `dispose()` are safe to call any time: the native teardown is
176
255
  deferred behind any in-flight call, so it never frees a session mid-compute.
177
256
  - Disposing a `Session` or `TranscribeModel` while a stream is still active
178
257
  releases the lease and invalidates the stream — its later calls throw rather
179
258
  than touch the freed handle.
180
- - The **input PCM is borrowed, not copied**: `run`/`runBatch`/`feed` hand the
181
- buffer to native code that reads it on the worker thread, so do not mutate it
182
- (e.g. reuse a scratch/capture buffer) until the returned promise resolves.
259
+ - The **input PCM is borrowed, not copied**: `run`/`runBatch`/`feed` (and
260
+ `DiarizeSession.run`) hand the buffer to native code that reads it on the
261
+ worker thread, so do not mutate it (e.g. reuse a scratch/capture buffer)
262
+ until the returned promise resolves.
183
263
  Pass a fresh buffer per call, or `await` before overwriting.
184
264
 
185
265
  The normal pattern is safe — `await` first, then read:
@@ -284,4 +364,4 @@ to your `build.rs` as `DEP_TRANSCRIBE_CPP_RUNTIME_DIR`.
284
364
  ## License
285
365
 
286
366
  MIT. Bundled native packages include third-party license texts (ggml, miniz,
287
- and any bundled backend runtimes).
367
+ Silero VAD, and any bundled backend runtimes).
@@ -1,4 +1,4 @@
1
- export declare const PUBLIC_HEADER_HASH = "57b1af43650f195d";
1
+ export declare const PUBLIC_HEADER_HASH = "98540564cd329b85";
2
2
  export declare const TRANSCRIBE_OK = 0;
3
3
  export declare const TRANSCRIBE_ERR_INVALID_ARG = 1;
4
4
  export declare const TRANSCRIBE_ERR_NOT_IMPLEMENTED = 2;
@@ -19,6 +19,8 @@ export declare const TRANSCRIBE_ERR_UNSUPPORTED_ITN = 16;
19
19
  export declare const TRANSCRIBE_ERR_INPUT_TOO_LONG = 17;
20
20
  export declare const TRANSCRIBE_ERR_OUTPUT_TRUNCATED = 18;
21
21
  export declare const TRANSCRIBE_ERR_OUTPUT_REPETITION = 19;
22
+ export declare const TRANSCRIBE_ERR_UNSUPPORTED_ROLE = 20;
23
+ export declare const TRANSCRIBE_ERR_INPUT_TOO_SHORT = 21;
22
24
  export declare const TRANSCRIBE_ABI_MODEL_LOAD_PARAMS = 0;
23
25
  export declare const TRANSCRIBE_ABI_SESSION_PARAMS = 1;
24
26
  export declare const TRANSCRIBE_ABI_RUN_PARAMS = 2;
@@ -35,6 +37,19 @@ export declare const TRANSCRIBE_ABI_EXT = 12;
35
37
  export declare const TRANSCRIBE_ABI_DEVICE_INFO = 13;
36
38
  export declare const TRANSCRIBE_ABI_SPEAKER_SEGMENT = 14;
37
39
  export declare const TRANSCRIBE_ABI_BACKEND_INIT_PARAMS = 15;
40
+ export declare const TRANSCRIBE_ABI_DIARIZE_INFO = 16;
41
+ export declare const TRANSCRIBE_ABI_DIARIZE_SESSION_PARAMS = 17;
42
+ export declare const TRANSCRIBE_ABI_DIARIZE_PARAMS = 18;
43
+ export declare const TRANSCRIBE_ABI_LANGID_INFO = 19;
44
+ export declare const TRANSCRIBE_ABI_LANGID_SESSION_PARAMS = 20;
45
+ export declare const TRANSCRIBE_ABI_LANGID_PARAMS = 21;
46
+ export declare const TRANSCRIBE_ABI_LANGID_RESULT = 22;
47
+ export declare const TRANSCRIBE_ABI_LANGID_CANDIDATE = 23;
48
+ export declare const TRANSCRIBE_ABI_VAD_INFO = 24;
49
+ export declare const TRANSCRIBE_ABI_VAD_SESSION_PARAMS = 25;
50
+ export declare const TRANSCRIBE_ABI_VAD_PARAMS = 26;
51
+ export declare const TRANSCRIBE_ABI_VAD_RESULT = 27;
52
+ export declare const TRANSCRIBE_ABI_VAD_SEGMENT = 28;
38
53
  export declare const TRANSCRIBE_LOG_LEVEL_NONE = 0;
39
54
  export declare const TRANSCRIBE_LOG_LEVEL_INFO = 1;
40
55
  export declare const TRANSCRIBE_LOG_LEVEL_WARN = 2;
@@ -63,6 +78,7 @@ export declare const TRANSCRIBE_DIARIZE_MODE_OFF = 1;
63
78
  export declare const TRANSCRIBE_DIARIZE_MODE_ON = 2;
64
79
  export declare const TRANSCRIBE_EXT_SLOT_RUN = 0;
65
80
  export declare const TRANSCRIBE_EXT_SLOT_STREAM = 1;
81
+ export declare const TRANSCRIBE_EXT_SLOT_DIARIZE_RUN = 2;
66
82
  export declare const TRANSCRIBE_BACKEND_AUTO = 0;
67
83
  export declare const TRANSCRIBE_BACKEND_CPU = 1;
68
84
  export declare const TRANSCRIBE_BACKEND_METAL = 2;
@@ -74,6 +90,10 @@ export declare const TRANSCRIBE_DEVICE_TYPE_CPU = 0;
74
90
  export declare const TRANSCRIBE_DEVICE_TYPE_GPU = 1;
75
91
  export declare const TRANSCRIBE_DEVICE_TYPE_IGPU = 2;
76
92
  export declare const TRANSCRIBE_DEVICE_TYPE_ACCEL = 3;
93
+ export declare const TRANSCRIBE_ROLE_ASR = 1;
94
+ export declare const TRANSCRIBE_ROLE_DIARIZE = 2;
95
+ export declare const TRANSCRIBE_ROLE_LANGID = 4;
96
+ export declare const TRANSCRIBE_ROLE_VAD = 8;
77
97
  export declare const TRANSCRIBE_FEATURE_INITIAL_PROMPT = 0;
78
98
  export declare const TRANSCRIBE_FEATURE_TEMPERATURE_FALLBACK = 1;
79
99
  export declare const TRANSCRIBE_FEATURE_LONG_FORM = 2;
@@ -108,7 +128,7 @@ export declare const TRANSCRIBE_BACKEND_MASK_VULKAN = 4;
108
128
  export declare const TRANSCRIBE_EXT_KIND_MOONSHINE_STREAMING_STREAM = 1414746957;
109
129
  export declare const TRANSCRIBE_EXT_KIND_PARAKEET_BUFFERED_STREAM = 1396853584;
110
130
  export declare const TRANSCRIBE_EXT_KIND_PARAKEET_STREAM = 1414744912;
111
- export declare const TRANSCRIBE_EXT_KIND_SORTFORMER_STREAM = 1414743635;
131
+ export declare const TRANSCRIBE_EXT_KIND_SORTFORMER_DIARIZE = 1380206163;
112
132
  export declare const TRANSCRIBE_EXT_KIND_VOXTRAL_REALTIME_STREAM = 1414746710;
113
133
  export declare const TRANSCRIBE_EXT_KIND_WHISPER_RUN = 1314015319;
114
134
  export interface StructLayout {
@@ -10,7 +10,7 @@
10
10
  // Stable digest of the ABI surface (structs, enums, macros, layout,
11
11
  // prototypes), computed by the Python oracle and pinned here so a header
12
12
  // ABI change turns this binding's drift check red for conscious review.
13
- export const PUBLIC_HEADER_HASH = "57b1af43650f195d";
13
+ export const PUBLIC_HEADER_HASH = "98540564cd329b85";
14
14
  // === enum constants ===
15
15
  export const TRANSCRIBE_OK = 0;
16
16
  export const TRANSCRIBE_ERR_INVALID_ARG = 1;
@@ -32,6 +32,8 @@ export const TRANSCRIBE_ERR_UNSUPPORTED_ITN = 16;
32
32
  export const TRANSCRIBE_ERR_INPUT_TOO_LONG = 17;
33
33
  export const TRANSCRIBE_ERR_OUTPUT_TRUNCATED = 18;
34
34
  export const TRANSCRIBE_ERR_OUTPUT_REPETITION = 19;
35
+ export const TRANSCRIBE_ERR_UNSUPPORTED_ROLE = 20;
36
+ export const TRANSCRIBE_ERR_INPUT_TOO_SHORT = 21;
35
37
  export const TRANSCRIBE_ABI_MODEL_LOAD_PARAMS = 0;
36
38
  export const TRANSCRIBE_ABI_SESSION_PARAMS = 1;
37
39
  export const TRANSCRIBE_ABI_RUN_PARAMS = 2;
@@ -48,6 +50,19 @@ export const TRANSCRIBE_ABI_EXT = 12;
48
50
  export const TRANSCRIBE_ABI_DEVICE_INFO = 13;
49
51
  export const TRANSCRIBE_ABI_SPEAKER_SEGMENT = 14;
50
52
  export const TRANSCRIBE_ABI_BACKEND_INIT_PARAMS = 15;
53
+ export const TRANSCRIBE_ABI_DIARIZE_INFO = 16;
54
+ export const TRANSCRIBE_ABI_DIARIZE_SESSION_PARAMS = 17;
55
+ export const TRANSCRIBE_ABI_DIARIZE_PARAMS = 18;
56
+ export const TRANSCRIBE_ABI_LANGID_INFO = 19;
57
+ export const TRANSCRIBE_ABI_LANGID_SESSION_PARAMS = 20;
58
+ export const TRANSCRIBE_ABI_LANGID_PARAMS = 21;
59
+ export const TRANSCRIBE_ABI_LANGID_RESULT = 22;
60
+ export const TRANSCRIBE_ABI_LANGID_CANDIDATE = 23;
61
+ export const TRANSCRIBE_ABI_VAD_INFO = 24;
62
+ export const TRANSCRIBE_ABI_VAD_SESSION_PARAMS = 25;
63
+ export const TRANSCRIBE_ABI_VAD_PARAMS = 26;
64
+ export const TRANSCRIBE_ABI_VAD_RESULT = 27;
65
+ export const TRANSCRIBE_ABI_VAD_SEGMENT = 28;
51
66
  export const TRANSCRIBE_LOG_LEVEL_NONE = 0;
52
67
  export const TRANSCRIBE_LOG_LEVEL_INFO = 1;
53
68
  export const TRANSCRIBE_LOG_LEVEL_WARN = 2;
@@ -76,6 +91,7 @@ export const TRANSCRIBE_DIARIZE_MODE_OFF = 1;
76
91
  export const TRANSCRIBE_DIARIZE_MODE_ON = 2;
77
92
  export const TRANSCRIBE_EXT_SLOT_RUN = 0;
78
93
  export const TRANSCRIBE_EXT_SLOT_STREAM = 1;
94
+ export const TRANSCRIBE_EXT_SLOT_DIARIZE_RUN = 2;
79
95
  export const TRANSCRIBE_BACKEND_AUTO = 0;
80
96
  export const TRANSCRIBE_BACKEND_CPU = 1;
81
97
  export const TRANSCRIBE_BACKEND_METAL = 2;
@@ -87,6 +103,10 @@ export const TRANSCRIBE_DEVICE_TYPE_CPU = 0;
87
103
  export const TRANSCRIBE_DEVICE_TYPE_GPU = 1;
88
104
  export const TRANSCRIBE_DEVICE_TYPE_IGPU = 2;
89
105
  export const TRANSCRIBE_DEVICE_TYPE_ACCEL = 3;
106
+ export const TRANSCRIBE_ROLE_ASR = 1;
107
+ export const TRANSCRIBE_ROLE_DIARIZE = 2;
108
+ export const TRANSCRIBE_ROLE_LANGID = 4;
109
+ export const TRANSCRIBE_ROLE_VAD = 8;
90
110
  export const TRANSCRIBE_FEATURE_INITIAL_PROMPT = 0;
91
111
  export const TRANSCRIBE_FEATURE_TEMPERATURE_FALLBACK = 1;
92
112
  export const TRANSCRIBE_FEATURE_LONG_FORM = 2;
@@ -122,7 +142,7 @@ export const TRANSCRIBE_BACKEND_MASK_VULKAN = 4;
122
142
  export const TRANSCRIBE_EXT_KIND_MOONSHINE_STREAMING_STREAM = 1414746957;
123
143
  export const TRANSCRIBE_EXT_KIND_PARAKEET_BUFFERED_STREAM = 1396853584;
124
144
  export const TRANSCRIBE_EXT_KIND_PARAKEET_STREAM = 1414744912;
125
- export const TRANSCRIBE_EXT_KIND_SORTFORMER_STREAM = 1414743635;
145
+ export const TRANSCRIBE_EXT_KIND_SORTFORMER_DIARIZE = 1380206163;
126
146
  export const TRANSCRIBE_EXT_KIND_VOXTRAL_REALTIME_STREAM = 1414746710;
127
147
  export const TRANSCRIBE_EXT_KIND_WHISPER_RUN = 1314015319;
128
148
  export const STRUCT_LAYOUT = {
@@ -142,10 +162,23 @@ export const STRUCT_LAYOUT = {
142
162
  'transcribe_word': { size: 48, align: 8, offsets: { 'struct_size': 0, 't0_ms': 8, 't1_ms': 16, 'seg_index': 24, 'first_token': 28, 'n_tokens': 32, 'text': 40 } },
143
163
  'transcribe_token': { size: 48, align: 8, offsets: { 'struct_size': 0, 'id': 8, 'p': 12, 't0_ms': 16, 't1_ms': 24, 'seg_index': 32, 'word_index': 36, 'text': 40 } },
144
164
  'transcribe_speaker_segment': { size: 32, align: 8, offsets: { 'struct_size': 0, 't0_ms': 8, 't1_ms': 16, 'speaker_id': 24, 'p': 28 } },
165
+ 'transcribe_diarize_info': { size: 16, align: 8, offsets: { 'struct_size': 0, 'sample_rate': 8, 'max_speakers': 12 } },
166
+ 'transcribe_diarize_session_params': { size: 16, align: 8, offsets: { 'struct_size': 0, 'n_threads': 8 } },
167
+ 'transcribe_diarize_params': { size: 16, align: 8, offsets: { 'struct_size': 0, 'family': 8 } },
168
+ 'transcribe_langid_info': { size: 24, align: 8, offsets: { 'struct_size': 0, 'sample_rate': 8, 'n_labels': 12, 'min_audio_ms': 16, 'max_audio_ms': 20 } },
169
+ 'transcribe_langid_session_params': { size: 16, align: 8, offsets: { 'struct_size': 0, 'n_threads': 8 } },
170
+ 'transcribe_langid_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'allowed': 8, 'n_allowed': 16 } },
171
+ 'transcribe_langid_result': { size: 16, align: 8, offsets: { 'struct_size': 0, 'n_candidates': 8, 'allowed_mass': 12 } },
172
+ 'transcribe_langid_candidate': { size: 40, align: 8, offsets: { 'struct_size': 0, 'index': 8, 'code': 16, 'name': 24, 'p': 32, 'logit': 36 } },
145
173
  'transcribe_moonshine_streaming_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'min_decode_interval_ms': 16 } },
146
174
  'transcribe_parakeet_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'att_context_right': 16 } },
147
175
  'transcribe_parakeet_buffered_stream_ext': { size: 32, align: 8, offsets: { 'ext': 0, 'left_ms': 16, 'chunk_ms': 20, 'right_ms': 24 } },
148
- 'transcribe_sortformer_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'preset': 16 } },
176
+ 'transcribe_sortformer_diarize_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'preset': 16 } },
177
+ 'transcribe_vad_info': { size: 16, align: 8, offsets: { 'struct_size': 0, 'sample_rate': 8, 'frame_samples': 12 } },
178
+ 'transcribe_vad_session_params': { size: 16, align: 8, offsets: { 'struct_size': 0, 'n_threads': 8 } },
179
+ 'transcribe_vad_params': { size: 40, align: 8, offsets: { 'struct_size': 0, 'threshold': 8, 'neg_threshold': 16, 'min_speech_ms': 24, 'min_silence_ms': 28, 'speech_pad_ms': 32, 'max_speech_ms': 36 } },
180
+ 'transcribe_vad_result': { size: 32, align: 8, offsets: { 'struct_size': 0, 'n_probs': 8, 'first_frame': 16, 'n_segments': 24 } },
181
+ 'transcribe_vad_segment': { size: 24, align: 8, offsets: { 'struct_size': 0, 'start_sample': 8, 'end_sample': 16 } },
149
182
  'transcribe_voxtral_realtime_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'num_delay_tokens': 16, 'min_decode_interval_ms': 20 } },
150
183
  'transcribe_whisper_run_ext': { size: 80, align: 8, offsets: { 'ext': 0, 'initial_prompt': 16, 'prompt_tokens': 24, 'n_prompt_tokens': 32, 'prompt_condition': 40, 'condition_on_prev_tokens': 44, 'max_prev_context_tokens': 48, 'temperature': 52, 'temperature_inc': 56, 'compression_ratio_thold': 60, 'logprob_thold': 64, 'no_speech_thold': 68, 'seed': 72, 'max_initial_timestamp': 76 } },
151
184
  'transcribe_whisper_chunk_trace': { size: 48, align: 8, offsets: { 'struct_size': 0, 't0_ms': 8, 't1_ms': 16, 'temperature_used': 24, 'compression_ratio': 28, 'avg_logprob': 32, 'no_speech_prob': 36, 'no_speech_triggered': 40, 'n_fallbacks': 44 } },
@@ -167,6 +200,19 @@ export const ABI_STRUCT_IDS = {
167
200
  'transcribe_word': 7,
168
201
  'transcribe_token': 8,
169
202
  'transcribe_speaker_segment': 14,
203
+ 'transcribe_diarize_info': 16,
204
+ 'transcribe_diarize_session_params': 17,
205
+ 'transcribe_diarize_params': 18,
206
+ 'transcribe_langid_info': 19,
207
+ 'transcribe_langid_session_params': 20,
208
+ 'transcribe_langid_params': 21,
209
+ 'transcribe_langid_result': 22,
210
+ 'transcribe_langid_candidate': 23,
211
+ 'transcribe_vad_info': 24,
212
+ 'transcribe_vad_session_params': 25,
213
+ 'transcribe_vad_params': 26,
214
+ 'transcribe_vad_result': 27,
215
+ 'transcribe_vad_segment': 28,
170
216
  };
171
217
  // Build koffi struct types; returns a name -> koffi.IKoffiCType map.
172
218
  export function defineTypes(koffi) {
@@ -187,10 +233,23 @@ export function defineTypes(koffi) {
187
233
  T['transcribe_word'] = koffi.struct({ struct_size: 'uint64_t', t0_ms: 'int64_t', t1_ms: 'int64_t', seg_index: 'int', first_token: 'int', n_tokens: 'int', text: 'char *' });
188
234
  T['transcribe_token'] = koffi.struct({ struct_size: 'uint64_t', id: 'int', p: 'float', t0_ms: 'int64_t', t1_ms: 'int64_t', seg_index: 'int', word_index: 'int', text: 'char *' });
189
235
  T['transcribe_speaker_segment'] = koffi.struct({ struct_size: 'uint64_t', t0_ms: 'int64_t', t1_ms: 'int64_t', speaker_id: 'int32_t', p: 'float' });
236
+ T['transcribe_diarize_info'] = koffi.struct({ struct_size: 'uint64_t', sample_rate: 'int32_t', max_speakers: 'int32_t' });
237
+ T['transcribe_diarize_session_params'] = koffi.struct({ struct_size: 'uint64_t', n_threads: 'int32_t' });
238
+ T['transcribe_diarize_params'] = koffi.struct({ struct_size: 'uint64_t', family: 'void *' });
239
+ T['transcribe_langid_info'] = koffi.struct({ struct_size: 'uint64_t', sample_rate: 'int32_t', n_labels: 'int32_t', min_audio_ms: 'int32_t', max_audio_ms: 'int32_t' });
240
+ T['transcribe_langid_session_params'] = koffi.struct({ struct_size: 'uint64_t', n_threads: 'int32_t' });
241
+ T['transcribe_langid_params'] = koffi.struct({ struct_size: 'uint64_t', allowed: 'void *', n_allowed: 'int32_t' });
242
+ T['transcribe_langid_result'] = koffi.struct({ struct_size: 'uint64_t', n_candidates: 'int32_t', allowed_mass: 'float' });
243
+ T['transcribe_langid_candidate'] = koffi.struct({ struct_size: 'uint64_t', index: 'int32_t', code: 'char *', name: 'char *', p: 'float', logit: 'float' });
190
244
  T['transcribe_moonshine_streaming_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], min_decode_interval_ms: 'int32_t' });
191
245
  T['transcribe_parakeet_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], att_context_right: 'int32_t' });
192
246
  T['transcribe_parakeet_buffered_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], left_ms: 'int32_t', chunk_ms: 'int32_t', right_ms: 'int32_t' });
193
- T['transcribe_sortformer_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], preset: 'int' });
247
+ T['transcribe_sortformer_diarize_ext'] = koffi.struct({ ext: T['transcribe_ext'], preset: 'int' });
248
+ T['transcribe_vad_info'] = koffi.struct({ struct_size: 'uint64_t', sample_rate: 'int32_t', frame_samples: 'int32_t' });
249
+ T['transcribe_vad_session_params'] = koffi.struct({ struct_size: 'uint64_t', n_threads: 'int32_t' });
250
+ T['transcribe_vad_params'] = koffi.struct({ struct_size: 'uint64_t', threshold: 'double', neg_threshold: 'double', min_speech_ms: 'int32_t', min_silence_ms: 'int32_t', speech_pad_ms: 'int32_t', max_speech_ms: 'int32_t' });
251
+ T['transcribe_vad_result'] = koffi.struct({ struct_size: 'uint64_t', n_probs: 'int32_t', first_frame: 'int64_t', n_segments: 'int32_t' });
252
+ T['transcribe_vad_segment'] = koffi.struct({ struct_size: 'uint64_t', start_sample: 'int64_t', end_sample: 'int64_t' });
194
253
  T['transcribe_voxtral_realtime_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], num_delay_tokens: 'int32_t', min_decode_interval_ms: 'int32_t' });
195
254
  T['transcribe_whisper_run_ext'] = koffi.struct({ ext: T['transcribe_ext'], initial_prompt: 'char *', prompt_tokens: 'void *', n_prompt_tokens: 'size_t', prompt_condition: 'int', condition_on_prev_tokens: 'bool', max_prev_context_tokens: 'int32_t', temperature: 'float', temperature_inc: 'float', compression_ratio_thold: 'float', logprob_thold: 'float', no_speech_thold: 'float', seed: 'uint32_t', max_initial_timestamp: 'float' });
196
255
  T['transcribe_whisper_chunk_trace'] = koffi.struct({ struct_size: 'uint64_t', t0_ms: 'int64_t', t1_ms: 'int64_t', temperature_used: 'float', compression_ratio: 'float', avg_logprob: 'float', no_speech_prob: 'float', no_speech_triggered: 'bool', n_fallbacks: 'int32_t' });
@@ -224,6 +283,17 @@ export const FUNCTION_SIGNATURES = {
224
283
  'transcribe_device_get': { ret: 'transcribe_device_t', args: ['int'] },
225
284
  'transcribe_device_get_info': { ret: 'transcribe_status', args: ['transcribe_device_t', 'struct transcribe_device_info *'] },
226
285
  'transcribe_device_info_init': { ret: 'void', args: ['struct transcribe_device_info *'] },
286
+ 'transcribe_diarize_get_info': { ret: 'transcribe_status', args: ['const struct transcribe_model *', 'struct transcribe_diarize_info *'] },
287
+ 'transcribe_diarize_get_segment': { ret: 'transcribe_status', args: ['const struct transcribe_diarize_session *', 'int', 'struct transcribe_speaker_segment *'] },
288
+ 'transcribe_diarize_get_timings': { ret: 'transcribe_status', args: ['const struct transcribe_diarize_session *', 'struct transcribe_timings *'] },
289
+ 'transcribe_diarize_info_init': { ret: 'void', args: ['struct transcribe_diarize_info *'] },
290
+ 'transcribe_diarize_n_segments': { ret: 'int', args: ['const struct transcribe_diarize_session *'] },
291
+ 'transcribe_diarize_params_init': { ret: 'void', args: ['struct transcribe_diarize_params *'] },
292
+ 'transcribe_diarize_run': { ret: 'transcribe_status', args: ['struct transcribe_diarize_session *', 'const float *', 'int', 'const struct transcribe_diarize_params *'] },
293
+ 'transcribe_diarize_session_free': { ret: 'void', args: ['struct transcribe_diarize_session *'] },
294
+ 'transcribe_diarize_session_init': { ret: 'transcribe_status', args: ['struct transcribe_model *', 'const struct transcribe_diarize_session_params *', 'struct transcribe_diarize_session **'] },
295
+ 'transcribe_diarize_session_params_init': { ret: 'void', args: ['struct transcribe_diarize_session_params *'] },
296
+ 'transcribe_diarize_set_abort_callback': { ret: 'void', args: ['struct transcribe_diarize_session *', 'transcribe_abort_callback', 'void *'] },
227
297
  'transcribe_ext_check': { ret: 'transcribe_status', args: ['const struct transcribe_ext *', 'uint32_t', 'uint64_t'] },
228
298
  'transcribe_full_text': { ret: 'const char *', args: ['const struct transcribe_session *'] },
229
299
  'transcribe_get_model': { ret: 'const struct transcribe_model *', args: ['const struct transcribe_session *'] },
@@ -237,6 +307,22 @@ export const FUNCTION_SIGNATURES = {
237
307
  'transcribe_init_backends': { ret: 'transcribe_status', args: ['const char *'] },
238
308
  'transcribe_init_backends_default': { ret: 'transcribe_status', args: [] },
239
309
  'transcribe_init_backends_ex': { ret: 'transcribe_status', args: ['const struct transcribe_backend_init_params *'] },
310
+ 'transcribe_langid_candidate_init': { ret: 'void', args: ['struct transcribe_langid_candidate *'] },
311
+ 'transcribe_langid_get_candidate': { ret: 'transcribe_status', args: ['const struct transcribe_langid_session *', 'int', 'struct transcribe_langid_candidate *'] },
312
+ 'transcribe_langid_get_info': { ret: 'transcribe_status', args: ['const struct transcribe_model *', 'struct transcribe_langid_info *'] },
313
+ 'transcribe_langid_get_result': { ret: 'transcribe_status', args: ['const struct transcribe_langid_session *', 'struct transcribe_langid_result *'] },
314
+ 'transcribe_langid_get_timings': { ret: 'transcribe_status', args: ['const struct transcribe_langid_session *', 'struct transcribe_timings *'] },
315
+ 'transcribe_langid_info_init': { ret: 'void', args: ['struct transcribe_langid_info *'] },
316
+ 'transcribe_langid_label_code': { ret: 'const char *', args: ['const struct transcribe_model *', 'int32_t'] },
317
+ 'transcribe_langid_label_index': { ret: 'int32_t', args: ['const struct transcribe_model *', 'const char *'] },
318
+ 'transcribe_langid_label_name': { ret: 'const char *', args: ['const struct transcribe_model *', 'int32_t'] },
319
+ 'transcribe_langid_params_init': { ret: 'void', args: ['struct transcribe_langid_params *'] },
320
+ 'transcribe_langid_result_init': { ret: 'void', args: ['struct transcribe_langid_result *'] },
321
+ 'transcribe_langid_run': { ret: 'transcribe_status', args: ['struct transcribe_langid_session *', 'const float *', 'int', 'const struct transcribe_langid_params *'] },
322
+ 'transcribe_langid_session_free': { ret: 'void', args: ['struct transcribe_langid_session *'] },
323
+ 'transcribe_langid_session_init': { ret: 'transcribe_status', args: ['struct transcribe_model *', 'const struct transcribe_langid_session_params *', 'struct transcribe_langid_session **'] },
324
+ 'transcribe_langid_session_params_init': { ret: 'void', args: ['struct transcribe_langid_session_params *'] },
325
+ 'transcribe_langid_set_abort_callback': { ret: 'void', args: ['struct transcribe_langid_session *', 'transcribe_abort_callback', 'void *'] },
240
326
  'transcribe_log_set': { ret: 'void', args: ['transcribe_log_callback', 'void *'] },
241
327
  'transcribe_model_accepts_ext_kind': { ret: '_Bool', args: ['const struct transcribe_model *', 'transcribe_ext_slot', 'uint32_t'] },
242
328
  'transcribe_model_arch_string': { ret: 'const char *', args: ['const struct transcribe_model *'] },
@@ -247,6 +333,7 @@ export const FUNCTION_SIGNATURES = {
247
333
  'transcribe_model_load_file': { ret: 'transcribe_status', args: ['const char *', 'const struct transcribe_model_load_params *', 'struct transcribe_model **'] },
248
334
  'transcribe_model_load_params_init': { ret: 'void', args: ['struct transcribe_model_load_params *'] },
249
335
  'transcribe_model_meta_val_str': { ret: 'const char *', args: ['const struct transcribe_model *', 'const char *'] },
336
+ 'transcribe_model_roles': { ret: 'uint32_t', args: ['const struct transcribe_model *'] },
250
337
  'transcribe_model_supports': { ret: '_Bool', args: ['const struct transcribe_model *', 'transcribe_feature'] },
251
338
  'transcribe_model_variant_string': { ret: 'const char *', args: ['const struct transcribe_model *'] },
252
339
  'transcribe_moonshine_streaming_stream_ext_init': { ret: 'void', args: ['struct transcribe_moonshine_streaming_stream_ext *'] },
@@ -271,7 +358,7 @@ export const FUNCTION_SIGNATURES = {
271
358
  'transcribe_session_limits_init': { ret: 'void', args: ['struct transcribe_session_limits *'] },
272
359
  'transcribe_session_params_init': { ret: 'void', args: ['struct transcribe_session_params *'] },
273
360
  'transcribe_set_abort_callback': { ret: 'void', args: ['struct transcribe_session *', 'transcribe_abort_callback', 'void *'] },
274
- 'transcribe_sortformer_stream_ext_init': { ret: 'void', args: ['struct transcribe_sortformer_stream_ext *'] },
361
+ 'transcribe_sortformer_diarize_ext_init': { ret: 'void', args: ['struct transcribe_sortformer_diarize_ext *'] },
275
362
  'transcribe_speaker_segment_init': { ret: 'void', args: ['struct transcribe_speaker_segment *'] },
276
363
  'transcribe_status_string': { ret: 'const char *', args: ['int'] },
277
364
  'transcribe_stream_begin': { ret: 'transcribe_status', args: ['struct transcribe_session *', 'const struct transcribe_run_params *', 'const struct transcribe_stream_params *'] },
@@ -291,6 +378,23 @@ export const FUNCTION_SIGNATURES = {
291
378
  'transcribe_timings_init': { ret: 'void', args: ['struct transcribe_timings *'] },
292
379
  'transcribe_token_init': { ret: 'void', args: ['struct transcribe_token *'] },
293
380
  'transcribe_tokenize': { ret: 'int', args: ['const struct transcribe_model *', 'const char *', 'int32_t *', 'size_t'] },
381
+ 'transcribe_vad_get_info': { ret: 'transcribe_status', args: ['const struct transcribe_model *', 'struct transcribe_vad_info *'] },
382
+ 'transcribe_vad_get_result': { ret: 'transcribe_status', args: ['const struct transcribe_vad_session *', 'struct transcribe_vad_result *'] },
383
+ 'transcribe_vad_get_segment': { ret: 'transcribe_status', args: ['const struct transcribe_vad_session *', 'int', 'struct transcribe_vad_segment *'] },
384
+ 'transcribe_vad_get_timings': { ret: 'transcribe_status', args: ['const struct transcribe_vad_session *', 'struct transcribe_timings *'] },
385
+ 'transcribe_vad_info_init': { ret: 'void', args: ['struct transcribe_vad_info *'] },
386
+ 'transcribe_vad_params_init': { ret: 'void', args: ['struct transcribe_vad_params *'] },
387
+ 'transcribe_vad_probs': { ret: 'const float *', args: ['const struct transcribe_vad_session *'] },
388
+ 'transcribe_vad_result_init': { ret: 'void', args: ['struct transcribe_vad_result *'] },
389
+ 'transcribe_vad_run': { ret: 'transcribe_status', args: ['struct transcribe_vad_session *', 'const float *', 'int', 'const struct transcribe_vad_params *'] },
390
+ 'transcribe_vad_segment_init': { ret: 'void', args: ['struct transcribe_vad_segment *'] },
391
+ 'transcribe_vad_session_free': { ret: 'void', args: ['struct transcribe_vad_session *'] },
392
+ 'transcribe_vad_session_init': { ret: 'transcribe_status', args: ['struct transcribe_model *', 'const struct transcribe_vad_session_params *', 'struct transcribe_vad_session **'] },
393
+ 'transcribe_vad_session_params_init': { ret: 'void', args: ['struct transcribe_vad_session_params *'] },
394
+ 'transcribe_vad_set_abort_callback': { ret: 'void', args: ['struct transcribe_vad_session *', 'transcribe_abort_callback', 'void *'] },
395
+ 'transcribe_vad_stream_feed': { ret: 'transcribe_status', args: ['struct transcribe_vad_session *', 'const float *', 'int'] },
396
+ 'transcribe_vad_stream_flush': { ret: 'transcribe_status', args: ['struct transcribe_vad_session *'] },
397
+ 'transcribe_vad_stream_reset': { ret: 'void', args: ['struct transcribe_vad_session *'] },
294
398
  'transcribe_version': { ret: 'const char *', args: [] },
295
399
  'transcribe_version_commit': { ret: 'const char *', args: [] },
296
400
  'transcribe_voxtral_realtime_stream_ext_init': { ret: 'void', args: ['struct transcribe_voxtral_realtime_stream_ext *'] },
package/dist/errors.d.ts CHANGED
@@ -35,8 +35,20 @@ export declare class AbiError extends TranscribeError {
35
35
  }
36
36
  export declare class InputTooLong extends TranscribeError {
37
37
  }
38
+ /** Raised when the audio is shorter than the role's minimum (e.g. language ID's minAudioMs). */
39
+ export declare class InputTooShort extends TranscribeError {
40
+ }
38
41
  export declare class VersionMismatch extends TranscribeError {
39
42
  }
43
+ /**
44
+ * Raised by a synchronous backend query while `initialize()` is still running
45
+ * (waiting could deadlock). Binding-side error, so `status` is 0.
46
+ */
47
+ export declare class BackendInitializing extends TranscribeError {
48
+ }
49
+ /** Raised when the model does not serve the role (ASR, diarize, langid, vad) the call needs. */
50
+ export declare class UnsupportedRole extends TranscribeError {
51
+ }
40
52
  /** Raised when a run is cancelled; carries any partial transcript in `partialResult`. */
41
53
  export declare class Aborted extends TranscribeError {
42
54
  }
package/dist/errors.js CHANGED
@@ -39,8 +39,20 @@ export class AbiError extends TranscribeError {
39
39
  }
40
40
  export class InputTooLong extends TranscribeError {
41
41
  }
42
+ /** Raised when the audio is shorter than the role's minimum (e.g. language ID's minAudioMs). */
43
+ export class InputTooShort extends TranscribeError {
44
+ }
42
45
  export class VersionMismatch extends TranscribeError {
43
46
  }
47
+ /**
48
+ * Raised by a synchronous backend query while `initialize()` is still running
49
+ * (waiting could deadlock). Binding-side error, so `status` is 0.
50
+ */
51
+ export class BackendInitializing extends TranscribeError {
52
+ }
53
+ /** Raised when the model does not serve the role (ASR, diarize, langid, vad) the call needs. */
54
+ export class UnsupportedRole extends TranscribeError {
55
+ }
44
56
  /** Raised when a run is cancelled; carries any partial transcript in `partialResult`. */
45
57
  export class Aborted extends TranscribeError {
46
58
  }
@@ -74,6 +86,8 @@ const STATUS_TO_EXC = {
74
86
  [g.TRANSCRIBE_ERR_INPUT_TOO_LONG]: InputTooLong,
75
87
  [g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED]: OutputTruncated,
76
88
  [g.TRANSCRIBE_ERR_OUTPUT_REPETITION]: OutputRepetition,
89
+ [g.TRANSCRIBE_ERR_UNSUPPORTED_ROLE]: UnsupportedRole,
90
+ [g.TRANSCRIBE_ERR_INPUT_TOO_SHORT]: InputTooShort,
77
91
  };
78
92
  /** Build (do not throw) the mapped exception for a status. */
79
93
  export function exceptionForStatus(status, statusString, context = "") {