transcribe-cpp 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -20
- package/dist/_generated.d.ts +22 -2
- package/dist/_generated.js +111 -7
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +14 -0
- package/dist/ffi.js +144 -2
- package/dist/index.d.ts +96 -3
- package/dist/index.js +628 -206
- package/dist/native.d.ts +40 -7
- package/dist/native.js +155 -23
- package/dist/types.d.ts +121 -6
- package/package.json +6 -6
package/dist/native.d.ts
CHANGED
|
@@ -1,24 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Native bootstrap
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Native bootstrap, in two phases:
|
|
3
|
+
*
|
|
4
|
+
* 1. `loadLibrary()`: resolve -> (CUDA runtime preload) -> dlopen -> bind ->
|
|
5
|
+
* verify ABI -> version-gate -> install the log callback. Synchronous but
|
|
6
|
+
* GPU-free. Memoized on success; a failure is not cached.
|
|
7
|
+
*
|
|
8
|
+
* 2. Backend initialization: `transcribe_init_backends` builds the ggml
|
|
9
|
+
* backend registry, running each device's bootstrap (on Metal, the shader
|
|
10
|
+
* library compile, which can take seconds). `initialize()` runs it on a
|
|
11
|
+
* koffi async worker; concurrent callers share one attempt. A non-OK
|
|
12
|
+
* status is cached as `failed`: the C library documents it as not
|
|
13
|
+
* retryable in this process.
|
|
14
|
+
*
|
|
15
|
+
* Synchronous entry points that touch the registry go through `nativeReady()`.
|
|
16
|
+
* It initializes inline when uninitialized (blocking the caller, the pre-async
|
|
17
|
+
* behavior) and throws BackendInitializing while an async init is in flight.
|
|
18
|
+
* It must not wait for that init: the worker may be blocked delivering a log
|
|
19
|
+
* message to this (main) thread, so waiting would deadlock.
|
|
5
20
|
*/
|
|
6
21
|
import { type Bound } from "./ffi.js";
|
|
7
22
|
export interface Native extends Bound {
|
|
8
23
|
libraryPath: string;
|
|
9
24
|
provider: string | null;
|
|
25
|
+
/** Directory scanned for backend modules by `transcribe_init_backends`. */
|
|
26
|
+
artifactDir: string;
|
|
10
27
|
abortProto: any;
|
|
11
28
|
logProto: any;
|
|
12
29
|
}
|
|
30
|
+
/** Lifecycle of the process-wide backend initialization. */
|
|
31
|
+
export type BackendState = "uninitialized" | "initializing" | "ready" | "failed";
|
|
13
32
|
export type LogHandler = (level: number, message: string) => void;
|
|
14
|
-
|
|
33
|
+
/** Load and verify the native library without initializing any backend. */
|
|
34
|
+
export declare function loadLibrary(): Native;
|
|
35
|
+
export declare function callAsync<T = number>(fn: any, ...args: any[]): Promise<T>;
|
|
36
|
+
/** The current backend initialization state. Never loads or initializes anything. */
|
|
37
|
+
export declare function backendState(): BackendState;
|
|
38
|
+
/**
|
|
39
|
+
* Load the native library and initialize compute backends off the event loop.
|
|
40
|
+
* Idempotent; concurrent calls share one attempt. A backend init failure is
|
|
41
|
+
* permanent for the process; a library-load failure is not cached.
|
|
42
|
+
*/
|
|
43
|
+
export declare function initialize(): Promise<void>;
|
|
44
|
+
/** Initialize (or join the in-flight init) and return the binding. */
|
|
45
|
+
export declare function nativeAsync(): Promise<Native>;
|
|
46
|
+
/** The binding with backends ready, for synchronous entry points. See module docs. */
|
|
47
|
+
export declare function nativeReady(): Native;
|
|
15
48
|
/**
|
|
16
49
|
* Route native (and ggml) diagnostics to `handler`, or pass null to disable.
|
|
17
50
|
* The callback may fire from ggml worker threads; koffi marshals it to the
|
|
18
|
-
* event-loop thread
|
|
19
|
-
*
|
|
51
|
+
* event-loop thread, so the handler runs on the main thread. Exceptions thrown
|
|
52
|
+
* by the handler are swallowed (never re-enter C).
|
|
20
53
|
*
|
|
21
|
-
* The native callback is installed once
|
|
54
|
+
* The native callback is installed once when the library loads, before backend
|
|
22
55
|
* initialization. Later calls only swap this JS handler; they never call
|
|
23
56
|
* transcribe_log_set again.
|
|
24
57
|
*/
|
package/dist/native.js
CHANGED
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Native bootstrap
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Native bootstrap, in two phases:
|
|
3
|
+
*
|
|
4
|
+
* 1. `loadLibrary()`: resolve -> (CUDA runtime preload) -> dlopen -> bind ->
|
|
5
|
+
* verify ABI -> version-gate -> install the log callback. Synchronous but
|
|
6
|
+
* GPU-free. Memoized on success; a failure is not cached.
|
|
7
|
+
*
|
|
8
|
+
* 2. Backend initialization: `transcribe_init_backends` builds the ggml
|
|
9
|
+
* backend registry, running each device's bootstrap (on Metal, the shader
|
|
10
|
+
* library compile, which can take seconds). `initialize()` runs it on a
|
|
11
|
+
* koffi async worker; concurrent callers share one attempt. A non-OK
|
|
12
|
+
* status is cached as `failed`: the C library documents it as not
|
|
13
|
+
* retryable in this process.
|
|
14
|
+
*
|
|
15
|
+
* Synchronous entry points that touch the registry go through `nativeReady()`.
|
|
16
|
+
* It initializes inline when uninitialized (blocking the caller, the pre-async
|
|
17
|
+
* behavior) and throws BackendInitializing while an async init is in flight.
|
|
18
|
+
* It must not wait for that init: the worker may be blocked delivering a log
|
|
19
|
+
* message to this (main) thread, so waiting would deadlock.
|
|
5
20
|
*/
|
|
6
21
|
import { resolveLibrary } from "./loader.js";
|
|
7
22
|
import { preloadCudaRuntime } from "./cuda.js";
|
|
8
23
|
import { abortProto, bindLibrary, logProto } from "./ffi.js";
|
|
9
24
|
import { verifyLayouts } from "./abi.js";
|
|
10
|
-
import { BackendError, VersionMismatch } from "./errors.js";
|
|
25
|
+
import { BackendError, BackendInitializing, VersionMismatch } from "./errors.js";
|
|
11
26
|
import { OUR_VERSION, baseVersion } from "./version.js";
|
|
12
27
|
import * as g from "./_generated.js";
|
|
13
|
-
let
|
|
28
|
+
let lib = null;
|
|
29
|
+
let state = "uninitialized";
|
|
30
|
+
let initPromise = null; // set while an async init is in flight
|
|
31
|
+
let initError = null; // the cached bootstrap failure
|
|
14
32
|
let logHandler = null;
|
|
15
33
|
let logRegistered = null;
|
|
34
|
+
// Registered once and never unregistered or re-installed: native code (including
|
|
35
|
+
// an in-flight backend init on a worker) may hold the pointer at any time. Only
|
|
36
|
+
// the JS target (`logHandler`) ever changes.
|
|
16
37
|
function ensureLogCallback(bound) {
|
|
17
38
|
if (logRegistered)
|
|
18
39
|
return;
|
|
@@ -30,14 +51,18 @@ function ensureLogCallback(bound) {
|
|
|
30
51
|
logRegistered = bound.koffi.register(thunk, bound.koffi.pointer(logProto()));
|
|
31
52
|
bound.F.logSet(logRegistered, null);
|
|
32
53
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
54
|
+
// ---- phase 1: library -------------------------------------------------------
|
|
55
|
+
/** Load and verify the native library without initializing any backend. */
|
|
56
|
+
export function loadLibrary() {
|
|
57
|
+
if (lib)
|
|
58
|
+
return lib;
|
|
36
59
|
const resolved = resolveLibrary();
|
|
37
60
|
// Bring-your-own CUDA runtime: if the selected provider advertises cuda,
|
|
38
61
|
// preload cudart/cublas (the TS twin of the Python cu12 provider's prepare()
|
|
39
62
|
// hook) BEFORE any dlopen, so the ggml-cuda module's DT_NEEDED sonames resolve
|
|
40
|
-
// when
|
|
63
|
+
// when backend init loads it. A no-op without cuda or the runtime dir. This
|
|
64
|
+
// is synchronous (koffi.load has no async form) and can be slow for a large
|
|
65
|
+
// cublas; it only runs for the opt-in CUDA package with the env var set.
|
|
41
66
|
if (resolved.backends.includes("cuda"))
|
|
42
67
|
preloadCudaRuntime();
|
|
43
68
|
const bound = bindLibrary(resolved.libraryPath);
|
|
@@ -51,31 +76,138 @@ export function native() {
|
|
|
51
76
|
// stable JS dispatch callback once, before backend init can create worker
|
|
52
77
|
// threads; setLogHandler later only swaps the JS target.
|
|
53
78
|
ensureLogCallback(bound);
|
|
54
|
-
|
|
55
|
-
// near no-op; on a dynamic-backend bundle it scans the artifact dir.
|
|
56
|
-
let st = bound.F.initBackends(resolved.artifactDir);
|
|
57
|
-
if (st !== g.TRANSCRIBE_OK)
|
|
58
|
-
st = bound.F.initBackendsDefault();
|
|
59
|
-
if (st !== g.TRANSCRIBE_OK) {
|
|
60
|
-
throw new BackendError(`transcribe_init_backends found no usable compute device in ${resolved.artifactDir}: ` +
|
|
61
|
-
`${bound.F.statusString(st)} (status ${st})`);
|
|
62
|
-
}
|
|
63
|
-
cached = {
|
|
79
|
+
lib = {
|
|
64
80
|
...bound,
|
|
65
81
|
libraryPath: resolved.libraryPath,
|
|
66
82
|
provider: resolved.provider,
|
|
83
|
+
artifactDir: resolved.artifactDir,
|
|
67
84
|
abortProto: abortProto(),
|
|
68
85
|
logProto: logProto(),
|
|
69
86
|
};
|
|
70
|
-
return
|
|
87
|
+
return lib;
|
|
88
|
+
}
|
|
89
|
+
// ---- phase 2: backends ------------------------------------------------------
|
|
90
|
+
export function callAsync(fn, ...args) {
|
|
91
|
+
return new Promise((resolve, reject) => fn.async(...args, (err, res) => (err ? reject(err) : resolve(res))));
|
|
92
|
+
}
|
|
93
|
+
function initFailure(n, st) {
|
|
94
|
+
return new BackendError(`transcribe_init_backends found no usable compute device in ${n.artifactDir}: ` +
|
|
95
|
+
`${n.F.statusString(st)} (status ${st})`, st);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The device count after init forces registry construction (and so every device
|
|
99
|
+
* bootstrap) even on paths that skip the module scan. Zero devices is a failure
|
|
100
|
+
* even after an OK init: the compiled-in default path doesn't check the count,
|
|
101
|
+
* and `transcribe_device_count` reports 0 if registry construction threw.
|
|
102
|
+
*/
|
|
103
|
+
function requireDevices(st, count) {
|
|
104
|
+
return st === g.TRANSCRIBE_OK && count <= 0 ? g.TRANSCRIBE_ERR_BACKEND : st;
|
|
105
|
+
}
|
|
106
|
+
async function initAsync(n) {
|
|
107
|
+
let st = await callAsync(n.F.initBackends, n.artifactDir);
|
|
108
|
+
if (st !== g.TRANSCRIBE_OK)
|
|
109
|
+
st = await callAsync(n.F.initBackendsDefault);
|
|
110
|
+
if (st !== g.TRANSCRIBE_OK)
|
|
111
|
+
return st;
|
|
112
|
+
return requireDevices(st, await callAsync(n.F.deviceCount));
|
|
113
|
+
}
|
|
114
|
+
function initSync(n) {
|
|
115
|
+
let st = n.F.initBackends(n.artifactDir);
|
|
116
|
+
if (st !== g.TRANSCRIBE_OK)
|
|
117
|
+
st = n.F.initBackendsDefault();
|
|
118
|
+
if (st !== g.TRANSCRIBE_OK)
|
|
119
|
+
return st;
|
|
120
|
+
return requireDevices(st, n.F.deviceCount());
|
|
121
|
+
}
|
|
122
|
+
/** The current backend initialization state. Never loads or initializes anything. */
|
|
123
|
+
export function backendState() {
|
|
124
|
+
return state;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Load the native library and initialize compute backends off the event loop.
|
|
128
|
+
* Idempotent; concurrent calls share one attempt. A backend init failure is
|
|
129
|
+
* permanent for the process; a library-load failure is not cached.
|
|
130
|
+
*/
|
|
131
|
+
export function initialize() {
|
|
132
|
+
if (state === "ready")
|
|
133
|
+
return Promise.resolve();
|
|
134
|
+
if (state === "failed")
|
|
135
|
+
return Promise.reject(initError);
|
|
136
|
+
if (initPromise)
|
|
137
|
+
return initPromise;
|
|
138
|
+
if (state === "initializing") {
|
|
139
|
+
// Re-entered from a log handler during a synchronous inline init.
|
|
140
|
+
return Promise.reject(inProgress());
|
|
141
|
+
}
|
|
142
|
+
let n;
|
|
143
|
+
try {
|
|
144
|
+
n = loadLibrary();
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
return Promise.reject(e);
|
|
148
|
+
}
|
|
149
|
+
state = "initializing";
|
|
150
|
+
initPromise = initAsync(n).then((st) => {
|
|
151
|
+
initPromise = null;
|
|
152
|
+
if (st === g.TRANSCRIBE_OK) {
|
|
153
|
+
state = "ready";
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
initError = initFailure(n, st);
|
|
157
|
+
state = "failed";
|
|
158
|
+
throw initError;
|
|
159
|
+
}, (e) => {
|
|
160
|
+
// koffi failed to dispatch a call: not a native bootstrap status, so the
|
|
161
|
+
// next call retries (transcribe_init_backends is idempotent).
|
|
162
|
+
initPromise = null;
|
|
163
|
+
state = "uninitialized";
|
|
164
|
+
throw e;
|
|
165
|
+
});
|
|
166
|
+
return initPromise;
|
|
167
|
+
}
|
|
168
|
+
/** Initialize (or join the in-flight init) and return the binding. */
|
|
169
|
+
export async function nativeAsync() {
|
|
170
|
+
await initialize();
|
|
171
|
+
return lib;
|
|
172
|
+
}
|
|
173
|
+
function inProgress() {
|
|
174
|
+
return new BackendInitializing("transcribe.cpp backend initialization is in progress; await initialize() " +
|
|
175
|
+
"(or use getAvailableBackendsAsync() / backendAvailableAsync()) instead of " +
|
|
176
|
+
"calling a synchronous backend query concurrently with it");
|
|
177
|
+
}
|
|
178
|
+
/** The binding with backends ready, for synchronous entry points. See module docs. */
|
|
179
|
+
export function nativeReady() {
|
|
180
|
+
if (state === "ready")
|
|
181
|
+
return lib;
|
|
182
|
+
if (state === "failed")
|
|
183
|
+
throw initError;
|
|
184
|
+
if (state === "initializing")
|
|
185
|
+
throw inProgress();
|
|
186
|
+
const n = loadLibrary();
|
|
187
|
+
state = "initializing"; // a re-entrant call from a log handler fails fast
|
|
188
|
+
let st;
|
|
189
|
+
try {
|
|
190
|
+
st = initSync(n);
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
state = "uninitialized";
|
|
194
|
+
throw e;
|
|
195
|
+
}
|
|
196
|
+
if (st !== g.TRANSCRIBE_OK) {
|
|
197
|
+
initError = initFailure(n, st);
|
|
198
|
+
state = "failed";
|
|
199
|
+
throw initError;
|
|
200
|
+
}
|
|
201
|
+
state = "ready";
|
|
202
|
+
return n;
|
|
71
203
|
}
|
|
72
204
|
/**
|
|
73
205
|
* Route native (and ggml) diagnostics to `handler`, or pass null to disable.
|
|
74
206
|
* The callback may fire from ggml worker threads; koffi marshals it to the
|
|
75
|
-
* event-loop thread
|
|
76
|
-
*
|
|
207
|
+
* event-loop thread, so the handler runs on the main thread. Exceptions thrown
|
|
208
|
+
* by the handler are swallowed (never re-enter C).
|
|
77
209
|
*
|
|
78
|
-
* The native callback is installed once
|
|
210
|
+
* The native callback is installed once when the library loads, before backend
|
|
79
211
|
* initialization. Later calls only swap this JS handler; they never call
|
|
80
212
|
* transcribe_log_set again.
|
|
81
213
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -119,6 +119,13 @@ export interface ModelOptions {
|
|
|
119
119
|
/** Exact device returned by {@link getAvailableBackends}. Omit for the
|
|
120
120
|
* backend's automatic policy. Exact selection never falls back. */
|
|
121
121
|
device?: BackendInfo;
|
|
122
|
+
/** Copy the weights into memory instead of memory-mapping the model file.
|
|
123
|
+
* Default false: where the device can use host memory (CPU, Metal on Apple
|
|
124
|
+
* silicon) the weights are served from the file's page cache, which the OS
|
|
125
|
+
* can reclaim. Don't truncate or rewrite a mapped model file in place;
|
|
126
|
+
* write a new file and rename it over the old one. The
|
|
127
|
+
* `TRANSCRIBE_NO_MMAP=1` environment variable forces true. */
|
|
128
|
+
noMmap?: boolean;
|
|
122
129
|
}
|
|
123
130
|
export interface SessionOptions {
|
|
124
131
|
/** CPU threads for CPU-side ops; 0 = library default. */
|
|
@@ -169,7 +176,7 @@ export type BatchItem = {
|
|
|
169
176
|
};
|
|
170
177
|
export type CommitPolicy = "auto" | "on_finalize" | "stable_prefix";
|
|
171
178
|
export type StreamState = "idle" | "active" | "finished" | "failed";
|
|
172
|
-
export type ExtSlot = "run" | "stream";
|
|
179
|
+
export type ExtSlot = "run" | "stream" | "diarize_run";
|
|
173
180
|
export interface StreamUpdate {
|
|
174
181
|
resultChanged: boolean;
|
|
175
182
|
isFinal: boolean;
|
|
@@ -238,9 +245,8 @@ export interface VoxtralRealtimeStreamOptions {
|
|
|
238
245
|
* "very_high_latency" (~30 s lookahead) is the offline-file operating
|
|
239
246
|
* point; "low_latency" (~1 s) is the real-time point. */
|
|
240
247
|
export type SortformerPreset = "default" | "very_high_latency" | "high_latency" | "low_latency";
|
|
241
|
-
/** Sortformer
|
|
242
|
-
|
|
243
|
-
export interface SortformerStreamOptions {
|
|
248
|
+
/** Sortformer options for {@link DiarizeOptions.family} (diarize_run slot). */
|
|
249
|
+
export interface SortformerDiarizeOptions {
|
|
244
250
|
preset?: SortformerPreset;
|
|
245
251
|
}
|
|
246
252
|
export type FamilyExtension = ({
|
|
@@ -254,5 +260,114 @@ export type FamilyExtension = ({
|
|
|
254
260
|
} & ParakeetBufferedStreamOptions) | ({
|
|
255
261
|
kind: "voxtral";
|
|
256
262
|
} & VoxtralRealtimeStreamOptions) | ({
|
|
257
|
-
kind: "
|
|
258
|
-
} &
|
|
263
|
+
kind: "sortformer_diarize";
|
|
264
|
+
} & SortformerDiarizeOptions);
|
|
265
|
+
/**
|
|
266
|
+
* What a model serves: "asr" (transcription), "diarize" (speaker turns),
|
|
267
|
+
* "langid" (language), "vad" (voice activity).
|
|
268
|
+
*/
|
|
269
|
+
export type Role = "asr" | "diarize" | "langid" | "vad";
|
|
270
|
+
export interface DiarizeInfo {
|
|
271
|
+
/** Input PCM rate. */
|
|
272
|
+
sampleRate: number;
|
|
273
|
+
/** Speaker ids are in [1, maxSpeakers]. */
|
|
274
|
+
maxSpeakers: number;
|
|
275
|
+
}
|
|
276
|
+
export interface DiarizeSessionOptions {
|
|
277
|
+
/** CPU threads for CPU-side ops; 0 = library default. */
|
|
278
|
+
nThreads?: number;
|
|
279
|
+
}
|
|
280
|
+
export interface DiarizeOptions {
|
|
281
|
+
/** Cancel the run cooperatively. */
|
|
282
|
+
signal?: AbortSignal;
|
|
283
|
+
/** A diarize_run-slot family extension (e.g. sortformer_diarize). */
|
|
284
|
+
family?: FamilyExtension;
|
|
285
|
+
}
|
|
286
|
+
export interface LangIdInfo {
|
|
287
|
+
/** Input PCM rate. */
|
|
288
|
+
sampleRate: number;
|
|
289
|
+
/** Label indices are [0, nLabels). */
|
|
290
|
+
nLabels: number;
|
|
291
|
+
/** Shorter scored audio throws InputTooShort. */
|
|
292
|
+
minAudioMs: number;
|
|
293
|
+
/** Longer input is scored on its first maxAudioMs (30000). */
|
|
294
|
+
maxAudioMs: number;
|
|
295
|
+
}
|
|
296
|
+
export interface LangIdSessionOptions {
|
|
297
|
+
/** CPU threads for CPU-side ops; 0 = library default. */
|
|
298
|
+
nThreads?: number;
|
|
299
|
+
}
|
|
300
|
+
export interface LangIdOptions {
|
|
301
|
+
/** Cancel the run cooperatively. */
|
|
302
|
+
signal?: AbortSignal;
|
|
303
|
+
/**
|
|
304
|
+
* Restrict the decision to these codes or aliases. Omitted (or undefined /
|
|
305
|
+
* null) means every label; an empty array throws InvalidArgument; an
|
|
306
|
+
* unknown code throws UnsupportedRequest.
|
|
307
|
+
*/
|
|
308
|
+
allowed?: readonly string[] | null;
|
|
309
|
+
}
|
|
310
|
+
/** One ranked label; `code` is the model's own label ("en", "iw"). */
|
|
311
|
+
export interface LangIdCandidate {
|
|
312
|
+
index: number;
|
|
313
|
+
code: string;
|
|
314
|
+
name: string;
|
|
315
|
+
/** Softmax renormalized over the allowed set. */
|
|
316
|
+
p: number;
|
|
317
|
+
logit: number;
|
|
318
|
+
}
|
|
319
|
+
export interface LangIdResult {
|
|
320
|
+
/**
|
|
321
|
+
* Every allowed label (duplicates once; every label when unrestricted),
|
|
322
|
+
* ranked by p, descending; ties keep label order.
|
|
323
|
+
*/
|
|
324
|
+
candidates: LangIdCandidate[];
|
|
325
|
+
/** The top candidate's code, or null with no candidates. */
|
|
326
|
+
code: string | null;
|
|
327
|
+
/** Unrestricted probability inside the allowed set (1 when unrestricted). */
|
|
328
|
+
allowedMass: number;
|
|
329
|
+
}
|
|
330
|
+
export interface VadInfo {
|
|
331
|
+
/** Input PCM rate (16000). */
|
|
332
|
+
sampleRate: number;
|
|
333
|
+
/** Samples per probability (512 = 32 ms for Silero). */
|
|
334
|
+
frameSamples: number;
|
|
335
|
+
}
|
|
336
|
+
export interface VadSessionOptions {
|
|
337
|
+
/** CPU threads; 0 = library default. */
|
|
338
|
+
nThreads?: number;
|
|
339
|
+
}
|
|
340
|
+
/** Segmentation options for VadSession.run; omitted fields keep Silero's defaults. */
|
|
341
|
+
export interface VadOptions {
|
|
342
|
+
/** Cancel the run cooperatively. */
|
|
343
|
+
signal?: AbortSignal;
|
|
344
|
+
/** A frame with p >= threshold is speech (default 0.5). */
|
|
345
|
+
threshold?: number;
|
|
346
|
+
/** Inside speech, p < negThreshold is silence; negative (default) = max(threshold - 0.15, 0.01). */
|
|
347
|
+
negThreshold?: number;
|
|
348
|
+
/** Shorter segments are dropped (default 250). */
|
|
349
|
+
minSpeechMs?: number;
|
|
350
|
+
/** Silence this long ends a segment (default 100). */
|
|
351
|
+
minSilenceMs?: number;
|
|
352
|
+
/** Padding added to each side of a segment (default 30). */
|
|
353
|
+
speechPadMs?: number;
|
|
354
|
+
/** Longer segments are split; 0 (default) = no limit. */
|
|
355
|
+
maxSpeechMs?: number;
|
|
356
|
+
}
|
|
357
|
+
export interface VadFeedOptions {
|
|
358
|
+
/** Cancel the feed cooperatively. */
|
|
359
|
+
signal?: AbortSignal;
|
|
360
|
+
}
|
|
361
|
+
/** One speech segment, in samples of the run's input: [startSample, endSample). */
|
|
362
|
+
export interface VadSegment {
|
|
363
|
+
startSample: number;
|
|
364
|
+
endSample: number;
|
|
365
|
+
}
|
|
366
|
+
export interface VadResult {
|
|
367
|
+
/** Per-frame speech probabilities produced by this call (copied). */
|
|
368
|
+
probs: number[];
|
|
369
|
+
/** Stream frame index of probs[0]: 0 after run; frames scored before a feed / flush. */
|
|
370
|
+
firstFrame: number;
|
|
371
|
+
/** Speech segments; run only, empty after a feed or flush. */
|
|
372
|
+
segments: VadSegment[];
|
|
373
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "transcribe-cpp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "TypeScript/Node.js bindings for transcribe.cpp — a C/C++ speech-to-text library built on ggml",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"koffi": "^3.0.2"
|
|
52
52
|
},
|
|
53
53
|
"optionalDependencies": {
|
|
54
|
-
"@transcribe-cpp/darwin-arm64-metal": "0.
|
|
55
|
-
"@transcribe-cpp/darwin-x64-cpu": "0.
|
|
56
|
-
"@transcribe-cpp/linux-x64-cpu-vulkan": "0.
|
|
57
|
-
"@transcribe-cpp/linux-arm64-cpu-vulkan": "0.
|
|
58
|
-
"@transcribe-cpp/win32-x64-cpu-vulkan": "0.
|
|
54
|
+
"@transcribe-cpp/darwin-arm64-metal": "0.4.1",
|
|
55
|
+
"@transcribe-cpp/darwin-x64-cpu": "0.4.1",
|
|
56
|
+
"@transcribe-cpp/linux-x64-cpu-vulkan": "0.4.1",
|
|
57
|
+
"@transcribe-cpp/linux-arm64-cpu-vulkan": "0.4.1",
|
|
58
|
+
"@transcribe-cpp/win32-x64-cpu-vulkan": "0.4.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^22.0.0",
|