transcribe-cpp 0.1.3 → 0.2.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 +12 -3
- package/dist/_generated.d.ts +13 -2
- package/dist/_generated.js +40 -15
- package/dist/ffi.js +32 -10
- package/dist/index.js +72 -12
- package/dist/types.d.ts +39 -13
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -12,6 +12,10 @@ A matching prebuilt native package is selected automatically for your
|
|
|
12
12
|
platform (`@transcribe-cpp/<platform>`); there is nothing to compile and no
|
|
13
13
|
environment variables to set.
|
|
14
14
|
|
|
15
|
+
Upgrading from 0.1? See the
|
|
16
|
+
[0.2 migration guide](https://github.com/handy-computer/transcribe.cpp/blob/main/docs/migrating-to-0.2.md),
|
|
17
|
+
including the replacement of `gpuDevice` with exact device objects.
|
|
18
|
+
|
|
15
19
|
## Quickstart
|
|
16
20
|
|
|
17
21
|
```ts
|
|
@@ -101,10 +105,15 @@ the model lease). Disposal is idempotent and order-independent.
|
|
|
101
105
|
```ts
|
|
102
106
|
import { getAvailableBackends, backendAvailable } from "transcribe-cpp";
|
|
103
107
|
|
|
104
|
-
getAvailableBackends();
|
|
105
|
-
backendAvailable("
|
|
108
|
+
const devices = getAvailableBackends();
|
|
109
|
+
backendAvailable("rocm"); // boolean — never throws
|
|
106
110
|
|
|
107
|
-
|
|
111
|
+
// Policy selection: first matching ROCm device.
|
|
112
|
+
const automatic = await TranscribeModel.load("model.gguf", { backend: "rocm" });
|
|
113
|
+
// Exact selection: use this process-local CPU device or fail without fallback.
|
|
114
|
+
const cpu = devices.find((device) => device.deviceType === "cpu");
|
|
115
|
+
if (!cpu) throw new Error("CPU device is not registered");
|
|
116
|
+
const exact = await TranscribeModel.load("model.gguf", { device: cpu });
|
|
108
117
|
```
|
|
109
118
|
|
|
110
119
|
`backend` defaults to `"auto"` (best accelerator, else CPU). A missing Vulkan
|
package/dist/_generated.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const PUBLIC_HEADER_HASH = "
|
|
1
|
+
export declare const PUBLIC_HEADER_HASH = "7df72bf9e667b8c2";
|
|
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;
|
|
@@ -31,7 +31,8 @@ export declare const TRANSCRIBE_ABI_STREAM_UPDATE = 9;
|
|
|
31
31
|
export declare const TRANSCRIBE_ABI_STREAM_TEXT = 10;
|
|
32
32
|
export declare const TRANSCRIBE_ABI_SESSION_LIMITS = 11;
|
|
33
33
|
export declare const TRANSCRIBE_ABI_EXT = 12;
|
|
34
|
-
export declare const
|
|
34
|
+
export declare const TRANSCRIBE_ABI_DEVICE_INFO = 13;
|
|
35
|
+
export declare const TRANSCRIBE_ABI_SPEAKER_SEGMENT = 14;
|
|
35
36
|
export declare const TRANSCRIBE_LOG_LEVEL_NONE = 0;
|
|
36
37
|
export declare const TRANSCRIBE_LOG_LEVEL_INFO = 1;
|
|
37
38
|
export declare const TRANSCRIBE_LOG_LEVEL_WARN = 2;
|
|
@@ -54,6 +55,9 @@ export declare const TRANSCRIBE_PNC_MODE_ON = 2;
|
|
|
54
55
|
export declare const TRANSCRIBE_ITN_MODE_DEFAULT = 0;
|
|
55
56
|
export declare const TRANSCRIBE_ITN_MODE_OFF = 1;
|
|
56
57
|
export declare const TRANSCRIBE_ITN_MODE_ON = 2;
|
|
58
|
+
export declare const TRANSCRIBE_DIARIZE_MODE_DEFAULT = 0;
|
|
59
|
+
export declare const TRANSCRIBE_DIARIZE_MODE_OFF = 1;
|
|
60
|
+
export declare const TRANSCRIBE_DIARIZE_MODE_ON = 2;
|
|
57
61
|
export declare const TRANSCRIBE_EXT_SLOT_RUN = 0;
|
|
58
62
|
export declare const TRANSCRIBE_EXT_SLOT_STREAM = 1;
|
|
59
63
|
export declare const TRANSCRIBE_BACKEND_AUTO = 0;
|
|
@@ -62,6 +66,7 @@ export declare const TRANSCRIBE_BACKEND_METAL = 2;
|
|
|
62
66
|
export declare const TRANSCRIBE_BACKEND_VULKAN = 3;
|
|
63
67
|
export declare const TRANSCRIBE_BACKEND_CPU_ACCEL = 4;
|
|
64
68
|
export declare const TRANSCRIBE_BACKEND_CUDA = 5;
|
|
69
|
+
export declare const TRANSCRIBE_BACKEND_ROCM = 6;
|
|
65
70
|
export declare const TRANSCRIBE_DEVICE_TYPE_CPU = 0;
|
|
66
71
|
export declare const TRANSCRIBE_DEVICE_TYPE_GPU = 1;
|
|
67
72
|
export declare const TRANSCRIBE_DEVICE_TYPE_IGPU = 2;
|
|
@@ -72,6 +77,7 @@ export declare const TRANSCRIBE_FEATURE_LONG_FORM = 2;
|
|
|
72
77
|
export declare const TRANSCRIBE_FEATURE_CANCELLATION = 3;
|
|
73
78
|
export declare const TRANSCRIBE_FEATURE_PNC = 4;
|
|
74
79
|
export declare const TRANSCRIBE_FEATURE_ITN = 5;
|
|
80
|
+
export declare const TRANSCRIBE_FEATURE_DIARIZATION = 6;
|
|
75
81
|
export declare const TRANSCRIBE_STREAM_IDLE = 0;
|
|
76
82
|
export declare const TRANSCRIBE_STREAM_ACTIVE = 1;
|
|
77
83
|
export declare const TRANSCRIBE_STREAM_FINISHED = 2;
|
|
@@ -79,11 +85,16 @@ export declare const TRANSCRIBE_STREAM_FAILED = 3;
|
|
|
79
85
|
export declare const TRANSCRIBE_STREAM_COMMIT_AUTO = 0;
|
|
80
86
|
export declare const TRANSCRIBE_STREAM_COMMIT_ON_FINALIZE = 1;
|
|
81
87
|
export declare const TRANSCRIBE_STREAM_COMMIT_STABLE_PREFIX = 2;
|
|
88
|
+
export declare const TRANSCRIBE_SORTFORMER_PRESET_DEFAULT = 0;
|
|
89
|
+
export declare const TRANSCRIBE_SORTFORMER_PRESET_VERY_HIGH_LATENCY = 1;
|
|
90
|
+
export declare const TRANSCRIBE_SORTFORMER_PRESET_HIGH_LATENCY = 2;
|
|
91
|
+
export declare const TRANSCRIBE_SORTFORMER_PRESET_LOW_LATENCY = 3;
|
|
82
92
|
export declare const TRANSCRIBE_WHISPER_PROMPT_FIRST_SEGMENT = 0;
|
|
83
93
|
export declare const TRANSCRIBE_WHISPER_PROMPT_ALL_SEGMENTS = 1;
|
|
84
94
|
export declare const TRANSCRIBE_EXT_KIND_MOONSHINE_STREAMING_STREAM = 1414746957;
|
|
85
95
|
export declare const TRANSCRIBE_EXT_KIND_PARAKEET_BUFFERED_STREAM = 1396853584;
|
|
86
96
|
export declare const TRANSCRIBE_EXT_KIND_PARAKEET_STREAM = 1414744912;
|
|
97
|
+
export declare const TRANSCRIBE_EXT_KIND_SORTFORMER_STREAM = 1414743635;
|
|
87
98
|
export declare const TRANSCRIBE_EXT_KIND_VOXTRAL_REALTIME_STREAM = 1414746710;
|
|
88
99
|
export declare const TRANSCRIBE_EXT_KIND_WHISPER_RUN = 1314015319;
|
|
89
100
|
export interface StructLayout {
|
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 = "7df72bf9e667b8c2";
|
|
14
14
|
// === enum constants ===
|
|
15
15
|
export const TRANSCRIBE_OK = 0;
|
|
16
16
|
export const TRANSCRIBE_ERR_INVALID_ARG = 1;
|
|
@@ -44,7 +44,8 @@ export const TRANSCRIBE_ABI_STREAM_UPDATE = 9;
|
|
|
44
44
|
export const TRANSCRIBE_ABI_STREAM_TEXT = 10;
|
|
45
45
|
export const TRANSCRIBE_ABI_SESSION_LIMITS = 11;
|
|
46
46
|
export const TRANSCRIBE_ABI_EXT = 12;
|
|
47
|
-
export const
|
|
47
|
+
export const TRANSCRIBE_ABI_DEVICE_INFO = 13;
|
|
48
|
+
export const TRANSCRIBE_ABI_SPEAKER_SEGMENT = 14;
|
|
48
49
|
export const TRANSCRIBE_LOG_LEVEL_NONE = 0;
|
|
49
50
|
export const TRANSCRIBE_LOG_LEVEL_INFO = 1;
|
|
50
51
|
export const TRANSCRIBE_LOG_LEVEL_WARN = 2;
|
|
@@ -67,6 +68,9 @@ export const TRANSCRIBE_PNC_MODE_ON = 2;
|
|
|
67
68
|
export const TRANSCRIBE_ITN_MODE_DEFAULT = 0;
|
|
68
69
|
export const TRANSCRIBE_ITN_MODE_OFF = 1;
|
|
69
70
|
export const TRANSCRIBE_ITN_MODE_ON = 2;
|
|
71
|
+
export const TRANSCRIBE_DIARIZE_MODE_DEFAULT = 0;
|
|
72
|
+
export const TRANSCRIBE_DIARIZE_MODE_OFF = 1;
|
|
73
|
+
export const TRANSCRIBE_DIARIZE_MODE_ON = 2;
|
|
70
74
|
export const TRANSCRIBE_EXT_SLOT_RUN = 0;
|
|
71
75
|
export const TRANSCRIBE_EXT_SLOT_STREAM = 1;
|
|
72
76
|
export const TRANSCRIBE_BACKEND_AUTO = 0;
|
|
@@ -75,6 +79,7 @@ export const TRANSCRIBE_BACKEND_METAL = 2;
|
|
|
75
79
|
export const TRANSCRIBE_BACKEND_VULKAN = 3;
|
|
76
80
|
export const TRANSCRIBE_BACKEND_CPU_ACCEL = 4;
|
|
77
81
|
export const TRANSCRIBE_BACKEND_CUDA = 5;
|
|
82
|
+
export const TRANSCRIBE_BACKEND_ROCM = 6;
|
|
78
83
|
export const TRANSCRIBE_DEVICE_TYPE_CPU = 0;
|
|
79
84
|
export const TRANSCRIBE_DEVICE_TYPE_GPU = 1;
|
|
80
85
|
export const TRANSCRIBE_DEVICE_TYPE_IGPU = 2;
|
|
@@ -85,6 +90,7 @@ export const TRANSCRIBE_FEATURE_LONG_FORM = 2;
|
|
|
85
90
|
export const TRANSCRIBE_FEATURE_CANCELLATION = 3;
|
|
86
91
|
export const TRANSCRIBE_FEATURE_PNC = 4;
|
|
87
92
|
export const TRANSCRIBE_FEATURE_ITN = 5;
|
|
93
|
+
export const TRANSCRIBE_FEATURE_DIARIZATION = 6;
|
|
88
94
|
export const TRANSCRIBE_STREAM_IDLE = 0;
|
|
89
95
|
export const TRANSCRIBE_STREAM_ACTIVE = 1;
|
|
90
96
|
export const TRANSCRIBE_STREAM_FINISHED = 2;
|
|
@@ -92,39 +98,46 @@ export const TRANSCRIBE_STREAM_FAILED = 3;
|
|
|
92
98
|
export const TRANSCRIBE_STREAM_COMMIT_AUTO = 0;
|
|
93
99
|
export const TRANSCRIBE_STREAM_COMMIT_ON_FINALIZE = 1;
|
|
94
100
|
export const TRANSCRIBE_STREAM_COMMIT_STABLE_PREFIX = 2;
|
|
101
|
+
export const TRANSCRIBE_SORTFORMER_PRESET_DEFAULT = 0;
|
|
102
|
+
export const TRANSCRIBE_SORTFORMER_PRESET_VERY_HIGH_LATENCY = 1;
|
|
103
|
+
export const TRANSCRIBE_SORTFORMER_PRESET_HIGH_LATENCY = 2;
|
|
104
|
+
export const TRANSCRIBE_SORTFORMER_PRESET_LOW_LATENCY = 3;
|
|
95
105
|
export const TRANSCRIBE_WHISPER_PROMPT_FIRST_SEGMENT = 0;
|
|
96
106
|
export const TRANSCRIBE_WHISPER_PROMPT_ALL_SEGMENTS = 1;
|
|
97
107
|
// === macro constants (integer object-like macros) ===
|
|
98
108
|
export const TRANSCRIBE_EXT_KIND_MOONSHINE_STREAMING_STREAM = 1414746957;
|
|
99
109
|
export const TRANSCRIBE_EXT_KIND_PARAKEET_BUFFERED_STREAM = 1396853584;
|
|
100
110
|
export const TRANSCRIBE_EXT_KIND_PARAKEET_STREAM = 1414744912;
|
|
111
|
+
export const TRANSCRIBE_EXT_KIND_SORTFORMER_STREAM = 1414743635;
|
|
101
112
|
export const TRANSCRIBE_EXT_KIND_VOXTRAL_REALTIME_STREAM = 1414746710;
|
|
102
113
|
export const TRANSCRIBE_EXT_KIND_WHISPER_RUN = 1314015319;
|
|
103
114
|
export const STRUCT_LAYOUT = {
|
|
104
115
|
'transcribe_ext': { size: 16, align: 8, offsets: { 'size': 0, 'kind': 8 } },
|
|
105
|
-
'
|
|
106
|
-
'transcribe_model_load_params': { size:
|
|
116
|
+
'transcribe_device_info': { 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 } },
|
|
117
|
+
'transcribe_model_load_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'backend': 8, 'device': 16 } },
|
|
107
118
|
'transcribe_session_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'n_threads': 8, 'kv_type': 12, 'n_ctx': 16 } },
|
|
108
|
-
'transcribe_run_params': { size:
|
|
119
|
+
'transcribe_run_params': { size: 72, align: 8, offsets: { 'struct_size': 0, 'task': 8, 'timestamps': 12, 'pnc': 16, 'itn': 20, 'diarize': 24, 'language': 32, 'target_language': 40, 'keep_special_tags': 48, 'family': 56, 'spec_k_drafts': 64 } },
|
|
109
120
|
'transcribe_capabilities': { size: 56, align: 8, offsets: { 'struct_size': 0, 'native_sample_rate': 8, 'n_languages': 12, 'languages': 16, 'max_timestamp_kind': 24, 'supports_language_detect': 28, 'supports_translate': 29, 'supports_streaming': 30, 'supports_spec_decode': 31, 'max_audio_ms': 32, 'n_translate_target_languages': 40, 'translate_target_languages': 48 } },
|
|
110
121
|
'transcribe_session_limits': { size: 32, align: 8, offsets: { 'struct_size': 0, 'effective_n_ctx': 8, 'effective_max_audio_ms': 16, 'max_kv_bytes': 24 } },
|
|
111
122
|
'transcribe_stream_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'family': 8, 'commit_policy': 16, 'stable_prefix_agreement_n': 20 } },
|
|
112
123
|
'transcribe_stream_update': { size: 48, align: 8, offsets: { 'struct_size': 0, 'result_changed': 8, 'is_final': 9, 'revision': 12, 'input_received_ms': 16, 'audio_committed_ms': 24, 'buffered_ms': 32, 'committed_changed': 40, 'tentative_changed': 41 } },
|
|
113
124
|
'transcribe_stream_text': { size: 64, align: 8, offsets: { 'struct_size': 0, 'full_text': 8, 'full_text_bytes': 16, 'committed_text': 24, 'committed_text_bytes': 32, 'tentative_text': 40, 'tentative_text_bytes': 48, 'raw_tentative_start_bytes': 56 } },
|
|
114
125
|
'transcribe_timings': { size: 24, align: 8, offsets: { 'struct_size': 0, 'load_ms': 8, 'mel_ms': 12, 'encode_ms': 16, 'decode_ms': 20 } },
|
|
115
|
-
'transcribe_segment': { size:
|
|
126
|
+
'transcribe_segment': { size: 56, align: 8, offsets: { 'struct_size': 0, 't0_ms': 8, 't1_ms': 16, 'first_word': 24, 'n_words': 28, 'first_token': 32, 'n_tokens': 36, 'text': 40, 'speaker_id': 48 } },
|
|
116
127
|
'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 } },
|
|
117
128
|
'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 } },
|
|
129
|
+
'transcribe_speaker_segment': { size: 32, align: 8, offsets: { 'struct_size': 0, 't0_ms': 8, 't1_ms': 16, 'speaker_id': 24, 'p': 28 } },
|
|
118
130
|
'transcribe_moonshine_streaming_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'min_decode_interval_ms': 16 } },
|
|
119
131
|
'transcribe_parakeet_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'att_context_right': 16 } },
|
|
120
132
|
'transcribe_parakeet_buffered_stream_ext': { size: 32, align: 8, offsets: { 'ext': 0, 'left_ms': 16, 'chunk_ms': 20, 'right_ms': 24 } },
|
|
133
|
+
'transcribe_sortformer_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'preset': 16 } },
|
|
121
134
|
'transcribe_voxtral_realtime_stream_ext': { size: 24, align: 8, offsets: { 'ext': 0, 'num_delay_tokens': 16, 'min_decode_interval_ms': 20 } },
|
|
122
135
|
'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 } },
|
|
123
136
|
'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 } },
|
|
124
137
|
};
|
|
125
138
|
export const ABI_STRUCT_IDS = {
|
|
126
139
|
'transcribe_ext': 12,
|
|
127
|
-
'
|
|
140
|
+
'transcribe_device_info': 13,
|
|
128
141
|
'transcribe_model_load_params': 0,
|
|
129
142
|
'transcribe_session_params': 1,
|
|
130
143
|
'transcribe_run_params': 2,
|
|
@@ -137,27 +150,30 @@ export const ABI_STRUCT_IDS = {
|
|
|
137
150
|
'transcribe_segment': 6,
|
|
138
151
|
'transcribe_word': 7,
|
|
139
152
|
'transcribe_token': 8,
|
|
153
|
+
'transcribe_speaker_segment': 14,
|
|
140
154
|
};
|
|
141
155
|
// Build koffi struct types; returns a name -> koffi.IKoffiCType map.
|
|
142
156
|
export function defineTypes(koffi) {
|
|
143
157
|
const T = {};
|
|
144
158
|
T['transcribe_ext'] = koffi.struct({ size: 'uint64_t', kind: 'uint32_t' });
|
|
145
|
-
T['
|
|
146
|
-
T['transcribe_model_load_params'] = koffi.struct({ struct_size: 'uint64_t', backend: 'int',
|
|
159
|
+
T['transcribe_device_info'] = 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' });
|
|
160
|
+
T['transcribe_model_load_params'] = koffi.struct({ struct_size: 'uint64_t', backend: 'int', device: 'void *' });
|
|
147
161
|
T['transcribe_session_params'] = koffi.struct({ struct_size: 'uint64_t', n_threads: 'int', kv_type: 'int', n_ctx: 'int32_t' });
|
|
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' });
|
|
162
|
+
T['transcribe_run_params'] = koffi.struct({ struct_size: 'uint64_t', task: 'int', timestamps: 'int', pnc: 'int', itn: 'int', diarize: 'int', language: 'char *', target_language: 'char *', keep_special_tags: 'bool', family: 'void *', spec_k_drafts: 'int32_t' });
|
|
149
163
|
T['transcribe_capabilities'] = koffi.struct({ struct_size: 'uint64_t', native_sample_rate: 'int32_t', n_languages: 'int', languages: 'void *', max_timestamp_kind: 'int', supports_language_detect: 'bool', supports_translate: 'bool', supports_streaming: 'bool', supports_spec_decode: 'bool', max_audio_ms: 'int64_t', n_translate_target_languages: 'int', translate_target_languages: 'void *' });
|
|
150
164
|
T['transcribe_session_limits'] = koffi.struct({ struct_size: 'uint64_t', effective_n_ctx: 'int32_t', effective_max_audio_ms: 'int64_t', max_kv_bytes: 'int64_t' });
|
|
151
165
|
T['transcribe_stream_params'] = koffi.struct({ struct_size: 'uint64_t', family: 'void *', commit_policy: 'int', stable_prefix_agreement_n: 'uint32_t' });
|
|
152
166
|
T['transcribe_stream_update'] = koffi.struct({ struct_size: 'uint64_t', result_changed: 'bool', is_final: 'bool', revision: 'int32_t', input_received_ms: 'int64_t', audio_committed_ms: 'int64_t', buffered_ms: 'int64_t', committed_changed: 'bool', tentative_changed: 'bool' });
|
|
153
167
|
T['transcribe_stream_text'] = koffi.struct({ struct_size: 'uint64_t', full_text: 'char *', full_text_bytes: 'uint64_t', committed_text: 'char *', committed_text_bytes: 'uint64_t', tentative_text: 'char *', tentative_text_bytes: 'uint64_t', raw_tentative_start_bytes: 'uint64_t' });
|
|
154
168
|
T['transcribe_timings'] = koffi.struct({ struct_size: 'uint64_t', load_ms: 'float', mel_ms: 'float', encode_ms: 'float', decode_ms: 'float' });
|
|
155
|
-
T['transcribe_segment'] = koffi.struct({ struct_size: 'uint64_t', t0_ms: 'int64_t', t1_ms: 'int64_t', first_word: 'int', n_words: 'int', first_token: 'int', n_tokens: 'int', text: 'char *' });
|
|
169
|
+
T['transcribe_segment'] = koffi.struct({ struct_size: 'uint64_t', t0_ms: 'int64_t', t1_ms: 'int64_t', first_word: 'int', n_words: 'int', first_token: 'int', n_tokens: 'int', text: 'char *', speaker_id: 'int32_t' });
|
|
156
170
|
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 *' });
|
|
157
171
|
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 *' });
|
|
172
|
+
T['transcribe_speaker_segment'] = koffi.struct({ struct_size: 'uint64_t', t0_ms: 'int64_t', t1_ms: 'int64_t', speaker_id: 'int32_t', p: 'float' });
|
|
158
173
|
T['transcribe_moonshine_streaming_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], min_decode_interval_ms: 'int32_t' });
|
|
159
174
|
T['transcribe_parakeet_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], att_context_right: 'int32_t' });
|
|
160
175
|
T['transcribe_parakeet_buffered_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], left_ms: 'int32_t', chunk_ms: 'int32_t', right_ms: 'int32_t' });
|
|
176
|
+
T['transcribe_sortformer_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], preset: 'int' });
|
|
161
177
|
T['transcribe_voxtral_realtime_stream_ext'] = koffi.struct({ ext: T['transcribe_ext'], num_delay_tokens: 'int32_t', min_decode_interval_ms: 'int32_t' });
|
|
162
178
|
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' });
|
|
163
179
|
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' });
|
|
@@ -167,28 +183,33 @@ export const FUNCTION_SIGNATURES = {
|
|
|
167
183
|
'transcribe_abi_struct_align': { ret: 'size_t', args: ['transcribe_abi_struct'] },
|
|
168
184
|
'transcribe_abi_struct_size': { ret: 'size_t', args: ['transcribe_abi_struct'] },
|
|
169
185
|
'transcribe_backend_available': { ret: '_Bool', args: ['transcribe_backend_request'] },
|
|
170
|
-
'transcribe_backend_device_count': { ret: 'int', args: [] },
|
|
171
|
-
'transcribe_backend_device_init': { ret: 'void', args: ['struct transcribe_backend_device *'] },
|
|
172
186
|
'transcribe_batch_detected_language': { ret: 'const char *', args: ['const struct transcribe_session *', 'int'] },
|
|
173
187
|
'transcribe_batch_full_text': { ret: 'const char *', args: ['const struct transcribe_session *', 'int'] },
|
|
174
188
|
'transcribe_batch_get_segment': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'int', 'struct transcribe_segment *'] },
|
|
189
|
+
'transcribe_batch_get_speaker_segment': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'int', 'struct transcribe_speaker_segment *'] },
|
|
175
190
|
'transcribe_batch_get_timings': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'struct transcribe_timings *'] },
|
|
176
191
|
'transcribe_batch_get_token': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'int', 'struct transcribe_token *'] },
|
|
177
192
|
'transcribe_batch_get_word': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'int', 'struct transcribe_word *'] },
|
|
178
193
|
'transcribe_batch_n_results': { ret: 'int', args: ['const struct transcribe_session *'] },
|
|
179
194
|
'transcribe_batch_n_segments': { ret: 'int', args: ['const struct transcribe_session *', 'int'] },
|
|
195
|
+
'transcribe_batch_n_speaker_segments': { ret: 'int', args: ['const struct transcribe_session *', 'int'] },
|
|
180
196
|
'transcribe_batch_n_tokens': { ret: 'int', args: ['const struct transcribe_session *', 'int'] },
|
|
181
197
|
'transcribe_batch_n_words': { ret: 'int', args: ['const struct transcribe_session *', 'int'] },
|
|
198
|
+
'transcribe_batch_raw_text': { ret: 'const char *', args: ['const struct transcribe_session *', 'int'] },
|
|
182
199
|
'transcribe_batch_returned_timestamp_kind': { ret: 'transcribe_timestamp_kind', args: ['const struct transcribe_session *', 'int'] },
|
|
183
200
|
'transcribe_batch_status': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int'] },
|
|
184
201
|
'transcribe_capabilities_init': { ret: 'void', args: ['struct transcribe_capabilities *'] },
|
|
185
202
|
'transcribe_close': { ret: 'void', args: ['struct transcribe_session *'] },
|
|
186
203
|
'transcribe_detected_language': { ret: 'const char *', args: ['const struct transcribe_session *'] },
|
|
204
|
+
'transcribe_device_count': { ret: 'int', args: [] },
|
|
205
|
+
'transcribe_device_get': { ret: 'transcribe_device_t', args: ['int'] },
|
|
206
|
+
'transcribe_device_get_info': { ret: 'transcribe_status', args: ['transcribe_device_t', 'struct transcribe_device_info *'] },
|
|
207
|
+
'transcribe_device_info_init': { ret: 'void', args: ['struct transcribe_device_info *'] },
|
|
187
208
|
'transcribe_ext_check': { ret: 'transcribe_status', args: ['const struct transcribe_ext *', 'uint32_t', 'uint64_t'] },
|
|
188
209
|
'transcribe_full_text': { ret: 'const char *', args: ['const struct transcribe_session *'] },
|
|
189
|
-
'transcribe_get_backend_device': { ret: 'transcribe_status', args: ['int', 'struct transcribe_backend_device *'] },
|
|
190
210
|
'transcribe_get_model': { ret: 'const struct transcribe_model *', args: ['const struct transcribe_session *'] },
|
|
191
211
|
'transcribe_get_segment': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'struct transcribe_segment *'] },
|
|
212
|
+
'transcribe_get_speaker_segment': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'struct transcribe_speaker_segment *'] },
|
|
192
213
|
'transcribe_get_timings': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'struct transcribe_timings *'] },
|
|
193
214
|
'transcribe_get_token': { ret: 'transcribe_status', args: ['const struct transcribe_session *', 'int', 'struct transcribe_token *'] },
|
|
194
215
|
'transcribe_get_whisper_chunk_count': { ret: 'int', args: ['const struct transcribe_session *'] },
|
|
@@ -200,9 +221,9 @@ export const FUNCTION_SIGNATURES = {
|
|
|
200
221
|
'transcribe_model_accepts_ext_kind': { ret: '_Bool', args: ['const struct transcribe_model *', 'transcribe_ext_slot', 'uint32_t'] },
|
|
201
222
|
'transcribe_model_arch_string': { ret: 'const char *', args: ['const struct transcribe_model *'] },
|
|
202
223
|
'transcribe_model_backend': { ret: 'const char *', args: ['const struct transcribe_model *'] },
|
|
224
|
+
'transcribe_model_device': { ret: 'transcribe_device_t', args: ['const struct transcribe_model *'] },
|
|
203
225
|
'transcribe_model_free': { ret: 'void', args: ['struct transcribe_model *'] },
|
|
204
226
|
'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 *'] },
|
|
206
227
|
'transcribe_model_load_file': { ret: 'transcribe_status', args: ['const char *', 'const struct transcribe_model_load_params *', 'struct transcribe_model **'] },
|
|
207
228
|
'transcribe_model_load_params_init': { ret: 'void', args: ['struct transcribe_model_load_params *'] },
|
|
208
229
|
'transcribe_model_meta_val_str': { ret: 'const char *', args: ['const struct transcribe_model *', 'const char *'] },
|
|
@@ -210,12 +231,14 @@ export const FUNCTION_SIGNATURES = {
|
|
|
210
231
|
'transcribe_model_variant_string': { ret: 'const char *', args: ['const struct transcribe_model *'] },
|
|
211
232
|
'transcribe_moonshine_streaming_stream_ext_init': { ret: 'void', args: ['struct transcribe_moonshine_streaming_stream_ext *'] },
|
|
212
233
|
'transcribe_n_segments': { ret: 'int', args: ['const struct transcribe_session *'] },
|
|
234
|
+
'transcribe_n_speaker_segments': { ret: 'int', args: ['const struct transcribe_session *'] },
|
|
213
235
|
'transcribe_n_tokens': { ret: 'int', args: ['const struct transcribe_session *'] },
|
|
214
236
|
'transcribe_n_words': { ret: 'int', args: ['const struct transcribe_session *'] },
|
|
215
237
|
'transcribe_open': { ret: 'transcribe_status', args: ['const char *', 'const struct transcribe_model_load_params *', 'const struct transcribe_session_params *', 'struct transcribe_session **'] },
|
|
216
238
|
'transcribe_parakeet_buffered_stream_ext_init': { ret: 'void', args: ['struct transcribe_parakeet_buffered_stream_ext *'] },
|
|
217
239
|
'transcribe_parakeet_stream_ext_init': { ret: 'void', args: ['struct transcribe_parakeet_stream_ext *'] },
|
|
218
240
|
'transcribe_print_timings': { ret: 'void', args: ['const struct transcribe_session *'] },
|
|
241
|
+
'transcribe_raw_text': { ret: 'const char *', args: ['const struct transcribe_session *'] },
|
|
219
242
|
'transcribe_reset_timings': { ret: 'void', args: ['struct transcribe_session *'] },
|
|
220
243
|
'transcribe_returned_timestamp_kind': { ret: 'transcribe_timestamp_kind', args: ['const struct transcribe_session *'] },
|
|
221
244
|
'transcribe_run': { ret: 'transcribe_status', args: ['struct transcribe_session *', 'const float *', 'int', 'const struct transcribe_run_params *'] },
|
|
@@ -228,6 +251,8 @@ export const FUNCTION_SIGNATURES = {
|
|
|
228
251
|
'transcribe_session_limits_init': { ret: 'void', args: ['struct transcribe_session_limits *'] },
|
|
229
252
|
'transcribe_session_params_init': { ret: 'void', args: ['struct transcribe_session_params *'] },
|
|
230
253
|
'transcribe_set_abort_callback': { ret: 'void', args: ['struct transcribe_session *', 'transcribe_abort_callback', 'void *'] },
|
|
254
|
+
'transcribe_sortformer_stream_ext_init': { ret: 'void', args: ['struct transcribe_sortformer_stream_ext *'] },
|
|
255
|
+
'transcribe_speaker_segment_init': { ret: 'void', args: ['struct transcribe_speaker_segment *'] },
|
|
231
256
|
'transcribe_status_string': { ret: 'const char *', args: ['int'] },
|
|
232
257
|
'transcribe_stream_begin': { ret: 'transcribe_status', args: ['struct transcribe_session *', 'const struct transcribe_run_params *', 'const struct transcribe_stream_params *'] },
|
|
233
258
|
'transcribe_stream_feed': { ret: 'transcribe_status', args: ['struct transcribe_session *', 'const float *', 'int', 'struct transcribe_stream_update *'] },
|
package/dist/ffi.js
CHANGED
|
@@ -27,13 +27,14 @@ export function bindLibrary(libraryPath) {
|
|
|
27
27
|
// backends
|
|
28
28
|
initBackends: lib.func("transcribe_init_backends", "int", ["str"]),
|
|
29
29
|
initBackendsDefault: lib.func("transcribe_init_backends_default", "int", []),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
deviceCount: lib.func("transcribe_device_count", "int", []),
|
|
31
|
+
deviceGet: lib.func("transcribe_device_get", "void *", ["int"]),
|
|
32
|
+
deviceInfoInit: lib.func("transcribe_device_info_init", "void", [
|
|
33
|
+
outp(T.transcribe_device_info),
|
|
33
34
|
]),
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
iop(T.
|
|
35
|
+
deviceGetInfo: lib.func("transcribe_device_get_info", "int", [
|
|
36
|
+
"void *",
|
|
37
|
+
iop(T.transcribe_device_info),
|
|
37
38
|
]),
|
|
38
39
|
backendAvailable: lib.func("transcribe_backend_available", "bool", ["int"]),
|
|
39
40
|
// logging (callback pointer comes from koffi.register -> passed as void*)
|
|
@@ -51,10 +52,7 @@ export function bindLibrary(libraryPath) {
|
|
|
51
52
|
modelArch: lib.func("transcribe_model_arch_string", "str", ["void *"]),
|
|
52
53
|
modelVariant: lib.func("transcribe_model_variant_string", "str", ["void *"]),
|
|
53
54
|
modelBackend: lib.func("transcribe_model_backend", "str", ["void *"]),
|
|
54
|
-
|
|
55
|
-
"void *",
|
|
56
|
-
iop(T.transcribe_backend_device),
|
|
57
|
-
]),
|
|
55
|
+
modelDevice: lib.func("transcribe_model_device", "void *", ["void *"]),
|
|
58
56
|
modelSupports: lib.func("transcribe_model_supports", "bool", ["void *", "int"]),
|
|
59
57
|
tokenize: lib.func("transcribe_tokenize", "int", ["void *", "str", "int32_t *", "size_t"]),
|
|
60
58
|
capabilitiesInit: lib.func("transcribe_capabilities_init", "void", [
|
|
@@ -99,14 +97,19 @@ export function bindLibrary(libraryPath) {
|
|
|
99
97
|
inp(T.transcribe_run_params),
|
|
100
98
|
]),
|
|
101
99
|
fullText: lib.func("transcribe_full_text", "str", ["void *"]),
|
|
100
|
+
rawText: lib.func("transcribe_raw_text", "str", ["void *"]),
|
|
102
101
|
detectedLanguage: lib.func("transcribe_detected_language", "str", ["void *"]),
|
|
103
102
|
returnedTimestampKind: lib.func("transcribe_returned_timestamp_kind", "int", ["void *"]),
|
|
104
103
|
nSegments: lib.func("transcribe_n_segments", "int", ["void *"]),
|
|
105
104
|
nWords: lib.func("transcribe_n_words", "int", ["void *"]),
|
|
106
105
|
nTokens: lib.func("transcribe_n_tokens", "int", ["void *"]),
|
|
106
|
+
nSpeakerSegments: lib.func("transcribe_n_speaker_segments", "int", ["void *"]),
|
|
107
107
|
segmentInit: lib.func("transcribe_segment_init", "void", [outp(T.transcribe_segment)]),
|
|
108
108
|
wordInit: lib.func("transcribe_word_init", "void", [outp(T.transcribe_word)]),
|
|
109
109
|
tokenInit: lib.func("transcribe_token_init", "void", [outp(T.transcribe_token)]),
|
|
110
|
+
speakerSegmentInit: lib.func("transcribe_speaker_segment_init", "void", [
|
|
111
|
+
outp(T.transcribe_speaker_segment),
|
|
112
|
+
]),
|
|
110
113
|
getSegment: lib.func("transcribe_get_segment", "int", [
|
|
111
114
|
"void *",
|
|
112
115
|
"int",
|
|
@@ -114,6 +117,11 @@ export function bindLibrary(libraryPath) {
|
|
|
114
117
|
]),
|
|
115
118
|
getWord: lib.func("transcribe_get_word", "int", ["void *", "int", iop(T.transcribe_word)]),
|
|
116
119
|
getToken: lib.func("transcribe_get_token", "int", ["void *", "int", iop(T.transcribe_token)]),
|
|
120
|
+
getSpeakerSegment: lib.func("transcribe_get_speaker_segment", "int", [
|
|
121
|
+
"void *",
|
|
122
|
+
"int",
|
|
123
|
+
iop(T.transcribe_speaker_segment),
|
|
124
|
+
]),
|
|
117
125
|
timingsInit: lib.func("transcribe_timings_init", "void", [outp(T.transcribe_timings)]),
|
|
118
126
|
getTimings: lib.func("transcribe_get_timings", "int", ["void *", iop(T.transcribe_timings)]),
|
|
119
127
|
// family extensions
|
|
@@ -135,6 +143,9 @@ export function bindLibrary(libraryPath) {
|
|
|
135
143
|
voxtralRealtimeStreamExtInit: lib.func("transcribe_voxtral_realtime_stream_ext_init", "void", [
|
|
136
144
|
outp(T.transcribe_voxtral_realtime_stream_ext),
|
|
137
145
|
]),
|
|
146
|
+
sortformerStreamExtInit: lib.func("transcribe_sortformer_stream_ext_init", "void", [
|
|
147
|
+
outp(T.transcribe_sortformer_stream_ext),
|
|
148
|
+
]),
|
|
138
149
|
// batch (offline)
|
|
139
150
|
runBatch: lib.func("transcribe_run_batch", "int", [
|
|
140
151
|
"void *",
|
|
@@ -160,13 +171,24 @@ export function bindLibrary(libraryPath) {
|
|
|
160
171
|
iop(T.transcribe_word),
|
|
161
172
|
]),
|
|
162
173
|
batchNTokens: lib.func("transcribe_batch_n_tokens", "int", ["void *", "int"]),
|
|
174
|
+
batchNSpeakerSegments: lib.func("transcribe_batch_n_speaker_segments", "int", [
|
|
175
|
+
"void *",
|
|
176
|
+
"int",
|
|
177
|
+
]),
|
|
163
178
|
batchGetToken: lib.func("transcribe_batch_get_token", "int", [
|
|
164
179
|
"void *",
|
|
165
180
|
"int",
|
|
166
181
|
"int",
|
|
167
182
|
iop(T.transcribe_token),
|
|
168
183
|
]),
|
|
184
|
+
batchGetSpeakerSegment: lib.func("transcribe_batch_get_speaker_segment", "int", [
|
|
185
|
+
"void *",
|
|
186
|
+
"int",
|
|
187
|
+
"int",
|
|
188
|
+
iop(T.transcribe_speaker_segment),
|
|
189
|
+
]),
|
|
169
190
|
batchFullText: lib.func("transcribe_batch_full_text", "str", ["void *", "int"]),
|
|
191
|
+
batchRawText: lib.func("transcribe_batch_raw_text", "str", ["void *", "int"]),
|
|
170
192
|
batchDetectedLanguage: lib.func("transcribe_batch_detected_language", "str", ["void *", "int"]),
|
|
171
193
|
batchReturnedTimestampKind: lib.func("transcribe_batch_returned_timestamp_kind", "int", [
|
|
172
194
|
"void *",
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ const BACKENDS = {
|
|
|
20
20
|
vulkan: g.TRANSCRIBE_BACKEND_VULKAN,
|
|
21
21
|
cpu_accel: g.TRANSCRIBE_BACKEND_CPU_ACCEL,
|
|
22
22
|
cuda: g.TRANSCRIBE_BACKEND_CUDA,
|
|
23
|
+
rocm: g.TRANSCRIBE_BACKEND_ROCM,
|
|
23
24
|
};
|
|
24
25
|
const KV_TYPES = {
|
|
25
26
|
auto: g.TRANSCRIBE_KV_TYPE_AUTO,
|
|
@@ -38,6 +39,11 @@ const TIMESTAMPS = {
|
|
|
38
39
|
token: g.TRANSCRIBE_TIMESTAMPS_TOKEN,
|
|
39
40
|
};
|
|
40
41
|
const TIMESTAMP_NAMES = Object.fromEntries(Object.entries(TIMESTAMPS).map(([k, v]) => [v, k]));
|
|
42
|
+
const DIARIZE = {
|
|
43
|
+
default: g.TRANSCRIBE_DIARIZE_MODE_DEFAULT,
|
|
44
|
+
off: g.TRANSCRIBE_DIARIZE_MODE_OFF,
|
|
45
|
+
on: g.TRANSCRIBE_DIARIZE_MODE_ON,
|
|
46
|
+
};
|
|
41
47
|
const FEATURES = {
|
|
42
48
|
initial_prompt: g.TRANSCRIBE_FEATURE_INITIAL_PROMPT,
|
|
43
49
|
temperature_fallback: g.TRANSCRIBE_FEATURE_TEMPERATURE_FALLBACK,
|
|
@@ -45,6 +51,7 @@ const FEATURES = {
|
|
|
45
51
|
cancellation: g.TRANSCRIBE_FEATURE_CANCELLATION,
|
|
46
52
|
pnc: g.TRANSCRIBE_FEATURE_PNC,
|
|
47
53
|
itn: g.TRANSCRIBE_FEATURE_ITN,
|
|
54
|
+
diarization: g.TRANSCRIBE_FEATURE_DIARIZATION,
|
|
48
55
|
};
|
|
49
56
|
// ---- helpers ---------------------------------------------------------------
|
|
50
57
|
function lookup(map, key, what) {
|
|
@@ -239,17 +246,18 @@ export function libraryPath() {
|
|
|
239
246
|
export function artifactDir() {
|
|
240
247
|
return resolveLibrary().artifactDir;
|
|
241
248
|
}
|
|
249
|
+
const DEVICE_HANDLES = new WeakMap();
|
|
242
250
|
const DEVICE_TYPE_NAMES = {
|
|
243
251
|
[g.TRANSCRIBE_DEVICE_TYPE_CPU]: "cpu",
|
|
244
252
|
[g.TRANSCRIBE_DEVICE_TYPE_GPU]: "gpu",
|
|
245
253
|
[g.TRANSCRIBE_DEVICE_TYPE_IGPU]: "igpu",
|
|
246
254
|
[g.TRANSCRIBE_DEVICE_TYPE_ACCEL]: "accel",
|
|
247
255
|
};
|
|
248
|
-
// Decode a koffi-filled
|
|
256
|
+
// Decode a koffi-filled transcribe_device_info struct into a BackendInfo.
|
|
249
257
|
// memory_* are uint64 (bigint from koffi) but stay well under 2^53 for any
|
|
250
258
|
// real device, so num() narrows them losslessly.
|
|
251
|
-
function deviceFromRaw(dev, index = null) {
|
|
252
|
-
|
|
259
|
+
function deviceFromRaw(dev, handle, index = null) {
|
|
260
|
+
const info = {
|
|
253
261
|
name: dev.name ?? "",
|
|
254
262
|
description: dev.description ?? "",
|
|
255
263
|
kind: dev.kind ?? "",
|
|
@@ -259,16 +267,21 @@ function deviceFromRaw(dev, index = null) {
|
|
|
259
267
|
memoryFree: num(dev.memory_free),
|
|
260
268
|
index,
|
|
261
269
|
};
|
|
270
|
+
DEVICE_HANDLES.set(info, handle);
|
|
271
|
+
return info;
|
|
262
272
|
}
|
|
263
273
|
export function getAvailableBackends() {
|
|
264
274
|
const n = native();
|
|
265
|
-
const count = n.F.
|
|
275
|
+
const count = n.F.deviceCount();
|
|
266
276
|
const out = [];
|
|
267
277
|
for (let i = 0; i < count; i++) {
|
|
278
|
+
const handle = n.F.deviceGet(i);
|
|
279
|
+
if (!handle)
|
|
280
|
+
continue;
|
|
268
281
|
const dev = {};
|
|
269
|
-
n.F.
|
|
270
|
-
check(n, n.F.
|
|
271
|
-
out.push(deviceFromRaw(dev, i));
|
|
282
|
+
n.F.deviceInfoInit(dev);
|
|
283
|
+
check(n, n.F.deviceGetInfo(handle, dev), `reading backend device ${i}`);
|
|
284
|
+
out.push(deviceFromRaw(dev, handle, i));
|
|
272
285
|
}
|
|
273
286
|
return out;
|
|
274
287
|
}
|
|
@@ -285,8 +298,11 @@ function singleAccessors(n, h) {
|
|
|
285
298
|
getWord: (j, o) => F.getWord(h, j, o),
|
|
286
299
|
nTokens: () => F.nTokens(h),
|
|
287
300
|
getToken: (j, o) => F.getToken(h, j, o),
|
|
301
|
+
nSpeakerSegments: () => F.nSpeakerSegments(h),
|
|
302
|
+
getSpeakerSegment: (j, o) => F.getSpeakerSegment(h, j, o),
|
|
288
303
|
getTimings: (o) => F.getTimings(h, o),
|
|
289
304
|
fullText: () => F.fullText(h),
|
|
305
|
+
rawText: () => F.rawText(h),
|
|
290
306
|
detectedLanguage: () => F.detectedLanguage(h),
|
|
291
307
|
returnedTimestampKind: () => F.returnedTimestampKind(h),
|
|
292
308
|
};
|
|
@@ -300,8 +316,11 @@ function batchAccessors(n, h, i) {
|
|
|
300
316
|
getWord: (j, o) => F.batchGetWord(h, i, j, o),
|
|
301
317
|
nTokens: () => F.batchNTokens(h, i),
|
|
302
318
|
getToken: (j, o) => F.batchGetToken(h, i, j, o),
|
|
319
|
+
nSpeakerSegments: () => F.batchNSpeakerSegments(h, i),
|
|
320
|
+
getSpeakerSegment: (j, o) => F.batchGetSpeakerSegment(h, i, j, o),
|
|
303
321
|
getTimings: (o) => F.batchGetTimings(h, i, o),
|
|
304
322
|
fullText: () => F.batchFullText(h, i),
|
|
323
|
+
rawText: () => F.batchRawText(h, i),
|
|
305
324
|
detectedLanguage: () => F.batchDetectedLanguage(h, i),
|
|
306
325
|
returnedTimestampKind: () => F.batchReturnedTimestampKind(h, i),
|
|
307
326
|
};
|
|
@@ -321,6 +340,7 @@ function materialize(n, acc) {
|
|
|
321
340
|
nWords: s.n_words,
|
|
322
341
|
firstToken: s.first_token,
|
|
323
342
|
nTokens: s.n_tokens,
|
|
343
|
+
speakerId: s.speaker_id,
|
|
324
344
|
});
|
|
325
345
|
}
|
|
326
346
|
const words = [];
|
|
@@ -352,6 +372,18 @@ function materialize(n, acc) {
|
|
|
352
372
|
wordIndex: t.word_index,
|
|
353
373
|
});
|
|
354
374
|
}
|
|
375
|
+
const speakerSegments = [];
|
|
376
|
+
for (let i = 0, c = acc.nSpeakerSegments(); i < c; i++) {
|
|
377
|
+
const s = {};
|
|
378
|
+
F.speakerSegmentInit(s);
|
|
379
|
+
check(n, acc.getSpeakerSegment(i, s), `reading speaker segment ${i}`);
|
|
380
|
+
speakerSegments.push({
|
|
381
|
+
t0Ms: num(s.t0_ms),
|
|
382
|
+
t1Ms: num(s.t1_ms),
|
|
383
|
+
speakerId: s.speaker_id,
|
|
384
|
+
p: s.p,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
355
387
|
const tm = {};
|
|
356
388
|
F.timingsInit(tm);
|
|
357
389
|
check(n, acc.getTimings(tm), "reading timings");
|
|
@@ -363,9 +395,11 @@ function materialize(n, acc) {
|
|
|
363
395
|
};
|
|
364
396
|
return {
|
|
365
397
|
text: acc.fullText() ?? "",
|
|
398
|
+
rawText: acc.rawText() ?? "",
|
|
366
399
|
language: acc.detectedLanguage() ?? "",
|
|
367
400
|
timestampKind: TIMESTAMP_NAMES[acc.returnedTimestampKind()] ?? "none",
|
|
368
401
|
segments,
|
|
402
|
+
speakerSegments,
|
|
369
403
|
words,
|
|
370
404
|
tokens,
|
|
371
405
|
timings,
|
|
@@ -441,6 +475,19 @@ const FAMILY = {
|
|
|
441
475
|
min_decode_interval_ms: o.minDecodeIntervalMs,
|
|
442
476
|
}),
|
|
443
477
|
},
|
|
478
|
+
sortformer: {
|
|
479
|
+
slot: "run",
|
|
480
|
+
kind: g.TRANSCRIBE_EXT_KIND_SORTFORMER_STREAM,
|
|
481
|
+
type: "transcribe_sortformer_stream_ext",
|
|
482
|
+
init: "sortformerStreamExtInit",
|
|
483
|
+
map: (o) => ({ preset: SORTFORMER_PRESET[o.preset] }),
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
const SORTFORMER_PRESET = {
|
|
487
|
+
default: g.TRANSCRIBE_SORTFORMER_PRESET_DEFAULT,
|
|
488
|
+
very_high_latency: g.TRANSCRIBE_SORTFORMER_PRESET_VERY_HIGH_LATENCY,
|
|
489
|
+
high_latency: g.TRANSCRIBE_SORTFORMER_PRESET_HIGH_LATENCY,
|
|
490
|
+
low_latency: g.TRANSCRIBE_SORTFORMER_PRESET_LOW_LATENCY,
|
|
444
491
|
};
|
|
445
492
|
/**
|
|
446
493
|
* Build a native ext-struct buffer for a family extension and return the koffi
|
|
@@ -610,6 +657,7 @@ export class Session {
|
|
|
610
657
|
// whisper resolves it to "segment" (its robust path), no-timestamp
|
|
611
658
|
// families resolve to "none".
|
|
612
659
|
p.timestamps = lookup(TIMESTAMPS, opts.timestamps ?? "auto", "timestamps");
|
|
660
|
+
p.diarize = lookup(DIARIZE, opts.diarize ?? "default", "diarize");
|
|
613
661
|
if (opts.language !== undefined)
|
|
614
662
|
p.language = opts.language;
|
|
615
663
|
if (opts.targetLanguage !== undefined)
|
|
@@ -696,6 +744,7 @@ export class Session {
|
|
|
696
744
|
language: opts.language,
|
|
697
745
|
targetLanguage: opts.targetLanguage,
|
|
698
746
|
timestamps: opts.timestamps,
|
|
747
|
+
diarize: opts.diarize,
|
|
699
748
|
keepSpecialTags: opts.keepSpecialTags,
|
|
700
749
|
specKDrafts: -1,
|
|
701
750
|
});
|
|
@@ -1004,10 +1053,18 @@ export class TranscribeModel {
|
|
|
1004
1053
|
const n = native();
|
|
1005
1054
|
const p = {};
|
|
1006
1055
|
n.F.modelLoadParamsInit(p);
|
|
1056
|
+
if ("gpuDevice" in opts) {
|
|
1057
|
+
throw new TranscribeError("gpuDevice was removed in 0.2; pass a device from getAvailableBackends() instead");
|
|
1058
|
+
}
|
|
1007
1059
|
if (opts.backend)
|
|
1008
1060
|
p.backend = lookup(BACKENDS, opts.backend, "backend");
|
|
1009
|
-
if (opts.
|
|
1010
|
-
|
|
1061
|
+
if (opts.device !== undefined) {
|
|
1062
|
+
const handle = DEVICE_HANDLES.get(opts.device);
|
|
1063
|
+
if (!handle) {
|
|
1064
|
+
throw new TranscribeError("device must be an entry returned by getAvailableBackends() or model.device");
|
|
1065
|
+
}
|
|
1066
|
+
p.device = handle;
|
|
1067
|
+
}
|
|
1011
1068
|
const out = [null];
|
|
1012
1069
|
const st = await callAsync(n.F.modelLoadFile, path, p, out);
|
|
1013
1070
|
check(n, st, `loading model ${path}`);
|
|
@@ -1124,10 +1181,13 @@ export class TranscribeModel {
|
|
|
1124
1181
|
* snapshot, so read this again to poll how much device memory is left
|
|
1125
1182
|
* after the model loaded. */
|
|
1126
1183
|
get device() {
|
|
1184
|
+
const handle = this.#n.F.modelDevice(this.handle);
|
|
1185
|
+
if (!handle)
|
|
1186
|
+
throw new TranscribeError("model has no resolved compute device");
|
|
1127
1187
|
const dev = {};
|
|
1128
|
-
this.#n.F.
|
|
1129
|
-
check(this.#n, this.#n.F.
|
|
1130
|
-
return deviceFromRaw(dev);
|
|
1188
|
+
this.#n.F.deviceInfoInit(dev);
|
|
1189
|
+
check(this.#n, this.#n.F.deviceGetInfo(handle, dev), "reading model device");
|
|
1190
|
+
return deviceFromRaw(dev, handle);
|
|
1131
1191
|
}
|
|
1132
1192
|
dispose() {
|
|
1133
1193
|
if (this.#disposed)
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** Public value types for the transcribe.cpp TypeScript binding. */
|
|
2
2
|
import type { TranscribeError } from "./errors.js";
|
|
3
|
-
export type Backend = "auto" | "cpu" | "cpu_accel" | "cuda" | "vulkan" | "metal";
|
|
3
|
+
export type Backend = "auto" | "cpu" | "cpu_accel" | "cuda" | "rocm" | "vulkan" | "metal";
|
|
4
4
|
export type KvType = "auto" | "f32" | "f16";
|
|
5
5
|
export type Task = "transcribe" | "translate";
|
|
6
6
|
export type TimestampKind = "none" | "auto" | "segment" | "word" | "token";
|
|
7
|
-
export type
|
|
7
|
+
export type Diarize = "default" | "off" | "on";
|
|
8
|
+
export type Feature = "initial_prompt" | "temperature_fallback" | "long_form" | "cancellation" | "pnc" | "itn" | "diarization";
|
|
8
9
|
/** Mono float32 PCM at the model's native sample rate (16 kHz for v1). */
|
|
9
10
|
export type PcmLike = Float32Array | number[] | ArrayBuffer | Buffer;
|
|
10
11
|
export interface Segment {
|
|
@@ -15,6 +16,15 @@ export interface Segment {
|
|
|
15
16
|
nWords: number;
|
|
16
17
|
firstToken: number;
|
|
17
18
|
nTokens: number;
|
|
19
|
+
/** 1-based speaker id; 0 means no attribution. */
|
|
20
|
+
speakerId: number;
|
|
21
|
+
}
|
|
22
|
+
export interface SpeakerSegment {
|
|
23
|
+
t0Ms: number;
|
|
24
|
+
t1Ms: number;
|
|
25
|
+
speakerId: number;
|
|
26
|
+
/** Family-specific confidence, or NaN when unavailable. */
|
|
27
|
+
p: number;
|
|
18
28
|
}
|
|
19
29
|
export interface Word {
|
|
20
30
|
text: string;
|
|
@@ -57,9 +67,14 @@ export interface SessionLimits {
|
|
|
57
67
|
}
|
|
58
68
|
export interface TranscriptionResult {
|
|
59
69
|
text: string;
|
|
70
|
+
/** The model's decoded output before family post-processing (diarization
|
|
71
|
+
* markers, timestamp/special tokens, tag filtering, whitespace trims).
|
|
72
|
+
* Equal to `text` modulo whitespace for families that emit clean text. */
|
|
73
|
+
rawText: string;
|
|
60
74
|
language: string;
|
|
61
75
|
timestampKind: TimestampKind;
|
|
62
76
|
segments: Segment[];
|
|
77
|
+
speakerSegments: SpeakerSegment[];
|
|
63
78
|
words: Word[];
|
|
64
79
|
tokens: Token[];
|
|
65
80
|
timings: Timings;
|
|
@@ -85,21 +100,17 @@ export interface BackendInfo {
|
|
|
85
100
|
* unreported. Re-query (via {@link getAvailableBackends} or `model.device`)
|
|
86
101
|
* to refresh; backend-defined and not comparable across device kinds. */
|
|
87
102
|
memoryFree: number;
|
|
88
|
-
/**
|
|
89
|
-
* {@link ModelOptions.
|
|
90
|
-
*
|
|
91
|
-
* `model.device`, since `transcribe_model_get_device` does not expose an
|
|
92
|
-
* index; correlate such a device back to {@link getAvailableBackends} by
|
|
93
|
-
* `deviceId` / `name` instead. Order-dependent and not stable across
|
|
94
|
-
* driver updates or hosts. */
|
|
103
|
+
/** Process-local registry index for display. Pass this object via
|
|
104
|
+
* {@link ModelOptions.device} for exact selection; persist `deviceId`, not
|
|
105
|
+
* the index. */
|
|
95
106
|
index: number | null;
|
|
96
107
|
}
|
|
97
108
|
export interface ModelOptions {
|
|
98
109
|
/** "auto" (default), or an explicit backend. */
|
|
99
110
|
backend?: Backend;
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
|
|
111
|
+
/** Exact device returned by {@link getAvailableBackends}. Omit for the
|
|
112
|
+
* backend's automatic policy. Exact selection never falls back. */
|
|
113
|
+
device?: BackendInfo;
|
|
103
114
|
}
|
|
104
115
|
export interface SessionOptions {
|
|
105
116
|
/** CPU threads for CPU-side ops; 0 = library default. */
|
|
@@ -114,6 +125,8 @@ export interface TranscribeOptions {
|
|
|
114
125
|
targetLanguage?: string;
|
|
115
126
|
/** Default "auto" (richest the model supports, per-family). */
|
|
116
127
|
timestamps?: TimestampKind;
|
|
128
|
+
/** Default "default" (speaker attribution off for every family). */
|
|
129
|
+
diarize?: Diarize;
|
|
117
130
|
keepSpecialTags?: boolean;
|
|
118
131
|
/** Speculative-decode draft count; -1 = family default. */
|
|
119
132
|
specKDrafts?: number;
|
|
@@ -158,6 +171,7 @@ export interface StreamOptions {
|
|
|
158
171
|
language?: string;
|
|
159
172
|
targetLanguage?: string;
|
|
160
173
|
timestamps?: TimestampKind;
|
|
174
|
+
diarize?: Diarize;
|
|
161
175
|
keepSpecialTags?: boolean;
|
|
162
176
|
commitPolicy?: CommitPolicy;
|
|
163
177
|
stablePrefixAgreementN?: number;
|
|
@@ -191,6 +205,16 @@ export interface VoxtralRealtimeStreamOptions {
|
|
|
191
205
|
numDelayTokens?: number;
|
|
192
206
|
minDecodeIntervalMs?: number;
|
|
193
207
|
}
|
|
208
|
+
/** Sortformer streaming operating point (latency / accuracy trade-off).
|
|
209
|
+
* "default" keeps the GGUF-shipped checkpoint configuration;
|
|
210
|
+
* "very_high_latency" (~30 s lookahead) is the offline-file operating
|
|
211
|
+
* point; "low_latency" (~1 s) is the real-time point. */
|
|
212
|
+
export type SortformerPreset = "default" | "very_high_latency" | "high_latency" | "low_latency";
|
|
213
|
+
/** Sortformer diarizer options (run slot). A run produces speaker
|
|
214
|
+
* segments, no text. */
|
|
215
|
+
export interface SortformerStreamOptions {
|
|
216
|
+
preset?: SortformerPreset;
|
|
217
|
+
}
|
|
194
218
|
export type FamilyExtension = ({
|
|
195
219
|
kind: "whisper";
|
|
196
220
|
} & WhisperRunOptions) | ({
|
|
@@ -201,4 +225,6 @@ export type FamilyExtension = ({
|
|
|
201
225
|
kind: "parakeet_buffered";
|
|
202
226
|
} & ParakeetBufferedStreamOptions) | ({
|
|
203
227
|
kind: "voxtral";
|
|
204
|
-
} & VoxtralRealtimeStreamOptions)
|
|
228
|
+
} & VoxtralRealtimeStreamOptions) | ({
|
|
229
|
+
kind: "sortformer";
|
|
230
|
+
} & SortformerStreamOptions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "transcribe-cpp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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.2.0",
|
|
55
|
+
"@transcribe-cpp/darwin-x64-cpu": "0.2.0",
|
|
56
|
+
"@transcribe-cpp/linux-x64-cpu-vulkan": "0.2.0",
|
|
57
|
+
"@transcribe-cpp/linux-arm64-cpu-vulkan": "0.2.0",
|
|
58
|
+
"@transcribe-cpp/win32-x64-cpu-vulkan": "0.2.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^22.0.0",
|