@fugood/node-whisper-wasm 1.2.0-rc.2 → 1.2.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,8 +1,31 @@
1
+ /** Alignment heads for DTW token timestamps: the model the context loads, or `n-top-most` */
2
+ export type DtwAheadsPreset =
3
+ | 'tiny.en'
4
+ | 'tiny'
5
+ | 'base.en'
6
+ | 'base'
7
+ | 'small.en'
8
+ | 'small'
9
+ | 'medium.en'
10
+ | 'medium'
11
+ | 'large-v1'
12
+ | 'large-v2'
13
+ | 'large-v3'
14
+ | 'large-v3-turbo'
15
+ | 'n-top-most'
16
+
1
17
  export interface NativeContextOptions {
2
18
  filePath: string
3
19
  modelUrl?: string
4
20
  useFlashAttn?: boolean
5
21
  useGpu?: boolean
22
+ /**
23
+ * Compute DTW-aligned token timestamps (`tokens[].tDtw` with `includeTokens`) with the
24
+ * alignment heads of this model. Not available with flash attention: see `WhisperContext.dtw`.
25
+ */
26
+ dtwAheadsPreset?: DtwAheadsPreset
27
+ /** Text layers used by the `n-top-most` preset (Default: all) */
28
+ dtwNTop?: number
6
29
  maxModelBytes?: number
7
30
  cacheModel?: boolean
8
31
  modelCacheName?: string
@@ -34,9 +57,14 @@ export interface NativeParakeetContextOptions {
34
57
  }
35
58
 
36
59
  export interface TranscribeOptions {
60
+ /** Spoken language code, or 'auto' to detect it (Default: 'en') */
37
61
  language?: string
38
62
  translate?: boolean
39
63
  maxThreads?: number
64
+ /** Accepted for compatibility with the native builds, ignored in the browser */
65
+ cpu_mask?: string
66
+ /** Accepted for compatibility with the native builds, ignored in the browser */
67
+ cpu_strict?: boolean
40
68
  maxContext?: number
41
69
  maxLen?: number
42
70
  tokenTimestamps?: boolean
@@ -44,12 +72,28 @@ export interface TranscribeOptions {
44
72
  wordThold?: number
45
73
  offset?: number
46
74
  duration?: number
75
+ /**
76
+ * Encoder audio context size: a non-negative integer (0 = model default, at most the
77
+ * model's audio context, 1500 for stock models), or 'auto' to fit it to the input length
78
+ */
79
+ audioCtx?: number | 'auto'
47
80
  temperature?: number
48
81
  temperatureInc?: number
49
82
  beamSize?: number
50
83
  bestOf?: number
84
+ /** Maximum number of text tokens per segment, 0 for no limit (Default: 0) */
85
+ maxTokens?: number
86
+ /** One segment per 30-second decoding window (Default: false) */
87
+ singleSegment?: boolean
88
+ noSpeechThold?: number
89
+ logprobThold?: number
90
+ entropyThold?: number
91
+ suppressBlank?: boolean
92
+ suppressNst?: boolean
51
93
  prompt?: string
52
94
  nProcessors?: number
95
+ /** Add each segment's text tokens (`segments[].tokens`) to the result (Default: false) */
96
+ includeTokens?: boolean
53
97
  onProgress?: (progress: number) => void
54
98
  onNewSegments?: (result: TranscribeNewSegmentsResult) => void
55
99
  }
@@ -61,13 +105,36 @@ export interface TranscribeNewSegmentsResult {
61
105
  segments: TranscribeResult['segments']
62
106
  }
63
107
 
108
+ /** A text token of a Whisper result (special and timestamp tokens are left out) */
109
+ export interface TranscribeToken {
110
+ id: number
111
+ /** A character split across tokens comes with the token that completes it */
112
+ text: string
113
+ p: number
114
+ plog: number
115
+ /** Start / end in ms with `tokenTimestamps`, else -1 */
116
+ t0: number
117
+ t1: number
118
+ /** DTW-aligned time in ms when the context uses DTW (`dtwAheadsPreset`), else -1 */
119
+ tDtw: number
120
+ }
121
+
64
122
  export interface TranscribeResult {
65
123
  language?: string
124
+ /** Whisper: probability of the language when it was auto-detected (`language: 'auto'`) */
125
+ languageProb?: number
66
126
  result: string
127
+ /** Segments, t0 / t1 in ms */
67
128
  segments: Array<{
68
129
  text: string
69
130
  t0: number
70
131
  t1: number
132
+ /** Whisper: probability that the segment's audio window has no speech */
133
+ noSpeechProb?: number
134
+ /** Whisper: mean log probability of the segment's text tokens */
135
+ avgLogprob?: number
136
+ /** Whisper with `includeTokens` */
137
+ tokens?: TranscribeToken[]
71
138
  }>
72
139
  isAborted: boolean
73
140
  }
@@ -121,6 +188,8 @@ export interface BenchResult {
121
188
  }
122
189
 
123
190
  export interface WhisperContext {
191
+ /** Whether DTW token timestamps are computed (`dtwAheadsPreset`, off with flash attention) */
192
+ readonly dtw: boolean
124
193
  transcribe(
125
194
  filePath: string,
126
195
  options?: TranscribeOptions,
package/index.js CHANGED
@@ -1123,6 +1123,7 @@ const createWhisperNodeApi = function (root) {
1123
1123
  this._id = id
1124
1124
  this._meta = meta
1125
1125
  this._released = false
1126
+ this.dtw = meta.dtw === true
1126
1127
  }
1127
1128
 
1128
1129
  WorkerWhisperContextInstance.prototype._assertValid = function () {
@@ -1209,6 +1210,10 @@ const createWhisperNodeApi = function (root) {
1209
1210
 
1210
1211
  var model = await ensureModel(runtime, modelSource, 'whisper', options)
1211
1212
  var useFlashAttn = useGpu && options.useFlashAttn === true
1213
+ // DTW token timestamps: alignment heads preset ('' = off), text layers of 'n-top-most'
1214
+ var dtwAheadsPreset =
1215
+ typeof options.dtwAheadsPreset === 'string' ? options.dtwAheadsPreset : ''
1216
+ var dtwNTop = Number.isFinite(options.dtwNTop) ? Math.floor(options.dtwNTop) : -1
1212
1217
  var init
1213
1218
  try {
1214
1219
  init = unwrapWasmResult(
@@ -1216,6 +1221,8 @@ const createWhisperNodeApi = function (root) {
1216
1221
  model.virtualPath,
1217
1222
  useGpu,
1218
1223
  useFlashAttn,
1224
+ dtwAheadsPreset,
1225
+ dtwNTop,
1219
1226
  ),
1220
1227
  )
1221
1228
  } catch (error) {
@@ -1226,7 +1233,13 @@ const createWhisperNodeApi = function (root) {
1226
1233
  useGpu = false
1227
1234
  useFlashAttn = false
1228
1235
  init = unwrapWasmResult(
1229
- await runtime.__wasm_init_whisper(model.virtualPath, false, false),
1236
+ await runtime.__wasm_init_whisper(
1237
+ model.virtualPath,
1238
+ false,
1239
+ false,
1240
+ dtwAheadsPreset,
1241
+ dtwNTop,
1242
+ ),
1230
1243
  )
1231
1244
  }
1232
1245
 
@@ -1235,6 +1248,7 @@ const createWhisperNodeApi = function (root) {
1235
1248
  wasmFilePath: model.virtualPath,
1236
1249
  useGpu: useGpu,
1237
1250
  useFlashAttn: useFlashAttn,
1251
+ dtw: init.dtw === true,
1238
1252
  bytes: model.bytes,
1239
1253
  cacheHit: model.cacheHit,
1240
1254
  cacheStored: model.cacheStored,
@@ -1249,6 +1263,7 @@ const createWhisperNodeApi = function (root) {
1249
1263
  this._id = id
1250
1264
  this._meta = meta
1251
1265
  this._released = false
1266
+ this.dtw = meta.dtw === true
1252
1267
  }
1253
1268
 
1254
1269
  WhisperContextInstance.prototype._assertValid = function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/node-whisper-wasm",
3
- "version": "1.2.0-rc.2",
3
+ "version": "1.2.0-rc.3",
4
4
  "description": "Browser WASM module for whisper.node",
5
5
  "type": "module",
6
6
  "main": "index.js",