whisper-cpp-node 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 +316 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +6 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +80 -0
- package/dist/loader.js.map +1 -0
- package/dist/types.d.ts +233 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# whisper-cpp-node
|
|
2
|
+
|
|
3
|
+
Node.js bindings for [whisper.cpp](https://github.com/ggerganov/whisper.cpp) - fast speech-to-text with GPU acceleration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Fast**: Native whisper.cpp performance with GPU acceleration
|
|
8
|
+
- **Cross-platform**: macOS (Metal), Windows (Vulkan)
|
|
9
|
+
- **Core ML**: Optional Apple Neural Engine support for 3x+ speedup (macOS)
|
|
10
|
+
- **OpenVINO**: Optional Intel CPU/GPU encoder acceleration (Windows/Linux)
|
|
11
|
+
- **Streaming VAD**: Built-in Silero voice activity detection
|
|
12
|
+
- **TypeScript**: Full type definitions included
|
|
13
|
+
- **Self-contained**: No external dependencies, just install and use
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
**macOS:**
|
|
18
|
+
- macOS 13.3+ (Ventura or later)
|
|
19
|
+
- Apple Silicon (M1/M2/M3/M4)
|
|
20
|
+
- Node.js 18+
|
|
21
|
+
|
|
22
|
+
**Windows:**
|
|
23
|
+
- Windows 10/11 (x64)
|
|
24
|
+
- Node.js 18+
|
|
25
|
+
- Vulkan-capable GPU (optional, for GPU acceleration)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install whisper-cpp-node
|
|
31
|
+
# or
|
|
32
|
+
pnpm add whisper-cpp-node
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The platform-specific binary is automatically installed:
|
|
36
|
+
- macOS ARM64: `@whisper-cpp-node/darwin-arm64`
|
|
37
|
+
- Windows x64: `@whisper-cpp-node/win32-x64`
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
### File-based transcription
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import {
|
|
45
|
+
createWhisperContext,
|
|
46
|
+
transcribeAsync,
|
|
47
|
+
} from "whisper-cpp-node";
|
|
48
|
+
|
|
49
|
+
// Create a context with your model
|
|
50
|
+
const ctx = createWhisperContext({
|
|
51
|
+
model: "./models/ggml-base.en.bin",
|
|
52
|
+
use_gpu: true,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Transcribe audio file
|
|
56
|
+
const result = await transcribeAsync(ctx, {
|
|
57
|
+
fname_inp: "./audio.wav",
|
|
58
|
+
language: "en",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Result: { segments: [["00:00:00,000", "00:00:02,500", " Hello world"], ...] }
|
|
62
|
+
for (const [start, end, text] of result.segments) {
|
|
63
|
+
console.log(`[${start} --> ${end}]${text}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Clean up
|
|
67
|
+
ctx.free();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Buffer-based transcription
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import {
|
|
74
|
+
createWhisperContext,
|
|
75
|
+
transcribeAsync,
|
|
76
|
+
} from "whisper-cpp-node";
|
|
77
|
+
|
|
78
|
+
const ctx = createWhisperContext({
|
|
79
|
+
model: "./models/ggml-base.en.bin",
|
|
80
|
+
use_gpu: true,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Pass raw PCM audio (16kHz, mono, float32)
|
|
84
|
+
const pcmData = new Float32Array(/* your audio samples */);
|
|
85
|
+
const result = await transcribeAsync(ctx, {
|
|
86
|
+
pcmf32: pcmData,
|
|
87
|
+
language: "en",
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
for (const [start, end, text] of result.segments) {
|
|
91
|
+
console.log(`[${start} --> ${end}]${text}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
ctx.free();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
### `createWhisperContext(options)`
|
|
100
|
+
|
|
101
|
+
Create a persistent context for transcription.
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
interface WhisperContextOptions {
|
|
105
|
+
model: string; // Path to GGML model file (required)
|
|
106
|
+
use_gpu?: boolean; // Enable GPU acceleration (default: true)
|
|
107
|
+
// Uses Metal on macOS, Vulkan on Windows
|
|
108
|
+
use_coreml?: boolean; // Enable Core ML on macOS (default: false)
|
|
109
|
+
use_openvino?: boolean; // Enable OpenVINO encoder on Intel (default: false)
|
|
110
|
+
openvino_device?: string; // OpenVINO device: 'CPU', 'GPU', 'NPU' (default: 'CPU')
|
|
111
|
+
openvino_model_path?: string; // Path to OpenVINO encoder model (auto-derived)
|
|
112
|
+
openvino_cache_dir?: string; // Cache dir for compiled OpenVINO models
|
|
113
|
+
flash_attn?: boolean; // Enable Flash Attention (default: false)
|
|
114
|
+
gpu_device?: number; // GPU device index (default: 0)
|
|
115
|
+
dtw?: string; // DTW preset for word timestamps
|
|
116
|
+
no_prints?: boolean; // Suppress log output (default: false)
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `transcribeAsync(context, options)`
|
|
121
|
+
|
|
122
|
+
Transcribe audio (Promise-based). Accepts either a file path or PCM buffer.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// File input
|
|
126
|
+
interface TranscribeOptionsFile {
|
|
127
|
+
fname_inp: string; // Path to audio file
|
|
128
|
+
// ... common options
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Buffer input
|
|
132
|
+
interface TranscribeOptionsBuffer {
|
|
133
|
+
pcmf32: Float32Array; // Raw PCM (16kHz, mono, float32, -1.0 to 1.0)
|
|
134
|
+
// ... common options
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Common options (partial list - see types.ts for full options)
|
|
138
|
+
interface TranscribeOptionsBase {
|
|
139
|
+
// Language
|
|
140
|
+
language?: string; // Language code ('en', 'zh', 'auto')
|
|
141
|
+
translate?: boolean; // Translate to English
|
|
142
|
+
detect_language?: boolean; // Auto-detect language
|
|
143
|
+
|
|
144
|
+
// Threading
|
|
145
|
+
n_threads?: number; // CPU threads (default: 4)
|
|
146
|
+
n_processors?: number; // Parallel processors
|
|
147
|
+
|
|
148
|
+
// Audio processing
|
|
149
|
+
offset_ms?: number; // Start offset in ms
|
|
150
|
+
duration_ms?: number; // Duration to process (0 = all)
|
|
151
|
+
|
|
152
|
+
// Output control
|
|
153
|
+
no_timestamps?: boolean; // Disable timestamps
|
|
154
|
+
max_len?: number; // Max segment length (chars)
|
|
155
|
+
max_tokens?: number; // Max tokens per segment
|
|
156
|
+
split_on_word?: boolean; // Split on word boundaries
|
|
157
|
+
token_timestamps?: boolean; // Include token-level timestamps
|
|
158
|
+
|
|
159
|
+
// Sampling
|
|
160
|
+
temperature?: number; // Sampling temperature (0.0 = greedy)
|
|
161
|
+
beam_size?: number; // Beam search size (-1 = greedy)
|
|
162
|
+
best_of?: number; // Best-of-N sampling
|
|
163
|
+
|
|
164
|
+
// Thresholds
|
|
165
|
+
entropy_thold?: number; // Entropy threshold
|
|
166
|
+
logprob_thold?: number; // Log probability threshold
|
|
167
|
+
no_speech_thold?: number; // No-speech probability threshold
|
|
168
|
+
|
|
169
|
+
// Context
|
|
170
|
+
prompt?: string; // Initial prompt text
|
|
171
|
+
no_context?: boolean; // Don't use previous context
|
|
172
|
+
|
|
173
|
+
// VAD preprocessing
|
|
174
|
+
vad?: boolean; // Enable VAD preprocessing
|
|
175
|
+
vad_model?: string; // Path to VAD model
|
|
176
|
+
vad_threshold?: number; // VAD threshold (0.0-1.0)
|
|
177
|
+
vad_min_speech_duration_ms?: number;
|
|
178
|
+
vad_min_silence_duration_ms?: number;
|
|
179
|
+
vad_speech_pad_ms?: number;
|
|
180
|
+
|
|
181
|
+
// Callbacks
|
|
182
|
+
progress_callback?: (progress: number) => void;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Result
|
|
186
|
+
interface TranscribeResult {
|
|
187
|
+
segments: TranscriptSegment[];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Segment is a tuple: [start, end, text]
|
|
191
|
+
type TranscriptSegment = [string, string, string];
|
|
192
|
+
// Example: ["00:00:00,000", "00:00:02,500", " Hello world"]
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### `createVadContext(options)`
|
|
196
|
+
|
|
197
|
+
Create a voice activity detection context for streaming audio.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
interface VadContextOptions {
|
|
201
|
+
model: string; // Path to Silero VAD model
|
|
202
|
+
threshold?: number; // Speech threshold (default: 0.5)
|
|
203
|
+
n_threads?: number; // Number of threads (default: 1)
|
|
204
|
+
no_prints?: boolean; // Suppress log output
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
interface VadContext {
|
|
208
|
+
getWindowSamples(): number; // Returns 512 (32ms at 16kHz)
|
|
209
|
+
getSampleRate(): number; // Returns 16000
|
|
210
|
+
process(samples: Float32Array): number; // Returns probability 0.0-1.0
|
|
211
|
+
reset(): void; // Reset LSTM state
|
|
212
|
+
free(): void; // Release resources
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### VAD Example
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { createVadContext } from "whisper-cpp-node";
|
|
220
|
+
|
|
221
|
+
const vad = createVadContext({
|
|
222
|
+
model: "./models/ggml-silero-v6.2.0.bin",
|
|
223
|
+
threshold: 0.5,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const windowSize = vad.getWindowSamples(); // 512 samples
|
|
227
|
+
|
|
228
|
+
// Process audio in 32ms chunks
|
|
229
|
+
function processAudioChunk(samples: Float32Array) {
|
|
230
|
+
const probability = vad.process(samples);
|
|
231
|
+
if (probability >= 0.5) {
|
|
232
|
+
console.log("Speech detected!", probability);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Reset when starting new audio stream
|
|
237
|
+
vad.reset();
|
|
238
|
+
|
|
239
|
+
// Clean up when done
|
|
240
|
+
vad.free();
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Core ML Acceleration (macOS)
|
|
244
|
+
|
|
245
|
+
For 3x+ faster encoding on Apple Silicon:
|
|
246
|
+
|
|
247
|
+
1. Generate a Core ML model:
|
|
248
|
+
```bash
|
|
249
|
+
pip install ane_transformers openai-whisper coremltools
|
|
250
|
+
./models/generate-coreml-model.sh base.en
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
2. Place it next to your GGML model:
|
|
254
|
+
```
|
|
255
|
+
models/ggml-base.en.bin
|
|
256
|
+
models/ggml-base.en-encoder.mlmodelc/
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
3. Enable Core ML:
|
|
260
|
+
```typescript
|
|
261
|
+
const ctx = createWhisperContext({
|
|
262
|
+
model: "./models/ggml-base.en.bin",
|
|
263
|
+
use_coreml: true,
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## OpenVINO Acceleration (Intel)
|
|
268
|
+
|
|
269
|
+
For faster encoder inference on Intel CPUs and GPUs (requires build with OpenVINO support):
|
|
270
|
+
|
|
271
|
+
1. Install OpenVINO and convert the model:
|
|
272
|
+
```bash
|
|
273
|
+
pip install openvino openvino-dev
|
|
274
|
+
python models/convert-whisper-to-openvino.py --model base.en
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
2. The OpenVINO model files are placed next to your GGML model:
|
|
278
|
+
```
|
|
279
|
+
models/ggml-base.en.bin
|
|
280
|
+
models/ggml-base.en-encoder-openvino.xml
|
|
281
|
+
models/ggml-base.en-encoder-openvino.bin
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
3. Enable OpenVINO:
|
|
285
|
+
```typescript
|
|
286
|
+
const ctx = createWhisperContext({
|
|
287
|
+
model: "./models/ggml-base.en.bin",
|
|
288
|
+
use_openvino: true,
|
|
289
|
+
openvino_device: "CPU", // or "GPU" for Intel iGPU
|
|
290
|
+
openvino_cache_dir: "./openvino_cache", // optional, speeds up init
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**Note:** OpenVINO support requires the addon to be built with `-DADDON_OPENVINO=ON`.
|
|
295
|
+
|
|
296
|
+
## Models
|
|
297
|
+
|
|
298
|
+
Download models from [Hugging Face](https://huggingface.co/ggerganov/whisper.cpp):
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# Base English model (~150MB)
|
|
302
|
+
curl -L -o models/ggml-base.en.bin \
|
|
303
|
+
https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin
|
|
304
|
+
|
|
305
|
+
# Large v3 Turbo quantized (~500MB)
|
|
306
|
+
curl -L -o models/ggml-large-v3-turbo-q4_0.bin \
|
|
307
|
+
https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo-q4_0.bin
|
|
308
|
+
|
|
309
|
+
# Silero VAD model (for streaming VAD)
|
|
310
|
+
curl -L -o models/ggml-silero-v6.2.0.bin \
|
|
311
|
+
https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-silero-v6.2.0.bin
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { WhisperContext, WhisperContextOptions, VadContext, VadContextOptions, TranscribeOptions, TranscribeResult } from "./types";
|
|
2
|
+
export type { WhisperContextOptions, VadContextOptions, TranscribeOptions, TranscribeOptionsBase, TranscribeOptionsFile, TranscribeOptionsBuffer, TranscribeResult, TranscriptSegment, WhisperContext, VadContext, WhisperContextConstructor, VadContextConstructor, } from "./types";
|
|
3
|
+
export declare const WhisperContextClass: import("./types").WhisperContextConstructor;
|
|
4
|
+
export declare const VadContextClass: import("./types").VadContextConstructor;
|
|
5
|
+
export declare const transcribe: (context: WhisperContext, options: TranscribeOptions, callback: import("./types").TranscribeCallback) => void;
|
|
6
|
+
export declare const transcribeAsync: (context: WhisperContext, options: TranscribeOptions) => Promise<TranscribeResult>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new WhisperContext
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const ctx = createWhisperContext({
|
|
13
|
+
* model: './models/ggml-base.en.bin',
|
|
14
|
+
* use_gpu: true,
|
|
15
|
+
* use_coreml: true,
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const result = await transcribeAsync(ctx, {
|
|
19
|
+
* fname_inp: './audio.wav',
|
|
20
|
+
* language: 'en',
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* console.log(result.segments);
|
|
24
|
+
* ctx.free();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function createWhisperContext(options: WhisperContextOptions): WhisperContext;
|
|
28
|
+
/**
|
|
29
|
+
* Create a new VadContext for voice activity detection
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const vad = createVadContext({
|
|
34
|
+
* model: './models/ggml-silero-v6.2.0.bin',
|
|
35
|
+
* threshold: 0.5,
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const samples = new Float32Array(512);
|
|
39
|
+
* const probability = vad.process(samples);
|
|
40
|
+
*
|
|
41
|
+
* vad.free();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createVadContext(options: VadContextOptions): VadContext;
|
|
45
|
+
declare const _default: {
|
|
46
|
+
WhisperContext: import("./types").WhisperContextConstructor;
|
|
47
|
+
VadContext: import("./types").VadContextConstructor;
|
|
48
|
+
transcribe: (context: WhisperContext, options: TranscribeOptions, callback: import("./types").TranscribeCallback) => void;
|
|
49
|
+
transcribeAsync: (context: WhisperContext, options: TranscribeOptions) => Promise<TranscribeResult>;
|
|
50
|
+
createWhisperContext: typeof createWhisperContext;
|
|
51
|
+
createVadContext: typeof createVadContext;
|
|
52
|
+
};
|
|
53
|
+
export default _default;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAMjB,eAAO,MAAM,mBAAmB,6CAAuB,CAAC;AACxD,eAAO,MAAM,eAAe,yCAAmB,CAAC;AAGhD,eAAO,MAAM,UAAU,+GAAmB,CAAC;AAG3C,eAAO,MAAM,eAAe,EAAkC,CAC5D,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,iBAAiB,KACvB,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAEhB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAEvE;;;;;+BAhDU,cAAc,WACd,iBAAiB,KACvB,OAAO,CAAC,gBAAgB,CAAC;;;;AAiD9B,wBAOE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transcribeAsync = exports.transcribe = exports.VadContextClass = exports.WhisperContextClass = void 0;
|
|
4
|
+
exports.createWhisperContext = createWhisperContext;
|
|
5
|
+
exports.createVadContext = createVadContext;
|
|
6
|
+
const util_1 = require("util");
|
|
7
|
+
const loader_1 = require("./loader");
|
|
8
|
+
// Load native addon
|
|
9
|
+
const addon = (0, loader_1.loadNativeAddon)();
|
|
10
|
+
// Export native constructors with different names to avoid conflict
|
|
11
|
+
exports.WhisperContextClass = addon.WhisperContext;
|
|
12
|
+
exports.VadContextClass = addon.VadContext;
|
|
13
|
+
// Original callback-based transcribe
|
|
14
|
+
exports.transcribe = addon.transcribe;
|
|
15
|
+
// Promisified version for async/await
|
|
16
|
+
exports.transcribeAsync = (0, util_1.promisify)(addon.transcribe);
|
|
17
|
+
/**
|
|
18
|
+
* Create a new WhisperContext
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const ctx = createWhisperContext({
|
|
23
|
+
* model: './models/ggml-base.en.bin',
|
|
24
|
+
* use_gpu: true,
|
|
25
|
+
* use_coreml: true,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const result = await transcribeAsync(ctx, {
|
|
29
|
+
* fname_inp: './audio.wav',
|
|
30
|
+
* language: 'en',
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* console.log(result.segments);
|
|
34
|
+
* ctx.free();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function createWhisperContext(options) {
|
|
38
|
+
return new addon.WhisperContext(options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a new VadContext for voice activity detection
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const vad = createVadContext({
|
|
46
|
+
* model: './models/ggml-silero-v6.2.0.bin',
|
|
47
|
+
* threshold: 0.5,
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* const samples = new Float32Array(512);
|
|
51
|
+
* const probability = vad.process(samples);
|
|
52
|
+
*
|
|
53
|
+
* vad.free();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function createVadContext(options) {
|
|
57
|
+
return new addon.VadContext(options);
|
|
58
|
+
}
|
|
59
|
+
// Default export with all functionality
|
|
60
|
+
exports.default = {
|
|
61
|
+
WhisperContext: addon.WhisperContext,
|
|
62
|
+
VadContext: addon.VadContext,
|
|
63
|
+
transcribe: addon.transcribe,
|
|
64
|
+
transcribeAsync: exports.transcribeAsync,
|
|
65
|
+
createWhisperContext,
|
|
66
|
+
createVadContext,
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAgEA,oDAIC;AAkBD,4CAEC;AAxFD,+BAAiC;AACjC,qCAA2C;AA2B3C,oBAAoB;AACpB,MAAM,KAAK,GAAiB,IAAA,wBAAe,GAAE,CAAC;AAE9C,oEAAoE;AACvD,QAAA,mBAAmB,GAAG,KAAK,CAAC,cAAc,CAAC;AAC3C,QAAA,eAAe,GAAG,KAAK,CAAC,UAAU,CAAC;AAEhD,qCAAqC;AACxB,QAAA,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;AAE3C,sCAAsC;AACzB,QAAA,eAAe,GAAG,IAAA,gBAAS,EAAC,KAAK,CAAC,UAAU,CAG3B,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,oBAAoB,CAClC,OAA8B;IAE9B,OAAO,IAAI,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,gBAAgB,CAAC,OAA0B;IACzD,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED,wCAAwC;AACxC,kBAAe;IACb,cAAc,EAAE,KAAK,CAAC,cAAc;IACpC,UAAU,EAAE,KAAK,CAAC,UAAU;IAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;IAC5B,eAAe,EAAf,uBAAe;IACf,oBAAoB;IACpB,gBAAgB;CACjB,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA6D5C;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,CA4B9C"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadNativeAddon = loadNativeAddon;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
/**
|
|
8
|
+
* Supported platform-arch combinations
|
|
9
|
+
*/
|
|
10
|
+
const SUPPORTED_PLATFORMS = {
|
|
11
|
+
"darwin-arm64": "@whisper-cpp-node/darwin-arm64",
|
|
12
|
+
"win32-x64": "@whisper-cpp-node/win32-x64",
|
|
13
|
+
// Future: add more platforms
|
|
14
|
+
// "darwin-x64": "@whisper-cpp-node/darwin-x64",
|
|
15
|
+
// "linux-x64": "@whisper-cpp-node/linux-x64",
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Get the platform key for current system
|
|
19
|
+
*/
|
|
20
|
+
function getPlatformKey() {
|
|
21
|
+
return `${(0, os_1.platform)()}-${(0, os_1.arch)()}`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the platform-specific package name
|
|
25
|
+
*/
|
|
26
|
+
function getPlatformPackage() {
|
|
27
|
+
const platformKey = getPlatformKey();
|
|
28
|
+
const packageName = SUPPORTED_PLATFORMS[platformKey];
|
|
29
|
+
if (!packageName) {
|
|
30
|
+
const supported = Object.keys(SUPPORTED_PLATFORMS).join(", ");
|
|
31
|
+
throw new Error(`Unsupported platform: ${platformKey}. ` +
|
|
32
|
+
`Supported platforms: ${supported}`);
|
|
33
|
+
}
|
|
34
|
+
return packageName;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Try to find the binary in workspace development paths
|
|
38
|
+
*/
|
|
39
|
+
function tryWorkspacePath() {
|
|
40
|
+
const platformKey = getPlatformKey();
|
|
41
|
+
// In monorepo development, the binary is in sibling package
|
|
42
|
+
const possiblePaths = [
|
|
43
|
+
// From dist/ folder: ../darwin-arm64/whisper.node
|
|
44
|
+
(0, path_1.join)(__dirname, "..", "..", platformKey, "whisper.node"),
|
|
45
|
+
// From src/ folder during ts-node: ../../darwin-arm64/whisper.node
|
|
46
|
+
(0, path_1.join)(__dirname, "..", "..", "..", platformKey, "whisper.node"),
|
|
47
|
+
];
|
|
48
|
+
for (const p of possiblePaths) {
|
|
49
|
+
if ((0, fs_1.existsSync)(p)) {
|
|
50
|
+
return p;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Load the native addon for the current platform
|
|
57
|
+
*/
|
|
58
|
+
function loadNativeAddon() {
|
|
59
|
+
const packageName = getPlatformPackage();
|
|
60
|
+
// First, try workspace development path
|
|
61
|
+
const workspacePath = tryWorkspacePath();
|
|
62
|
+
if (workspacePath) {
|
|
63
|
+
return require(workspacePath);
|
|
64
|
+
}
|
|
65
|
+
// Then try the installed package
|
|
66
|
+
try {
|
|
67
|
+
const binaryPath = require.resolve((0, path_1.join)(packageName, "whisper.node"));
|
|
68
|
+
return require(binaryPath);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const err = error;
|
|
72
|
+
if (err.code === "MODULE_NOT_FOUND") {
|
|
73
|
+
throw new Error(`Native binary not found. Please ensure ${packageName} is installed.\n` +
|
|
74
|
+
`Try running: npm install ${packageName}\n` +
|
|
75
|
+
`Original error: ${err.message}`);
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Failed to load native addon from ${packageName}: ${err.message}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;AAmEA,0CA4BC;AA/FD,2BAAoC;AACpC,+BAA4B;AAC5B,2BAAgC;AAGhC;;GAEG;AACH,MAAM,mBAAmB,GAA2B;IAClD,cAAc,EAAE,gCAAgC;IAChD,WAAW,EAAE,6BAA6B;IAC1C,6BAA6B;IAC7B,gDAAgD;IAChD,8CAA8C;CAC/C,CAAC;AAEF;;GAEG;AACH,SAAS,cAAc;IACrB,OAAO,GAAG,IAAA,aAAQ,GAAE,IAAI,IAAA,SAAI,GAAE,EAAE,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB;IACzB,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAErD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9D,MAAM,IAAI,KAAK,CACb,yBA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I;gBAC3C,mBAAmB,GAAG,CAAC,OAAO,EAAE,CACnC,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,KAAK,CACb,oCAAoC,WAAW,KAAK,GAAG,CAAC,OAAO,EAAE,CAClE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a WhisperContext
|
|
3
|
+
*/
|
|
4
|
+
export interface WhisperContextOptions {
|
|
5
|
+
/** Path to the GGML model file */
|
|
6
|
+
model: string;
|
|
7
|
+
/** Enable GPU acceleration (default: true) */
|
|
8
|
+
use_gpu?: boolean;
|
|
9
|
+
/** Enable Flash Attention (default: false) */
|
|
10
|
+
flash_attn?: boolean;
|
|
11
|
+
/** GPU device index (default: 0) */
|
|
12
|
+
gpu_device?: number;
|
|
13
|
+
/** Enable Core ML acceleration on macOS (default: false) */
|
|
14
|
+
use_coreml?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Enable OpenVINO encoder acceleration (Intel CPUs/GPUs, default: false)
|
|
17
|
+
* Requires build with -DADDON_OPENVINO=ON and OpenVINO runtime installed.
|
|
18
|
+
* The OpenVINO encoder model must exist alongside the GGML model
|
|
19
|
+
* (e.g., ggml-base.en-encoder-openvino.xml for ggml-base.en.bin)
|
|
20
|
+
*/
|
|
21
|
+
use_openvino?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Path to OpenVINO encoder model (optional)
|
|
24
|
+
* If not specified, derived from the GGML model path with "-encoder-openvino.xml" suffix
|
|
25
|
+
*/
|
|
26
|
+
openvino_model_path?: string;
|
|
27
|
+
/**
|
|
28
|
+
* OpenVINO device to run encoder inference on (default: "CPU")
|
|
29
|
+
* Options: "CPU", "GPU", "NPU", etc.
|
|
30
|
+
*/
|
|
31
|
+
openvino_device?: string;
|
|
32
|
+
/**
|
|
33
|
+
* OpenVINO cache directory for compiled models (optional)
|
|
34
|
+
* Can speed up init time, especially for GPU, by caching compiled 'blobs'
|
|
35
|
+
*/
|
|
36
|
+
openvino_cache_dir?: string;
|
|
37
|
+
/** DTW alignment preset for word-level timestamps (e.g., 'base.en', 'small', 'large.v3') */
|
|
38
|
+
dtw?: string;
|
|
39
|
+
/** Suppress whisper.cpp log output (default: false) */
|
|
40
|
+
no_prints?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Base transcription options (shared between file and buffer input)
|
|
44
|
+
*/
|
|
45
|
+
export interface TranscribeOptionsBase {
|
|
46
|
+
/** Language code (e.g., 'en', 'zh', 'auto') */
|
|
47
|
+
language?: string;
|
|
48
|
+
/** Translate to English */
|
|
49
|
+
translate?: boolean;
|
|
50
|
+
/** Detect language automatically */
|
|
51
|
+
detect_language?: boolean;
|
|
52
|
+
/** Number of threads to use */
|
|
53
|
+
n_threads?: number;
|
|
54
|
+
/** Number of processors for parallel processing */
|
|
55
|
+
n_processors?: number;
|
|
56
|
+
/** Start offset in milliseconds */
|
|
57
|
+
offset_ms?: number;
|
|
58
|
+
/** Duration to process in milliseconds (0 = all) */
|
|
59
|
+
duration_ms?: number;
|
|
60
|
+
/** Audio context size */
|
|
61
|
+
audio_ctx?: number;
|
|
62
|
+
/** Disable timestamps in output */
|
|
63
|
+
no_timestamps?: boolean;
|
|
64
|
+
/** Single segment mode */
|
|
65
|
+
single_segment?: boolean;
|
|
66
|
+
/** Maximum segment length in characters (0 = no limit) */
|
|
67
|
+
max_len?: number;
|
|
68
|
+
/** Maximum tokens per segment (0 = no limit) */
|
|
69
|
+
max_tokens?: number;
|
|
70
|
+
/** Maximum context size (-1 = default) */
|
|
71
|
+
max_context?: number;
|
|
72
|
+
/** Split segments on word boundaries */
|
|
73
|
+
split_on_word?: boolean;
|
|
74
|
+
/** Include token-level timestamps */
|
|
75
|
+
token_timestamps?: boolean;
|
|
76
|
+
/** Word timestamp threshold */
|
|
77
|
+
word_thold?: number;
|
|
78
|
+
/** Use comma in timestamp format (default: true) */
|
|
79
|
+
comma_in_time?: boolean;
|
|
80
|
+
/** Temperature for sampling (0.0 = greedy) */
|
|
81
|
+
temperature?: number;
|
|
82
|
+
/** Temperature increment for fallback */
|
|
83
|
+
temperature_inc?: number;
|
|
84
|
+
/** Best of N sampling candidates */
|
|
85
|
+
best_of?: number;
|
|
86
|
+
/** Beam size for beam search (-1 = greedy) */
|
|
87
|
+
beam_size?: number;
|
|
88
|
+
/** Disable temperature fallback */
|
|
89
|
+
no_fallback?: boolean;
|
|
90
|
+
/** Entropy threshold for fallback */
|
|
91
|
+
entropy_thold?: number;
|
|
92
|
+
/** Log probability threshold */
|
|
93
|
+
logprob_thold?: number;
|
|
94
|
+
/** No speech probability threshold */
|
|
95
|
+
no_speech_thold?: number;
|
|
96
|
+
/** Initial prompt text for context */
|
|
97
|
+
prompt?: string;
|
|
98
|
+
/** Don't use previous context */
|
|
99
|
+
no_context?: boolean;
|
|
100
|
+
/** Suppress blank outputs */
|
|
101
|
+
suppress_blank?: boolean;
|
|
102
|
+
/** Suppress non-speech tokens */
|
|
103
|
+
suppress_nst?: boolean;
|
|
104
|
+
/** Enable speaker diarization */
|
|
105
|
+
diarize?: boolean;
|
|
106
|
+
/** Enable tinydiarize for speaker turn detection */
|
|
107
|
+
tinydiarize?: boolean;
|
|
108
|
+
/** Print special tokens */
|
|
109
|
+
print_special?: boolean;
|
|
110
|
+
/** Print progress */
|
|
111
|
+
print_progress?: boolean;
|
|
112
|
+
/** Print realtime output */
|
|
113
|
+
print_realtime?: boolean;
|
|
114
|
+
/** Print timestamps */
|
|
115
|
+
print_timestamps?: boolean;
|
|
116
|
+
/** Enable VAD preprocessing */
|
|
117
|
+
vad?: boolean;
|
|
118
|
+
/** Path to VAD model */
|
|
119
|
+
vad_model?: string;
|
|
120
|
+
/** VAD speech detection threshold (0.0-1.0) */
|
|
121
|
+
vad_threshold?: number;
|
|
122
|
+
/** Minimum speech duration in milliseconds */
|
|
123
|
+
vad_min_speech_duration_ms?: number;
|
|
124
|
+
/** Minimum silence duration in milliseconds */
|
|
125
|
+
vad_min_silence_duration_ms?: number;
|
|
126
|
+
/** Maximum speech duration in seconds */
|
|
127
|
+
vad_max_speech_duration_s?: number;
|
|
128
|
+
/** Speech padding in milliseconds */
|
|
129
|
+
vad_speech_pad_ms?: number;
|
|
130
|
+
/** VAD samples overlap ratio */
|
|
131
|
+
vad_samples_overlap?: number;
|
|
132
|
+
/** Progress callback function (progress: 0-100) */
|
|
133
|
+
progress_callback?: (progress: number) => void;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Transcription options with file input
|
|
137
|
+
*/
|
|
138
|
+
export interface TranscribeOptionsFile extends TranscribeOptionsBase {
|
|
139
|
+
/** Path to the audio file */
|
|
140
|
+
fname_inp: string;
|
|
141
|
+
pcmf32?: never;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Transcription options with PCM buffer input
|
|
145
|
+
*/
|
|
146
|
+
export interface TranscribeOptionsBuffer extends TranscribeOptionsBase {
|
|
147
|
+
/** Raw PCM audio samples (16kHz, mono, float32, values -1.0 to 1.0) */
|
|
148
|
+
pcmf32: Float32Array;
|
|
149
|
+
fname_inp?: never;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Options for transcription - either file path or PCM buffer
|
|
153
|
+
*/
|
|
154
|
+
export type TranscribeOptions = TranscribeOptionsFile | TranscribeOptionsBuffer;
|
|
155
|
+
/**
|
|
156
|
+
* Transcription result segment (tuple format)
|
|
157
|
+
* [0]: Start time in format "HH:MM:SS,mmm"
|
|
158
|
+
* [1]: End time in format "HH:MM:SS,mmm"
|
|
159
|
+
* [2]: Transcribed text
|
|
160
|
+
*/
|
|
161
|
+
export type TranscriptSegment = [start: string, end: string, text: string];
|
|
162
|
+
/**
|
|
163
|
+
* Transcription result
|
|
164
|
+
*/
|
|
165
|
+
export interface TranscribeResult {
|
|
166
|
+
/** Array of transcript segments as [start, end, text] tuples */
|
|
167
|
+
segments: TranscriptSegment[];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Options for creating a VadContext
|
|
171
|
+
*/
|
|
172
|
+
export interface VadContextOptions {
|
|
173
|
+
/** Path to the Silero VAD model file */
|
|
174
|
+
model: string;
|
|
175
|
+
/** Speech detection threshold (default: 0.5) */
|
|
176
|
+
threshold?: number;
|
|
177
|
+
/** Number of threads (default: 1) */
|
|
178
|
+
n_threads?: number;
|
|
179
|
+
/** Suppress model loading prints */
|
|
180
|
+
no_prints?: boolean;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* WhisperContext class for persistent model context
|
|
184
|
+
*/
|
|
185
|
+
export interface WhisperContext {
|
|
186
|
+
/** Get whisper.cpp system info string */
|
|
187
|
+
getSystemInfo(): string;
|
|
188
|
+
/** Check if model is multilingual */
|
|
189
|
+
isMultilingual(): boolean;
|
|
190
|
+
/** Free the context and release resources */
|
|
191
|
+
free(): void;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* WhisperContext constructor type
|
|
195
|
+
*/
|
|
196
|
+
export interface WhisperContextConstructor {
|
|
197
|
+
new (options: WhisperContextOptions): WhisperContext;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* VadContext class for voice activity detection
|
|
201
|
+
*/
|
|
202
|
+
export interface VadContext {
|
|
203
|
+
/** Get the required window size in samples */
|
|
204
|
+
getWindowSamples(): number;
|
|
205
|
+
/** Get the expected sample rate (16000 Hz) */
|
|
206
|
+
getSampleRate(): number;
|
|
207
|
+
/** Process audio samples and return speech probability [0, 1] */
|
|
208
|
+
process(samples: Float32Array): number;
|
|
209
|
+
/** Reset the internal LSTM state */
|
|
210
|
+
reset(): void;
|
|
211
|
+
/** Free the context and release resources */
|
|
212
|
+
free(): void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* VadContext constructor type
|
|
216
|
+
*/
|
|
217
|
+
export interface VadContextConstructor {
|
|
218
|
+
new (options: VadContextOptions): VadContext;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Transcribe callback function signature
|
|
222
|
+
*/
|
|
223
|
+
export type TranscribeCallback = (error: Error | null, result?: TranscribeResult) => void;
|
|
224
|
+
/**
|
|
225
|
+
* Native addon interface
|
|
226
|
+
*/
|
|
227
|
+
export interface WhisperAddon {
|
|
228
|
+
WhisperContext: WhisperContextConstructor;
|
|
229
|
+
VadContext: VadContextConstructor;
|
|
230
|
+
transcribe: (context: WhisperContext, options: TranscribeOptions, callback: TranscribeCallback) => void;
|
|
231
|
+
whisper: Record<string, unknown>;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oCAAoC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4FAA4F;IAC5F,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAEpC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;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ED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,MAAM,CAAC,EAAE,gBAAgB,KACtB,IAAI,CAAC;AAEV;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,yBAAyB,CAAC;IAC1C,UAAU,EAAE,qBAAqB,CAAC;IAClC,UAAU,EAAE,CACV,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,kBAAkB,KACzB,IAAI,CAAC;IACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "whisper-cpp-node",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Node.js bindings for whisper.cpp - fast speech-to-text with GPU acceleration",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/predict-woo/whisper.cpp",
|
|
9
|
+
"directory": "npm/packages/whisper-cpp-node"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"require": "./dist/index.js",
|
|
17
|
+
"import": "./dist/index.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"@whisper-cpp-node/darwin-arm64": "0.2.1",
|
|
25
|
+
"@whisper-cpp-node/win32-x64": "0.2.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^20.0.0",
|
|
29
|
+
"typescript": "^5.3.0"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"whisper",
|
|
36
|
+
"whisper.cpp",
|
|
37
|
+
"speech-to-text",
|
|
38
|
+
"transcription",
|
|
39
|
+
"audio",
|
|
40
|
+
"asr",
|
|
41
|
+
"apple-silicon",
|
|
42
|
+
"coreml",
|
|
43
|
+
"metal",
|
|
44
|
+
"windows",
|
|
45
|
+
"vulkan",
|
|
46
|
+
"openvino",
|
|
47
|
+
"gpu",
|
|
48
|
+
"intel"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc"
|
|
55
|
+
}
|
|
56
|
+
}
|