@fugood/node-whisper-wasm 1.0.19 → 1.0.21

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 CHANGED
@@ -1,13 +1,17 @@
1
1
  # @fugood/node-whisper-wasm
2
2
 
3
- Browser WASM package for `@fugood/whisper.node`.
3
+ Browser WASM implementation package for `@fugood/whisper.node`. Application
4
+ code should import `@fugood/whisper.node`; this package is pulled in by the main
5
+ package for browser builds.
4
6
 
5
7
  The package exposes the same high-level context API as the native packages, but
6
8
  model and audio file paths are fetched as URLs and copied into the Emscripten
7
9
  filesystem before inference.
8
10
 
9
11
  ```js
10
- const whisper = await WhisperNodeWasm.initWhisper({
12
+ import { initWhisper } from '@fugood/whisper.node'
13
+
14
+ const whisper = await initWhisper({
11
15
  filePath: 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin',
12
16
  useGpu: false,
13
17
  })
@@ -20,21 +24,38 @@ console.log(await promise)
20
24
  await whisper.release()
21
25
  ```
22
26
 
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
27
+ The package ships both single-thread and pthread WASM artifacts. On
28
+ cross-origin isolated pages with `SharedArrayBuffer`, the loader uses the
29
+ pthread artifact; otherwise it falls back to the single-thread artifact
30
+ automatically. Whisper transcription defaults to up to 8 threads based on
31
+ browser hardware concurrency when pthreads are available; pass `maxThreads` to
32
+ override it. Browser WASM clamps `maxThreads` to the compiled pool limit of 8,
33
+ or 1 in the single-thread fallback. Browser pages run model loading,
34
+ transcription, benchmarks, and VAD in a dedicated module worker by default so
35
+ the UI thread can keep rendering. Use the main `whisper.node` package entrypoint
36
+ in browser code:
37
+
38
+ ```js
39
+ import { configureWasm, initWhisper } from '@fugood/whisper.node'
40
+ ```
41
+
42
+ Use `configureWasm({ worker: false })` only when you explicitly need the
43
+ in-thread runtime, `configureWasm({ threads: false })` to force the
44
+ single-thread artifact, or pass `workerPath`, `jsPath`, and `wasmPath` when
45
+ serving the package files from custom URLs. The older `workerUrl` and
46
+ `runtimeScriptUrl` option names still work. Model downloads are cached in
47
+ browser Cache Storage by default. Pass `cacheModel: false` to disable persistent
48
+ caching, `modelCacheName` to isolate the cache namespace, or `modelCacheKey`
49
+ when the fetch URL is a proxy or signed URL but should reuse the same cached
50
+ model. Set `useGpu: true` only with a package built using `GGML_WEBGPU=ON` and a
51
+ browser that exposes `navigator.gpu`. VAD currently falls back to CPU in the
52
+ browser package because the Silero VAD graph hits unsupported WebGPU ops.
53
+
54
+ The default build emits `wasm/whisper-node.js`, `wasm/whisper-node.wasm`,
55
+ `wasm/whisper-node.threads.js`, and `wasm/whisper-node.threads.wasm`. Use
36
56
  `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`.
57
+ embedded into each generated JS file. Modern Emscripten embeds the pthread
58
+ worker bootstrap in the main JS file, so a separate `whisper-node.worker.js` is
59
+ not expected. The package module worker that keeps UI work off the main thread
60
+ is `worker.js`. Use `npm run build-wasm-docker` to build through Docker; it
61
+ selects a native arm64 Emscripten image on Apple Silicon hosts.
package/index.d.ts CHANGED
@@ -4,6 +4,9 @@ export interface NativeContextOptions {
4
4
  useFlashAttn?: boolean
5
5
  useGpu?: boolean
6
6
  maxModelBytes?: number
7
+ cacheModel?: boolean
8
+ modelCacheName?: string
9
+ modelCacheKey?: string
7
10
  worker?: boolean
8
11
  }
9
12
 
@@ -13,6 +16,9 @@ export interface NativeVadContextOptions {
13
16
  useGpu?: boolean
14
17
  nThreads?: number
15
18
  maxModelBytes?: number
19
+ cacheModel?: boolean
20
+ modelCacheName?: string
21
+ modelCacheKey?: string
16
22
  worker?: boolean
17
23
  }
18
24
 
@@ -136,12 +142,19 @@ export interface Module {
136
142
  export interface WasmRuntimeOptions {
137
143
  worker?: boolean
138
144
  workerUrl?: string
145
+ workerPath?: string
139
146
  indexScriptUrl?: string
140
147
  scriptUrl?: string
141
148
  runtimeScriptUrl?: string
149
+ jsPath?: string
150
+ wasmPath?: string
151
+ threads?: boolean
142
152
  locateFileBaseUrl?: string
143
153
  locateFile?: (path: string, prefix: string) => string
144
154
  mainScriptUrlOrBlob?: string | Blob
155
+ modelCacheName?: string
156
+ moduleFactory?: (options?: Record<string, unknown>) => Promise<unknown> | unknown
157
+ moduleOptions?: Record<string, unknown>
145
158
  print?: (text: string) => void
146
159
  printErr?: (text: string) => void
147
160
  }
@@ -149,8 +162,18 @@ export interface WasmRuntimeOptions {
149
162
  export declare const WhisperContext: Module['WhisperContext']
150
163
  export declare const WhisperVadContext: Module['WhisperVadContext']
151
164
  export declare const DEFAULT_WASM_MODEL_SIZE_LIMIT_BYTES: number
165
+ export declare const MAX_WASM_THREADS: number
166
+ export declare const WASM_CONFIG_PATHS: {
167
+ index: string
168
+ js: string
169
+ wasm: string
170
+ threadsJs: string
171
+ threadsWasm: string
172
+ worker: string
173
+ }
152
174
 
153
175
  export declare function configureWasm(options: WasmRuntimeOptions): void
176
+ export declare function isWasmThreadsSupported(): boolean
154
177
  export declare function loadWasmModule(): Promise<unknown>
155
178
  export declare function loadWhisperModule(): Promise<Module>
156
179
  export declare function initWhisper(
@@ -177,7 +200,10 @@ declare const _default: {
177
200
  initWhisperVad: typeof initWhisperVad
178
201
  toggleNativeLog: typeof toggleNativeLog
179
202
  addNativeLogListener: typeof addNativeLogListener
203
+ isWasmThreadsSupported: typeof isWasmThreadsSupported
180
204
  DEFAULT_WASM_MODEL_SIZE_LIMIT_BYTES: typeof DEFAULT_WASM_MODEL_SIZE_LIMIT_BYTES
205
+ MAX_WASM_THREADS: typeof MAX_WASM_THREADS
206
+ WASM_CONFIG_PATHS: typeof WASM_CONFIG_PATHS
181
207
  }
182
208
 
183
209
  export default _default