@fugood/node-whisper-wasm 1.0.19
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 +40 -0
- package/index.d.ts +183 -0
- package/index.js +1250 -0
- package/package.json +46 -0
- package/whisper-node.js +2 -0
- package/whisper-node.wasm +0 -0
- package/worker.js +255 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @fugood/node-whisper-wasm
|
|
2
|
+
|
|
3
|
+
Browser WASM package for `@fugood/whisper.node`.
|
|
4
|
+
|
|
5
|
+
The package exposes the same high-level context API as the native packages, but
|
|
6
|
+
model and audio file paths are fetched as URLs and copied into the Emscripten
|
|
7
|
+
filesystem before inference.
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const whisper = await WhisperNodeWasm.initWhisper({
|
|
11
|
+
filePath: 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin',
|
|
12
|
+
useGpu: false,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const { promise } = whisper.transcribeFile('https://raw.githubusercontent.com/ggml-org/whisper.cpp/master/samples/jfk.wav', {
|
|
16
|
+
language: 'en',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
console.log(await promise)
|
|
20
|
+
await whisper.release()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The WASM build uses pthreads, so browsers must serve the page with COOP/COEP
|
|
24
|
+
headers and expose `SharedArrayBuffer`. Whisper transcription defaults to up to
|
|
25
|
+
8 threads based on browser hardware concurrency; pass `maxThreads` to override
|
|
26
|
+
it. Browser pages run model loading, transcription, benchmarks, and VAD in a
|
|
27
|
+
dedicated worker by default so the UI thread can keep rendering. Use
|
|
28
|
+
`configureWasm({ worker: false })` only when you explicitly need the old
|
|
29
|
+
in-thread runtime, or pass `workerUrl`, `indexScriptUrl`, and `runtimeScriptUrl`
|
|
30
|
+
when serving the package files from custom URLs. Set `useGpu: true` only with a
|
|
31
|
+
package built using `GGML_WEBGPU=ON` and a browser that exposes `navigator.gpu`.
|
|
32
|
+
VAD currently falls back to CPU in the browser package because the Silero VAD
|
|
33
|
+
graph hits unsupported WebGPU ops.
|
|
34
|
+
|
|
35
|
+
The default build emits `whisper-node.js` and `whisper-node.wasm`. Use
|
|
36
|
+
`bash scripts/build-wasm.sh --single-file` only when you want the WASM binary
|
|
37
|
+
embedded into `whisper-node.js`. Modern Emscripten embeds the pthread worker
|
|
38
|
+
bootstrap in the main JS file, so a separate `whisper-node.worker.js` is not
|
|
39
|
+
expected. The package worker that keeps UI work off the main thread is
|
|
40
|
+
`worker.js`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
export interface NativeContextOptions {
|
|
2
|
+
filePath: string
|
|
3
|
+
modelUrl?: string
|
|
4
|
+
useFlashAttn?: boolean
|
|
5
|
+
useGpu?: boolean
|
|
6
|
+
maxModelBytes?: number
|
|
7
|
+
worker?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface NativeVadContextOptions {
|
|
11
|
+
filePath: string
|
|
12
|
+
modelUrl?: string
|
|
13
|
+
useGpu?: boolean
|
|
14
|
+
nThreads?: number
|
|
15
|
+
maxModelBytes?: number
|
|
16
|
+
worker?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TranscribeOptions {
|
|
20
|
+
language?: string
|
|
21
|
+
translate?: boolean
|
|
22
|
+
maxThreads?: number
|
|
23
|
+
maxContext?: number
|
|
24
|
+
maxLen?: number
|
|
25
|
+
tokenTimestamps?: boolean
|
|
26
|
+
tdrzEnable?: boolean
|
|
27
|
+
wordThold?: number
|
|
28
|
+
offset?: number
|
|
29
|
+
duration?: number
|
|
30
|
+
temperature?: number
|
|
31
|
+
temperatureInc?: number
|
|
32
|
+
beamSize?: number
|
|
33
|
+
bestOf?: number
|
|
34
|
+
prompt?: string
|
|
35
|
+
nProcessors?: number
|
|
36
|
+
onProgress?: (progress: number) => void
|
|
37
|
+
onNewSegments?: (result: TranscribeNewSegmentsResult) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface TranscribeNewSegmentsResult {
|
|
41
|
+
nNew: number
|
|
42
|
+
totalNNew: number
|
|
43
|
+
result: string
|
|
44
|
+
segments: TranscribeResult['segments']
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TranscribeResult {
|
|
48
|
+
language?: string
|
|
49
|
+
result: string
|
|
50
|
+
segments: Array<{
|
|
51
|
+
text: string
|
|
52
|
+
t0: number
|
|
53
|
+
t1: number
|
|
54
|
+
}>
|
|
55
|
+
isAborted: boolean
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface VadOptions {
|
|
59
|
+
threshold?: number
|
|
60
|
+
minSpeechDurationMs?: number
|
|
61
|
+
minSilenceDurationMs?: number
|
|
62
|
+
maxSpeechDurationS?: number
|
|
63
|
+
speechPadMs?: number
|
|
64
|
+
samplesOverlap?: number
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface VadSegment {
|
|
68
|
+
t0: number
|
|
69
|
+
t1: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface BenchResult {
|
|
73
|
+
config: string
|
|
74
|
+
nThreads: number
|
|
75
|
+
encodeMs: number
|
|
76
|
+
decodeMs: number
|
|
77
|
+
batchdMs: number
|
|
78
|
+
promptMs: number
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface WhisperContext {
|
|
82
|
+
transcribe(
|
|
83
|
+
filePath: string,
|
|
84
|
+
options?: TranscribeOptions,
|
|
85
|
+
): {
|
|
86
|
+
stop: () => Promise<void>
|
|
87
|
+
promise: Promise<TranscribeResult>
|
|
88
|
+
}
|
|
89
|
+
transcribeFile(
|
|
90
|
+
filePath: string,
|
|
91
|
+
options?: TranscribeOptions,
|
|
92
|
+
): {
|
|
93
|
+
stop: () => Promise<void>
|
|
94
|
+
promise: Promise<TranscribeResult>
|
|
95
|
+
}
|
|
96
|
+
transcribeData(
|
|
97
|
+
audioData: ArrayBuffer | ArrayBufferView | Float32Array,
|
|
98
|
+
options?: TranscribeOptions,
|
|
99
|
+
): {
|
|
100
|
+
stop: () => Promise<void>
|
|
101
|
+
promise: Promise<TranscribeResult>
|
|
102
|
+
}
|
|
103
|
+
bench(nThreads: number): Promise<BenchResult>
|
|
104
|
+
release(): Promise<void>
|
|
105
|
+
getModelInfo(): object
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface WhisperVadContext {
|
|
109
|
+
detectSpeech(filePath: string, options?: VadOptions): Promise<VadSegment[]>
|
|
110
|
+
detectSpeechFile(filePath: string, options?: VadOptions): Promise<VadSegment[]>
|
|
111
|
+
detectSpeechData(
|
|
112
|
+
audioData: ArrayBuffer | ArrayBufferView | Float32Array,
|
|
113
|
+
options?: VadOptions,
|
|
114
|
+
): Promise<VadSegment[]>
|
|
115
|
+
release(): Promise<void>
|
|
116
|
+
getModelInfo(): object
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface Module {
|
|
120
|
+
WhisperContext: {
|
|
121
|
+
new (options: NativeContextOptions): Promise<WhisperContext>
|
|
122
|
+
toggleNativeLog(
|
|
123
|
+
enable: boolean,
|
|
124
|
+
callback?: (level: string, text: string) => void,
|
|
125
|
+
): void | Promise<void>
|
|
126
|
+
}
|
|
127
|
+
WhisperVadContext: {
|
|
128
|
+
new (options: NativeVadContextOptions): Promise<WhisperVadContext>
|
|
129
|
+
toggleNativeLog(
|
|
130
|
+
enable: boolean,
|
|
131
|
+
callback?: (level: string, text: string) => void,
|
|
132
|
+
): void | Promise<void>
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface WasmRuntimeOptions {
|
|
137
|
+
worker?: boolean
|
|
138
|
+
workerUrl?: string
|
|
139
|
+
indexScriptUrl?: string
|
|
140
|
+
scriptUrl?: string
|
|
141
|
+
runtimeScriptUrl?: string
|
|
142
|
+
locateFileBaseUrl?: string
|
|
143
|
+
locateFile?: (path: string, prefix: string) => string
|
|
144
|
+
mainScriptUrlOrBlob?: string | Blob
|
|
145
|
+
print?: (text: string) => void
|
|
146
|
+
printErr?: (text: string) => void
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export declare const WhisperContext: Module['WhisperContext']
|
|
150
|
+
export declare const WhisperVadContext: Module['WhisperVadContext']
|
|
151
|
+
export declare const DEFAULT_WASM_MODEL_SIZE_LIMIT_BYTES: number
|
|
152
|
+
|
|
153
|
+
export declare function configureWasm(options: WasmRuntimeOptions): void
|
|
154
|
+
export declare function loadWasmModule(): Promise<unknown>
|
|
155
|
+
export declare function loadWhisperModule(): Promise<Module>
|
|
156
|
+
export declare function initWhisper(
|
|
157
|
+
options: NativeContextOptions,
|
|
158
|
+
): Promise<WhisperContext>
|
|
159
|
+
export declare function initWhisperVad(
|
|
160
|
+
options: NativeVadContextOptions,
|
|
161
|
+
): Promise<WhisperVadContext>
|
|
162
|
+
export declare function toggleNativeLog(
|
|
163
|
+
enable: boolean,
|
|
164
|
+
callback?: (level: string, text: string) => void,
|
|
165
|
+
): Promise<void>
|
|
166
|
+
export declare function addNativeLogListener(
|
|
167
|
+
listener: (level: string, text: string) => void,
|
|
168
|
+
): { remove: () => void }
|
|
169
|
+
|
|
170
|
+
declare const _default: {
|
|
171
|
+
WhisperContext: typeof WhisperContext
|
|
172
|
+
WhisperVadContext: typeof WhisperVadContext
|
|
173
|
+
configureWasm: typeof configureWasm
|
|
174
|
+
loadWasmModule: typeof loadWasmModule
|
|
175
|
+
loadWhisperModule: typeof loadWhisperModule
|
|
176
|
+
initWhisper: typeof initWhisper
|
|
177
|
+
initWhisperVad: typeof initWhisperVad
|
|
178
|
+
toggleNativeLog: typeof toggleNativeLog
|
|
179
|
+
addNativeLogListener: typeof addNativeLogListener
|
|
180
|
+
DEFAULT_WASM_MODEL_SIZE_LIMIT_BYTES: typeof DEFAULT_WASM_MODEL_SIZE_LIMIT_BYTES
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export default _default
|