transcribe-cpp 0.0.3 → 0.0.4
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/dist/_generated.d.ts +5 -1
- package/dist/_generated.js +8 -3
- package/dist/ffi.js +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +31 -1
- package/dist/types.d.ts +23 -4
- package/package.json +6 -6
package/dist/_generated.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const PUBLIC_HEADER_HASH = "
|
|
1
|
+
export declare const PUBLIC_HEADER_HASH = "ebe6a6816e34a24e";
|
|
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;
|
|
@@ -62,6 +62,10 @@ export declare const TRANSCRIBE_BACKEND_METAL = 2;
|
|
|
62
62
|
export declare const TRANSCRIBE_BACKEND_VULKAN = 3;
|
|
63
63
|
export declare const TRANSCRIBE_BACKEND_CPU_ACCEL = 4;
|
|
64
64
|
export declare const TRANSCRIBE_BACKEND_CUDA = 5;
|
|
65
|
+
export declare const TRANSCRIBE_DEVICE_TYPE_CPU = 0;
|
|
66
|
+
export declare const TRANSCRIBE_DEVICE_TYPE_GPU = 1;
|
|
67
|
+
export declare const TRANSCRIBE_DEVICE_TYPE_IGPU = 2;
|
|
68
|
+
export declare const TRANSCRIBE_DEVICE_TYPE_ACCEL = 3;
|
|
65
69
|
export declare const TRANSCRIBE_FEATURE_INITIAL_PROMPT = 0;
|
|
66
70
|
export declare const TRANSCRIBE_FEATURE_TEMPERATURE_FALLBACK = 1;
|
|
67
71
|
export declare const TRANSCRIBE_FEATURE_LONG_FORM = 2;
|
package/dist/_generated.js
CHANGED
|
@@ -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 = "
|
|
13
|
+
export const PUBLIC_HEADER_HASH = "ebe6a6816e34a24e";
|
|
14
14
|
// === enum constants ===
|
|
15
15
|
export const TRANSCRIBE_OK = 0;
|
|
16
16
|
export const TRANSCRIBE_ERR_INVALID_ARG = 1;
|
|
@@ -75,6 +75,10 @@ export const TRANSCRIBE_BACKEND_METAL = 2;
|
|
|
75
75
|
export const TRANSCRIBE_BACKEND_VULKAN = 3;
|
|
76
76
|
export const TRANSCRIBE_BACKEND_CPU_ACCEL = 4;
|
|
77
77
|
export const TRANSCRIBE_BACKEND_CUDA = 5;
|
|
78
|
+
export const TRANSCRIBE_DEVICE_TYPE_CPU = 0;
|
|
79
|
+
export const TRANSCRIBE_DEVICE_TYPE_GPU = 1;
|
|
80
|
+
export const TRANSCRIBE_DEVICE_TYPE_IGPU = 2;
|
|
81
|
+
export const TRANSCRIBE_DEVICE_TYPE_ACCEL = 3;
|
|
78
82
|
export const TRANSCRIBE_FEATURE_INITIAL_PROMPT = 0;
|
|
79
83
|
export const TRANSCRIBE_FEATURE_TEMPERATURE_FALLBACK = 1;
|
|
80
84
|
export const TRANSCRIBE_FEATURE_LONG_FORM = 2;
|
|
@@ -98,7 +102,7 @@ export const TRANSCRIBE_EXT_KIND_VOXTRAL_REALTIME_STREAM = 1414746710;
|
|
|
98
102
|
export const TRANSCRIBE_EXT_KIND_WHISPER_RUN = 1314015319;
|
|
99
103
|
export const STRUCT_LAYOUT = {
|
|
100
104
|
'transcribe_ext': { size: 16, align: 8, offsets: { 'size': 0, 'kind': 8 } },
|
|
101
|
-
'transcribe_backend_device': { size:
|
|
105
|
+
'transcribe_backend_device': { size: 64, align: 8, offsets: { 'struct_size': 0, 'name': 8, 'description': 16, 'kind': 24, 'device_id': 32, 'memory_total': 40, 'memory_free': 48, 'device_type': 56 } },
|
|
102
106
|
'transcribe_model_load_params': { size: 16, align: 8, offsets: { 'struct_size': 0, 'backend': 8, 'gpu_device': 12 } },
|
|
103
107
|
'transcribe_session_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'n_threads': 8, 'kv_type': 12, 'n_ctx': 16 } },
|
|
104
108
|
'transcribe_run_params': { size: 64, align: 8, offsets: { 'struct_size': 0, 'task': 8, 'timestamps': 12, 'pnc': 16, 'itn': 20, 'language': 24, 'target_language': 32, 'keep_special_tags': 40, 'family': 48, 'spec_k_drafts': 56 } },
|
|
@@ -138,7 +142,7 @@ export const ABI_STRUCT_IDS = {
|
|
|
138
142
|
export function defineTypes(koffi) {
|
|
139
143
|
const T = {};
|
|
140
144
|
T['transcribe_ext'] = koffi.struct({ size: 'uint64_t', kind: 'uint32_t' });
|
|
141
|
-
T['transcribe_backend_device'] = koffi.struct({ struct_size: 'uint64_t', name: 'char *', description: 'char *', kind: 'char *' });
|
|
145
|
+
T['transcribe_backend_device'] = koffi.struct({ struct_size: 'uint64_t', name: 'char *', description: 'char *', kind: 'char *', device_id: 'char *', memory_total: 'uint64_t', memory_free: 'uint64_t', device_type: 'int' });
|
|
142
146
|
T['transcribe_model_load_params'] = koffi.struct({ struct_size: 'uint64_t', backend: 'int', gpu_device: 'int' });
|
|
143
147
|
T['transcribe_session_params'] = koffi.struct({ struct_size: 'uint64_t', n_threads: 'int', kv_type: 'int', n_ctx: 'int32_t' });
|
|
144
148
|
T['transcribe_run_params'] = koffi.struct({ struct_size: 'uint64_t', task: 'int', timestamps: 'int', pnc: 'int', itn: 'int', language: 'char *', target_language: 'char *', keep_special_tags: 'bool', family: 'void *', spec_k_drafts: 'int32_t' });
|
|
@@ -198,6 +202,7 @@ export const FUNCTION_SIGNATURES = {
|
|
|
198
202
|
'transcribe_model_backend': { ret: 'const char *', args: ['const struct transcribe_model *'] },
|
|
199
203
|
'transcribe_model_free': { ret: 'void', args: ['struct transcribe_model *'] },
|
|
200
204
|
'transcribe_model_get_capabilities': { ret: 'transcribe_status', args: ['const struct transcribe_model *', 'struct transcribe_capabilities *'] },
|
|
205
|
+
'transcribe_model_get_device': { ret: 'transcribe_status', args: ['const struct transcribe_model *', 'struct transcribe_backend_device *'] },
|
|
201
206
|
'transcribe_model_load_file': { ret: 'transcribe_status', args: ['const char *', 'const struct transcribe_model_load_params *', 'struct transcribe_model **'] },
|
|
202
207
|
'transcribe_model_load_params_init': { ret: 'void', args: ['struct transcribe_model_load_params *'] },
|
|
203
208
|
'transcribe_model_supports': { ret: '_Bool', args: ['const struct transcribe_model *', 'transcribe_feature'] },
|
package/dist/ffi.js
CHANGED
|
@@ -51,6 +51,10 @@ export function bindLibrary(libraryPath) {
|
|
|
51
51
|
modelArch: lib.func("transcribe_model_arch_string", "str", ["void *"]),
|
|
52
52
|
modelVariant: lib.func("transcribe_model_variant_string", "str", ["void *"]),
|
|
53
53
|
modelBackend: lib.func("transcribe_model_backend", "str", ["void *"]),
|
|
54
|
+
modelGetDevice: lib.func("transcribe_model_get_device", "int", [
|
|
55
|
+
"void *",
|
|
56
|
+
iop(T.transcribe_backend_device),
|
|
57
|
+
]),
|
|
54
58
|
modelSupports: lib.func("transcribe_model_supports", "bool", ["void *", "int"]),
|
|
55
59
|
tokenize: lib.func("transcribe_tokenize", "int", ["void *", "str", "int32_t *", "size_t"]),
|
|
56
60
|
capabilitiesInit: lib.func("transcribe_capabilities_init", "void", [
|
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ export declare class TranscribeModel {
|
|
|
80
80
|
get arch(): string;
|
|
81
81
|
get variant(): string;
|
|
82
82
|
get backend(): string;
|
|
83
|
+
/** The compute device this model is running on. `memoryFree` is a live
|
|
84
|
+
* snapshot, so read this again to poll how much device memory is left
|
|
85
|
+
* after the model loaded. */
|
|
86
|
+
get device(): BackendInfo;
|
|
83
87
|
dispose(): void;
|
|
84
88
|
[Symbol.dispose](): void;
|
|
85
89
|
}
|
package/dist/index.js
CHANGED
|
@@ -216,6 +216,27 @@ export function version() {
|
|
|
216
216
|
export function libraryPath() {
|
|
217
217
|
return native().libraryPath;
|
|
218
218
|
}
|
|
219
|
+
const DEVICE_TYPE_NAMES = {
|
|
220
|
+
[g.TRANSCRIBE_DEVICE_TYPE_CPU]: "cpu",
|
|
221
|
+
[g.TRANSCRIBE_DEVICE_TYPE_GPU]: "gpu",
|
|
222
|
+
[g.TRANSCRIBE_DEVICE_TYPE_IGPU]: "igpu",
|
|
223
|
+
[g.TRANSCRIBE_DEVICE_TYPE_ACCEL]: "accel",
|
|
224
|
+
};
|
|
225
|
+
// Decode a koffi-filled transcribe_backend_device struct into a BackendInfo.
|
|
226
|
+
// memory_* are uint64 (bigint from koffi) but stay well under 2^53 for any
|
|
227
|
+
// real device, so num() narrows them losslessly.
|
|
228
|
+
function deviceFromRaw(dev, index = null) {
|
|
229
|
+
return {
|
|
230
|
+
name: dev.name ?? "",
|
|
231
|
+
description: dev.description ?? "",
|
|
232
|
+
kind: dev.kind ?? "",
|
|
233
|
+
deviceType: DEVICE_TYPE_NAMES[dev.device_type] ?? "unknown",
|
|
234
|
+
deviceId: dev.device_id ?? null,
|
|
235
|
+
memoryTotal: num(dev.memory_total),
|
|
236
|
+
memoryFree: num(dev.memory_free),
|
|
237
|
+
index,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
219
240
|
export function getAvailableBackends() {
|
|
220
241
|
const n = native();
|
|
221
242
|
const count = n.F.backendDeviceCount();
|
|
@@ -224,7 +245,7 @@ export function getAvailableBackends() {
|
|
|
224
245
|
const dev = {};
|
|
225
246
|
n.F.backendDeviceInit(dev);
|
|
226
247
|
check(n, n.F.getBackendDevice(i, dev), `reading backend device ${i}`);
|
|
227
|
-
out.push(
|
|
248
|
+
out.push(deviceFromRaw(dev, i));
|
|
228
249
|
}
|
|
229
250
|
return out;
|
|
230
251
|
}
|
|
@@ -1049,6 +1070,15 @@ export class TranscribeModel {
|
|
|
1049
1070
|
get backend() {
|
|
1050
1071
|
return this.#n.F.modelBackend(this.handle) ?? "";
|
|
1051
1072
|
}
|
|
1073
|
+
/** The compute device this model is running on. `memoryFree` is a live
|
|
1074
|
+
* snapshot, so read this again to poll how much device memory is left
|
|
1075
|
+
* after the model loaded. */
|
|
1076
|
+
get device() {
|
|
1077
|
+
const dev = {};
|
|
1078
|
+
this.#n.F.backendDeviceInit(dev);
|
|
1079
|
+
check(this.#n, this.#n.F.modelGetDevice(this.handle, dev), "reading model device");
|
|
1080
|
+
return deviceFromRaw(dev);
|
|
1081
|
+
}
|
|
1052
1082
|
dispose() {
|
|
1053
1083
|
if (this.#disposed)
|
|
1054
1084
|
return;
|
package/dist/types.d.ts
CHANGED
|
@@ -65,15 +65,37 @@ export interface TranscriptionResult {
|
|
|
65
65
|
aborted: boolean;
|
|
66
66
|
truncated: boolean;
|
|
67
67
|
}
|
|
68
|
+
/** Vendor-agnostic device class, orthogonal to {@link BackendInfo.kind}.
|
|
69
|
+
* `"unknown"` is reported for a device-type value newer than this binding —
|
|
70
|
+
* distinguish such devices by {@link BackendInfo.deviceId} / name, not this axis. */
|
|
71
|
+
export type DeviceType = "cpu" | "gpu" | "igpu" | "accel" | "unknown";
|
|
68
72
|
export interface BackendInfo {
|
|
69
73
|
name: string;
|
|
70
74
|
description: string;
|
|
71
75
|
kind: string;
|
|
76
|
+
/** The CPU/GPU/IGPU/ACCEL axis, orthogonal to `kind`. */
|
|
77
|
+
deviceType: DeviceType;
|
|
78
|
+
/** Stable hardware id (PCI bus id) when the backend reports one, else null
|
|
79
|
+
* (e.g. Metal). */
|
|
80
|
+
deviceId: string | null;
|
|
81
|
+
/** Reported device memory capacity in bytes, or 0 if unreported. */
|
|
82
|
+
memoryTotal: number;
|
|
83
|
+
/** Available device memory in bytes — a snapshot at query time, or 0 if
|
|
84
|
+
* unreported. Re-query (via {@link getAvailableBackends} or `model.device`)
|
|
85
|
+
* to refresh; backend-defined and not comparable across device kinds. */
|
|
86
|
+
memoryFree: number;
|
|
87
|
+
/** Registry index of this device — the value to pass as
|
|
88
|
+
* {@link ModelOptions.gpuDevice} to select it (0 selects the auto / first
|
|
89
|
+
* device). `null` when this came from `model.device`, since
|
|
90
|
+
* `transcribe_model_get_device` does not expose an index; correlate such a
|
|
91
|
+
* device back to {@link getAvailableBackends} by `deviceId` / `name`
|
|
92
|
+
* instead. Order-dependent and not stable across driver updates or hosts. */
|
|
93
|
+
index: number | null;
|
|
72
94
|
}
|
|
73
95
|
export interface ModelOptions {
|
|
74
96
|
/** "auto" (default), or an explicit backend. */
|
|
75
97
|
backend?: Backend;
|
|
76
|
-
/** GPU device
|
|
98
|
+
/** GPU device registry index. 0 means auto / first matching device. */
|
|
77
99
|
gpuDevice?: number;
|
|
78
100
|
}
|
|
79
101
|
export interface SessionOptions {
|
|
@@ -96,9 +118,6 @@ export interface TranscribeOptions {
|
|
|
96
118
|
/** A run-slot family extension (e.g. whisper). */
|
|
97
119
|
family?: FamilyExtension;
|
|
98
120
|
}
|
|
99
|
-
/** A native compute device the runtime discovered. */
|
|
100
|
-
export interface DeviceInfo extends BackendInfo {
|
|
101
|
-
}
|
|
102
121
|
/** One result of a batch run: success carries the transcript, failure the error.
|
|
103
122
|
* On failure, `error.utteranceIndex` is set, and `error.partialResult` carries any
|
|
104
123
|
* recovered transcript when the failure was an abort/truncation. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "transcribe-cpp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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.0.
|
|
55
|
-
"@transcribe-cpp/darwin-x64-cpu": "0.0.
|
|
56
|
-
"@transcribe-cpp/linux-x64-cpu-vulkan": "0.0.
|
|
57
|
-
"@transcribe-cpp/linux-arm64-cpu-vulkan": "0.0.
|
|
58
|
-
"@transcribe-cpp/win32-x64-cpu-vulkan": "0.0.
|
|
54
|
+
"@transcribe-cpp/darwin-arm64-metal": "0.0.4",
|
|
55
|
+
"@transcribe-cpp/darwin-x64-cpu": "0.0.4",
|
|
56
|
+
"@transcribe-cpp/linux-x64-cpu-vulkan": "0.0.4",
|
|
57
|
+
"@transcribe-cpp/linux-arm64-cpu-vulkan": "0.0.4",
|
|
58
|
+
"@transcribe-cpp/win32-x64-cpu-vulkan": "0.0.4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^22.0.0",
|