transcribe-cpp 0.0.0 → 0.0.3
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 +206 -8
- package/dist/_generated.d.ts +97 -0
- package/dist/_generated.js +251 -0
- package/dist/abi.d.ts +12 -0
- package/dist/abi.js +55 -0
- package/dist/errors.d.ts +49 -0
- package/dist/errors.js +83 -0
- package/dist/ffi.d.ts +21 -0
- package/dist/ffi.js +219 -0
- package/dist/index.d.ts +84 -7
- package/dist/index.js +1081 -6
- package/dist/loader.d.ts +20 -0
- package/dist/loader.js +140 -0
- package/dist/native.d.ts +25 -0
- package/dist/native.js +77 -0
- package/dist/types.d.ts +181 -0
- package/dist/types.js +2 -0
- package/dist/version.d.ts +18 -0
- package/dist/version.js +30 -0
- package/package.json +33 -6
- package/scripts/build-from-source.mjs +90 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Error hierarchy mapped from `transcribe_status`. Mirrors the Python binding. */
|
|
2
|
+
import type { TranscriptionResult } from "./types.js";
|
|
3
|
+
export declare class TranscribeError extends Error {
|
|
4
|
+
/** The `transcribe_status` value (0 for binding-side errors). */
|
|
5
|
+
readonly status: number;
|
|
6
|
+
/** Set on per-utterance failures from a batch run. */
|
|
7
|
+
utteranceIndex?: number;
|
|
8
|
+
/** Any partial transcript recovered before the error (set on Aborted / OutputTruncated). */
|
|
9
|
+
partialResult?: TranscriptionResult;
|
|
10
|
+
constructor(message: string, status?: number);
|
|
11
|
+
}
|
|
12
|
+
export declare class InvalidArgument extends TranscribeError {
|
|
13
|
+
}
|
|
14
|
+
export declare class NotImplementedByModel extends TranscribeError {
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Raised when another compute already occupies the model. The C library allows
|
|
18
|
+
* at most one run / batch / active stream in flight per model across ALL of its
|
|
19
|
+
* sessions (transcribe.h); a sibling op while a stream is active is refused with
|
|
20
|
+
* this rather than allowed to race. Binding-side error, so `status` is 0.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Busy extends TranscribeError {
|
|
23
|
+
}
|
|
24
|
+
export declare class ModelFileNotFound extends TranscribeError {
|
|
25
|
+
}
|
|
26
|
+
export declare class ModelLoadError extends TranscribeError {
|
|
27
|
+
}
|
|
28
|
+
export declare class OutOfMemory extends TranscribeError {
|
|
29
|
+
}
|
|
30
|
+
export declare class BackendError extends TranscribeError {
|
|
31
|
+
}
|
|
32
|
+
export declare class UnsupportedRequest extends TranscribeError {
|
|
33
|
+
}
|
|
34
|
+
export declare class AbiError extends TranscribeError {
|
|
35
|
+
}
|
|
36
|
+
export declare class InputTooLong extends TranscribeError {
|
|
37
|
+
}
|
|
38
|
+
export declare class VersionMismatch extends TranscribeError {
|
|
39
|
+
}
|
|
40
|
+
/** Raised when a run is cancelled; carries any partial transcript in `partialResult`. */
|
|
41
|
+
export declare class Aborted extends TranscribeError {
|
|
42
|
+
}
|
|
43
|
+
/** Raised when decode hits the context/generation cap; carries the partial in `partialResult`. */
|
|
44
|
+
export declare class OutputTruncated extends TranscribeError {
|
|
45
|
+
}
|
|
46
|
+
/** Build (do not throw) the mapped exception for a status. */
|
|
47
|
+
export declare function exceptionForStatus(status: number, statusString: string, context?: string): TranscribeError;
|
|
48
|
+
/** Throw the mapped exception unless the status is OK. */
|
|
49
|
+
export declare function raiseForStatus(status: number, statusString: string, context?: string): void;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** Error hierarchy mapped from `transcribe_status`. Mirrors the Python binding. */
|
|
2
|
+
import * as g from "./_generated.js";
|
|
3
|
+
export class TranscribeError extends Error {
|
|
4
|
+
/** The `transcribe_status` value (0 for binding-side errors). */
|
|
5
|
+
status;
|
|
6
|
+
/** Set on per-utterance failures from a batch run. */
|
|
7
|
+
utteranceIndex;
|
|
8
|
+
/** Any partial transcript recovered before the error (set on Aborted / OutputTruncated). */
|
|
9
|
+
partialResult;
|
|
10
|
+
constructor(message, status = g.TRANSCRIBE_OK) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = new.target.name;
|
|
13
|
+
this.status = status;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class InvalidArgument extends TranscribeError {
|
|
17
|
+
}
|
|
18
|
+
export class NotImplementedByModel extends TranscribeError {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Raised when another compute already occupies the model. The C library allows
|
|
22
|
+
* at most one run / batch / active stream in flight per model across ALL of its
|
|
23
|
+
* sessions (transcribe.h); a sibling op while a stream is active is refused with
|
|
24
|
+
* this rather than allowed to race. Binding-side error, so `status` is 0.
|
|
25
|
+
*/
|
|
26
|
+
export class Busy extends TranscribeError {
|
|
27
|
+
}
|
|
28
|
+
export class ModelFileNotFound extends TranscribeError {
|
|
29
|
+
}
|
|
30
|
+
export class ModelLoadError extends TranscribeError {
|
|
31
|
+
}
|
|
32
|
+
export class OutOfMemory extends TranscribeError {
|
|
33
|
+
}
|
|
34
|
+
export class BackendError extends TranscribeError {
|
|
35
|
+
}
|
|
36
|
+
export class UnsupportedRequest extends TranscribeError {
|
|
37
|
+
}
|
|
38
|
+
export class AbiError extends TranscribeError {
|
|
39
|
+
}
|
|
40
|
+
export class InputTooLong extends TranscribeError {
|
|
41
|
+
}
|
|
42
|
+
export class VersionMismatch extends TranscribeError {
|
|
43
|
+
}
|
|
44
|
+
/** Raised when a run is cancelled; carries any partial transcript in `partialResult`. */
|
|
45
|
+
export class Aborted extends TranscribeError {
|
|
46
|
+
}
|
|
47
|
+
/** Raised when decode hits the context/generation cap; carries the partial in `partialResult`. */
|
|
48
|
+
export class OutputTruncated extends TranscribeError {
|
|
49
|
+
}
|
|
50
|
+
const STATUS_TO_EXC = {
|
|
51
|
+
[g.TRANSCRIBE_ERR_INVALID_ARG]: InvalidArgument,
|
|
52
|
+
[g.TRANSCRIBE_ERR_NOT_IMPLEMENTED]: NotImplementedByModel,
|
|
53
|
+
[g.TRANSCRIBE_ERR_FILE_NOT_FOUND]: ModelFileNotFound,
|
|
54
|
+
[g.TRANSCRIBE_ERR_GGUF]: ModelLoadError,
|
|
55
|
+
[g.TRANSCRIBE_ERR_UNSUPPORTED_ARCH]: ModelLoadError,
|
|
56
|
+
[g.TRANSCRIBE_ERR_UNSUPPORTED_VARIANT]: ModelLoadError,
|
|
57
|
+
[g.TRANSCRIBE_ERR_OOM]: OutOfMemory,
|
|
58
|
+
[g.TRANSCRIBE_ERR_BACKEND]: BackendError,
|
|
59
|
+
[g.TRANSCRIBE_ERR_SAMPLE_RATE]: InvalidArgument,
|
|
60
|
+
[g.TRANSCRIBE_ERR_UNSUPPORTED_LANGUAGE]: UnsupportedRequest,
|
|
61
|
+
[g.TRANSCRIBE_ERR_UNSUPPORTED_TASK]: UnsupportedRequest,
|
|
62
|
+
[g.TRANSCRIBE_ERR_UNSUPPORTED_TIMESTAMPS]: UnsupportedRequest,
|
|
63
|
+
[g.TRANSCRIBE_ERR_ABORTED]: Aborted,
|
|
64
|
+
[g.TRANSCRIBE_ERR_BAD_STRUCT_SIZE]: AbiError,
|
|
65
|
+
[g.TRANSCRIBE_ERR_UNSUPPORTED_PNC]: UnsupportedRequest,
|
|
66
|
+
[g.TRANSCRIBE_ERR_UNSUPPORTED_ITN]: UnsupportedRequest,
|
|
67
|
+
[g.TRANSCRIBE_ERR_INPUT_TOO_LONG]: InputTooLong,
|
|
68
|
+
[g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED]: OutputTruncated,
|
|
69
|
+
};
|
|
70
|
+
/** Build (do not throw) the mapped exception for a status. */
|
|
71
|
+
export function exceptionForStatus(status, statusString, context = "") {
|
|
72
|
+
const Cls = STATUS_TO_EXC[status] ?? TranscribeError;
|
|
73
|
+
const msg = context
|
|
74
|
+
? `${context}: ${statusString} (status ${status})`
|
|
75
|
+
: `${statusString} (status ${status})`;
|
|
76
|
+
return new Cls(msg, status);
|
|
77
|
+
}
|
|
78
|
+
/** Throw the mapped exception unless the status is OK. */
|
|
79
|
+
export function raiseForStatus(status, statusString, context = "") {
|
|
80
|
+
if (status === g.TRANSCRIBE_OK)
|
|
81
|
+
return;
|
|
82
|
+
throw exceptionForStatus(status, statusString, context);
|
|
83
|
+
}
|
package/dist/ffi.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The koffi engine adapter: load the library and hand-bind the C functions
|
|
3
|
+
* with explicit in/out/inout direction (which a generic generator can't infer).
|
|
4
|
+
* Struct *layouts* come from the generated `defineTypes`; the drift gate covers
|
|
5
|
+
* signature changes via the pinned PUBLIC_HEADER_HASH.
|
|
6
|
+
*
|
|
7
|
+
* This is the one runtime-specific seam. A Bun/Deno adapter would re-implement
|
|
8
|
+
* this file against the same generated types and the same public shape.
|
|
9
|
+
*/
|
|
10
|
+
import koffi from "koffi";
|
|
11
|
+
export interface Bound {
|
|
12
|
+
koffi: typeof koffi;
|
|
13
|
+
lib: ReturnType<typeof koffi.load>;
|
|
14
|
+
T: Record<string, any>;
|
|
15
|
+
F: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
export declare function bindLibrary(libraryPath: string): Bound;
|
|
18
|
+
/** koffi proto for the abort callback: `bool (void *userdata)`. */
|
|
19
|
+
export declare function abortProto(): any;
|
|
20
|
+
/** koffi proto for the log callback: `void (int level, const char *msg, void *ud)`. */
|
|
21
|
+
export declare function logProto(): any;
|
package/dist/ffi.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The koffi engine adapter: load the library and hand-bind the C functions
|
|
3
|
+
* with explicit in/out/inout direction (which a generic generator can't infer).
|
|
4
|
+
* Struct *layouts* come from the generated `defineTypes`; the drift gate covers
|
|
5
|
+
* signature changes via the pinned PUBLIC_HEADER_HASH.
|
|
6
|
+
*
|
|
7
|
+
* This is the one runtime-specific seam. A Bun/Deno adapter would re-implement
|
|
8
|
+
* this file against the same generated types and the same public shape.
|
|
9
|
+
*/
|
|
10
|
+
import koffi from "koffi";
|
|
11
|
+
import { defineTypes } from "./_generated.js";
|
|
12
|
+
export function bindLibrary(libraryPath) {
|
|
13
|
+
const lib = koffi.load(libraryPath);
|
|
14
|
+
const T = defineTypes(koffi);
|
|
15
|
+
const inp = (t) => koffi.pointer(t); // const X * (marshalled in)
|
|
16
|
+
const outp = (t) => koffi.out(koffi.pointer(t)); // X * pure out (e.g. *_init)
|
|
17
|
+
// Accessors read struct_size on input then fill the rest: copy in AND back.
|
|
18
|
+
const iop = (t) => koffi.inout(koffi.pointer(t));
|
|
19
|
+
const handleOut = koffi.out(koffi.pointer("void *")); // X ** out
|
|
20
|
+
const F = {
|
|
21
|
+
// identity / diagnostics
|
|
22
|
+
version: lib.func("transcribe_version", "str", []),
|
|
23
|
+
versionCommit: lib.func("transcribe_version_commit", "str", []),
|
|
24
|
+
statusString: lib.func("transcribe_status_string", "str", ["int"]),
|
|
25
|
+
abiStructSize: lib.func("transcribe_abi_struct_size", "uint64", ["int"]),
|
|
26
|
+
abiStructAlign: lib.func("transcribe_abi_struct_align", "uint64", ["int"]),
|
|
27
|
+
// backends
|
|
28
|
+
initBackends: lib.func("transcribe_init_backends", "int", ["str"]),
|
|
29
|
+
initBackendsDefault: lib.func("transcribe_init_backends_default", "int", []),
|
|
30
|
+
backendDeviceCount: lib.func("transcribe_backend_device_count", "int", []),
|
|
31
|
+
backendDeviceInit: lib.func("transcribe_backend_device_init", "void", [
|
|
32
|
+
outp(T.transcribe_backend_device),
|
|
33
|
+
]),
|
|
34
|
+
getBackendDevice: lib.func("transcribe_get_backend_device", "int", [
|
|
35
|
+
"int",
|
|
36
|
+
iop(T.transcribe_backend_device),
|
|
37
|
+
]),
|
|
38
|
+
backendAvailable: lib.func("transcribe_backend_available", "bool", ["int"]),
|
|
39
|
+
// logging (callback pointer comes from koffi.register -> passed as void*)
|
|
40
|
+
logSet: lib.func("transcribe_log_set", "void", ["void *", "void *"]),
|
|
41
|
+
// model
|
|
42
|
+
modelLoadParamsInit: lib.func("transcribe_model_load_params_init", "void", [
|
|
43
|
+
outp(T.transcribe_model_load_params),
|
|
44
|
+
]),
|
|
45
|
+
modelLoadFile: lib.func("transcribe_model_load_file", "int", [
|
|
46
|
+
"str",
|
|
47
|
+
inp(T.transcribe_model_load_params),
|
|
48
|
+
handleOut,
|
|
49
|
+
]),
|
|
50
|
+
modelFree: lib.func("transcribe_model_free", "void", ["void *"]),
|
|
51
|
+
modelArch: lib.func("transcribe_model_arch_string", "str", ["void *"]),
|
|
52
|
+
modelVariant: lib.func("transcribe_model_variant_string", "str", ["void *"]),
|
|
53
|
+
modelBackend: lib.func("transcribe_model_backend", "str", ["void *"]),
|
|
54
|
+
modelSupports: lib.func("transcribe_model_supports", "bool", ["void *", "int"]),
|
|
55
|
+
tokenize: lib.func("transcribe_tokenize", "int", ["void *", "str", "int32_t *", "size_t"]),
|
|
56
|
+
capabilitiesInit: lib.func("transcribe_capabilities_init", "void", [
|
|
57
|
+
outp(T.transcribe_capabilities),
|
|
58
|
+
]),
|
|
59
|
+
modelGetCapabilities: lib.func("transcribe_model_get_capabilities", "int", [
|
|
60
|
+
"void *",
|
|
61
|
+
iop(T.transcribe_capabilities),
|
|
62
|
+
]),
|
|
63
|
+
// session
|
|
64
|
+
sessionParamsInit: lib.func("transcribe_session_params_init", "void", [
|
|
65
|
+
outp(T.transcribe_session_params),
|
|
66
|
+
]),
|
|
67
|
+
sessionInit: lib.func("transcribe_session_init", "int", [
|
|
68
|
+
"void *",
|
|
69
|
+
inp(T.transcribe_session_params),
|
|
70
|
+
handleOut,
|
|
71
|
+
]),
|
|
72
|
+
sessionFree: lib.func("transcribe_session_free", "void", ["void *"]),
|
|
73
|
+
sessionLimitsInit: lib.func("transcribe_session_limits_init", "void", [
|
|
74
|
+
outp(T.transcribe_session_limits),
|
|
75
|
+
]),
|
|
76
|
+
sessionGetLimits: lib.func("transcribe_session_get_limits", "int", [
|
|
77
|
+
"void *",
|
|
78
|
+
iop(T.transcribe_session_limits),
|
|
79
|
+
]),
|
|
80
|
+
setAbortCallback: lib.func("transcribe_set_abort_callback", "void", [
|
|
81
|
+
"void *",
|
|
82
|
+
"void *",
|
|
83
|
+
"void *",
|
|
84
|
+
]),
|
|
85
|
+
wasAborted: lib.func("transcribe_was_aborted", "bool", ["void *"]),
|
|
86
|
+
wasTruncated: lib.func("transcribe_was_truncated", "bool", ["void *"]),
|
|
87
|
+
// run (offline) + result accessors
|
|
88
|
+
runParamsInit: lib.func("transcribe_run_params_init", "void", [
|
|
89
|
+
outp(T.transcribe_run_params),
|
|
90
|
+
]),
|
|
91
|
+
run: lib.func("transcribe_run", "int", [
|
|
92
|
+
"void *",
|
|
93
|
+
inp("float"),
|
|
94
|
+
"int",
|
|
95
|
+
inp(T.transcribe_run_params),
|
|
96
|
+
]),
|
|
97
|
+
fullText: lib.func("transcribe_full_text", "str", ["void *"]),
|
|
98
|
+
detectedLanguage: lib.func("transcribe_detected_language", "str", ["void *"]),
|
|
99
|
+
returnedTimestampKind: lib.func("transcribe_returned_timestamp_kind", "int", ["void *"]),
|
|
100
|
+
nSegments: lib.func("transcribe_n_segments", "int", ["void *"]),
|
|
101
|
+
nWords: lib.func("transcribe_n_words", "int", ["void *"]),
|
|
102
|
+
nTokens: lib.func("transcribe_n_tokens", "int", ["void *"]),
|
|
103
|
+
segmentInit: lib.func("transcribe_segment_init", "void", [outp(T.transcribe_segment)]),
|
|
104
|
+
wordInit: lib.func("transcribe_word_init", "void", [outp(T.transcribe_word)]),
|
|
105
|
+
tokenInit: lib.func("transcribe_token_init", "void", [outp(T.transcribe_token)]),
|
|
106
|
+
getSegment: lib.func("transcribe_get_segment", "int", [
|
|
107
|
+
"void *",
|
|
108
|
+
"int",
|
|
109
|
+
iop(T.transcribe_segment),
|
|
110
|
+
]),
|
|
111
|
+
getWord: lib.func("transcribe_get_word", "int", ["void *", "int", iop(T.transcribe_word)]),
|
|
112
|
+
getToken: lib.func("transcribe_get_token", "int", ["void *", "int", iop(T.transcribe_token)]),
|
|
113
|
+
timingsInit: lib.func("transcribe_timings_init", "void", [outp(T.transcribe_timings)]),
|
|
114
|
+
getTimings: lib.func("transcribe_get_timings", "int", ["void *", iop(T.transcribe_timings)]),
|
|
115
|
+
// family extensions
|
|
116
|
+
modelAcceptsExtKind: lib.func("transcribe_model_accepts_ext_kind", "bool", [
|
|
117
|
+
"void *",
|
|
118
|
+
"int",
|
|
119
|
+
"uint32",
|
|
120
|
+
]),
|
|
121
|
+
whisperRunExtInit: lib.func("transcribe_whisper_run_ext_init", "void", [
|
|
122
|
+
outp(T.transcribe_whisper_run_ext),
|
|
123
|
+
]),
|
|
124
|
+
moonshineStreamingStreamExtInit: lib.func("transcribe_moonshine_streaming_stream_ext_init", "void", [outp(T.transcribe_moonshine_streaming_stream_ext)]),
|
|
125
|
+
parakeetStreamExtInit: lib.func("transcribe_parakeet_stream_ext_init", "void", [
|
|
126
|
+
outp(T.transcribe_parakeet_stream_ext),
|
|
127
|
+
]),
|
|
128
|
+
parakeetBufferedStreamExtInit: lib.func("transcribe_parakeet_buffered_stream_ext_init", "void", [
|
|
129
|
+
outp(T.transcribe_parakeet_buffered_stream_ext),
|
|
130
|
+
]),
|
|
131
|
+
voxtralRealtimeStreamExtInit: lib.func("transcribe_voxtral_realtime_stream_ext_init", "void", [
|
|
132
|
+
outp(T.transcribe_voxtral_realtime_stream_ext),
|
|
133
|
+
]),
|
|
134
|
+
// batch (offline)
|
|
135
|
+
runBatch: lib.func("transcribe_run_batch", "int", [
|
|
136
|
+
"void *",
|
|
137
|
+
"float **",
|
|
138
|
+
"int *",
|
|
139
|
+
"int",
|
|
140
|
+
inp(T.transcribe_run_params),
|
|
141
|
+
]),
|
|
142
|
+
batchNResults: lib.func("transcribe_batch_n_results", "int", ["void *"]),
|
|
143
|
+
batchStatus: lib.func("transcribe_batch_status", "int", ["void *", "int"]),
|
|
144
|
+
batchNSegments: lib.func("transcribe_batch_n_segments", "int", ["void *", "int"]),
|
|
145
|
+
batchGetSegment: lib.func("transcribe_batch_get_segment", "int", [
|
|
146
|
+
"void *",
|
|
147
|
+
"int",
|
|
148
|
+
"int",
|
|
149
|
+
iop(T.transcribe_segment),
|
|
150
|
+
]),
|
|
151
|
+
batchNWords: lib.func("transcribe_batch_n_words", "int", ["void *", "int"]),
|
|
152
|
+
batchGetWord: lib.func("transcribe_batch_get_word", "int", [
|
|
153
|
+
"void *",
|
|
154
|
+
"int",
|
|
155
|
+
"int",
|
|
156
|
+
iop(T.transcribe_word),
|
|
157
|
+
]),
|
|
158
|
+
batchNTokens: lib.func("transcribe_batch_n_tokens", "int", ["void *", "int"]),
|
|
159
|
+
batchGetToken: lib.func("transcribe_batch_get_token", "int", [
|
|
160
|
+
"void *",
|
|
161
|
+
"int",
|
|
162
|
+
"int",
|
|
163
|
+
iop(T.transcribe_token),
|
|
164
|
+
]),
|
|
165
|
+
batchFullText: lib.func("transcribe_batch_full_text", "str", ["void *", "int"]),
|
|
166
|
+
batchDetectedLanguage: lib.func("transcribe_batch_detected_language", "str", ["void *", "int"]),
|
|
167
|
+
batchReturnedTimestampKind: lib.func("transcribe_batch_returned_timestamp_kind", "int", [
|
|
168
|
+
"void *",
|
|
169
|
+
"int",
|
|
170
|
+
]),
|
|
171
|
+
batchGetTimings: lib.func("transcribe_batch_get_timings", "int", [
|
|
172
|
+
"void *",
|
|
173
|
+
"int",
|
|
174
|
+
iop(T.transcribe_timings),
|
|
175
|
+
]),
|
|
176
|
+
// streaming
|
|
177
|
+
streamParamsInit: lib.func("transcribe_stream_params_init", "void", [
|
|
178
|
+
outp(T.transcribe_stream_params),
|
|
179
|
+
]),
|
|
180
|
+
streamUpdateInit: lib.func("transcribe_stream_update_init", "void", [
|
|
181
|
+
outp(T.transcribe_stream_update),
|
|
182
|
+
]),
|
|
183
|
+
streamTextInit: lib.func("transcribe_stream_text_init", "void", [outp(T.transcribe_stream_text)]),
|
|
184
|
+
streamBegin: lib.func("transcribe_stream_begin", "int", [
|
|
185
|
+
"void *",
|
|
186
|
+
inp(T.transcribe_run_params),
|
|
187
|
+
inp(T.transcribe_stream_params),
|
|
188
|
+
]),
|
|
189
|
+
streamFeed: lib.func("transcribe_stream_feed", "int", [
|
|
190
|
+
"void *",
|
|
191
|
+
inp("float"),
|
|
192
|
+
"int",
|
|
193
|
+
iop(T.transcribe_stream_update),
|
|
194
|
+
]),
|
|
195
|
+
streamFinalize: lib.func("transcribe_stream_finalize", "int", [
|
|
196
|
+
"void *",
|
|
197
|
+
iop(T.transcribe_stream_update),
|
|
198
|
+
]),
|
|
199
|
+
streamGetText: lib.func("transcribe_stream_get_text", "int", [
|
|
200
|
+
"void *",
|
|
201
|
+
iop(T.transcribe_stream_text),
|
|
202
|
+
]),
|
|
203
|
+
streamReset: lib.func("transcribe_stream_reset", "void", ["void *"]),
|
|
204
|
+
streamGetState: lib.func("transcribe_stream_get_state", "int", ["void *"]),
|
|
205
|
+
streamRevision: lib.func("transcribe_stream_revision", "int", ["void *"]),
|
|
206
|
+
streamLastStatus: lib.func("transcribe_stream_last_status", "int", ["void *"]),
|
|
207
|
+
};
|
|
208
|
+
return { koffi, lib, T, F };
|
|
209
|
+
}
|
|
210
|
+
let abortProtoType = null;
|
|
211
|
+
let logProtoType = null;
|
|
212
|
+
/** koffi proto for the abort callback: `bool (void *userdata)`. */
|
|
213
|
+
export function abortProto() {
|
|
214
|
+
return (abortProtoType ??= koffi.proto("bool TranscribeAbortCb(void *udata)"));
|
|
215
|
+
}
|
|
216
|
+
/** koffi proto for the log callback: `void (int level, const char *msg, void *ud)`. */
|
|
217
|
+
export function logProto() {
|
|
218
|
+
return (logProtoType ??= koffi.proto("void TranscribeLogCb(int level, const char *msg, void *udata)"));
|
|
219
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,87 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TypeScript/Node.js bindings
|
|
2
|
+
* transcribe.cpp — TypeScript/Node.js bindings.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @see https://github.com/handy-computer/transcribe.cpp
|
|
4
|
+
* A koffi FFI binding over the shared native library: offline transcription and
|
|
5
|
+
* batch, streaming with committed/tentative text, typed per-family extensions,
|
|
6
|
+
* backend discovery, log routing, and cooperative cancellation.
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { setLogHandler, type LogHandler } from "./native.js";
|
|
9
|
+
import { TranscribeError } from "./errors.js";
|
|
10
|
+
import type { Backend, BackendInfo, BatchItem, Capabilities, FamilyExtension, Feature, ModelOptions, PcmLike, SessionLimits, SessionOptions, StreamOptions, StreamState, StreamText, StreamUpdate, TranscribeOptions, TranscriptionResult } from "./types.js";
|
|
11
|
+
export * from "./types.js";
|
|
12
|
+
export * from "./errors.js";
|
|
13
|
+
export { setLogHandler, type LogHandler };
|
|
14
|
+
export declare function version(): {
|
|
15
|
+
version: string;
|
|
16
|
+
commit: string;
|
|
17
|
+
headerHash: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function libraryPath(): string;
|
|
20
|
+
export declare function getAvailableBackends(): BackendInfo[];
|
|
21
|
+
export declare function backendAvailable(backend: Backend): boolean;
|
|
22
|
+
export declare class Session {
|
|
23
|
+
#private;
|
|
24
|
+
get limits(): SessionLimits;
|
|
25
|
+
/**
|
|
26
|
+
* Transcribe one clip. The input PCM is borrowed, not copied: native code
|
|
27
|
+
* reads it on a worker thread while this runs, so do not mutate the buffer
|
|
28
|
+
* (e.g. reuse a scratch array) until the returned promise resolves.
|
|
29
|
+
*/
|
|
30
|
+
run(pcm: PcmLike, opts?: TranscribeOptions): Promise<TranscriptionResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Offline batch transcription; each item carries its own success/failure.
|
|
33
|
+
* Inputs are borrowed, not copied: native code reads them on a worker thread
|
|
34
|
+
* while this runs, so do not mutate them until the returned promise resolves.
|
|
35
|
+
*/
|
|
36
|
+
runBatch(pcms: PcmLike[], opts?: TranscribeOptions): Promise<BatchItem[]>;
|
|
37
|
+
/** Begin a streaming session. The returned Stream owns the begin params. */
|
|
38
|
+
stream(opts?: StreamOptions): Promise<Stream>;
|
|
39
|
+
get wasAborted(): boolean;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
[Symbol.dispose](): void;
|
|
42
|
+
}
|
|
43
|
+
export declare class Stream {
|
|
44
|
+
#private;
|
|
45
|
+
/**
|
|
46
|
+
* Feed one chunk of PCM; returns the update snapshot. The chunk is borrowed,
|
|
47
|
+
* not copied: native code reads it on a worker thread while the feed runs, so
|
|
48
|
+
* do not mutate it (e.g. reuse a capture buffer) until the promise resolves.
|
|
49
|
+
*/
|
|
50
|
+
feed(pcm: PcmLike): Promise<StreamUpdate>;
|
|
51
|
+
/** Flush remaining audio and commit the final text. */
|
|
52
|
+
finalize(): Promise<StreamUpdate>;
|
|
53
|
+
/** Current text snapshot (copied at the boundary). */
|
|
54
|
+
get text(): StreamText;
|
|
55
|
+
get state(): StreamState;
|
|
56
|
+
get revision(): number;
|
|
57
|
+
/**
|
|
58
|
+
* The stream's recorded terminal failure, or `null` while it is healthy. Set
|
|
59
|
+
* after a feed()/finalize() transitions the stream to `"failed"`; reset by a
|
|
60
|
+
* new stream. Inspect it when `state === "failed"`.
|
|
61
|
+
*/
|
|
62
|
+
get lastStatus(): TranscribeError | null;
|
|
63
|
+
/** End the stream and return the session to idle. Idempotent. */
|
|
64
|
+
reset(): void;
|
|
65
|
+
[Symbol.dispose](): void;
|
|
66
|
+
}
|
|
67
|
+
export declare class TranscribeModel {
|
|
68
|
+
#private;
|
|
69
|
+
private constructor();
|
|
70
|
+
static load(path: string, opts?: ModelOptions): Promise<TranscribeModel>;
|
|
71
|
+
createSession(opts?: SessionOptions): Session;
|
|
72
|
+
/** Convenience: one session, one run, disposed after. */
|
|
73
|
+
transcribe(pcm: PcmLike, opts?: TranscribeOptions): Promise<TranscriptionResult>;
|
|
74
|
+
get capabilities(): Capabilities;
|
|
75
|
+
supports(feature: Feature): boolean;
|
|
76
|
+
/** Whether this model accepts the given family extension on its slot. */
|
|
77
|
+
accepts(family: FamilyExtension): boolean;
|
|
78
|
+
/** Tokenize plain UTF-8 text into the model's vocabulary (no special tokens). */
|
|
79
|
+
tokenize(text: string): Int32Array;
|
|
80
|
+
get arch(): string;
|
|
81
|
+
get variant(): string;
|
|
82
|
+
get backend(): string;
|
|
83
|
+
dispose(): void;
|
|
84
|
+
[Symbol.dispose](): void;
|
|
85
|
+
}
|
|
86
|
+
/** One-shot: load (or reuse) a model, transcribe, return the result. */
|
|
87
|
+
export declare function transcribe(model: TranscribeModel | string, pcm: PcmLike, opts?: TranscribeOptions & ModelOptions): Promise<TranscriptionResult>;
|