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

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.
Binary file
Binary file
package/worker.js CHANGED
@@ -53,6 +53,14 @@ import WhisperNodeWasm from './index.js'
53
53
  return entry.context
54
54
  }
55
55
 
56
+ function getVadStream(id) {
57
+ var entry = contexts[id]
58
+ if (!entry || entry.type !== 'vadStream') {
59
+ throw new Error('VAD stream not found')
60
+ }
61
+ return entry.context
62
+ }
63
+
56
64
  function abortedResult() {
57
65
  return {
58
66
  result: '',
@@ -252,8 +260,44 @@ import WhisperNodeWasm from './index.js'
252
260
  case 'releaseVad':
253
261
  await getContext(args[0], 'vad').release()
254
262
  delete contexts[args[0]]
263
+ // Its streams were freed with it
264
+ Object.keys(contexts).forEach(function (key) {
265
+ if (contexts[key].type === 'vadStream' && contexts[key].vadId === args[0]) {
266
+ delete contexts[key]
267
+ }
268
+ })
269
+ return { ok: true }
270
+
271
+ case 'vadStreamCreate': {
272
+ var vadStream = await getContext(args[0], 'vad').createStream()
273
+ var vadStreamId = nextContextId++
274
+ contexts[vadStreamId] = {
275
+ type: 'vadStream',
276
+ context: vadStream,
277
+ vadId: args[0],
278
+ }
279
+ return { id: vadStreamId }
280
+ }
281
+
282
+ case 'vadStreamPush':
283
+ return getVadStream(args[0]).push(args[1])
284
+
285
+ case 'vadStreamFlush':
286
+ return getVadStream(args[0]).flush()
287
+
288
+ case 'vadStreamReset':
289
+ await getVadStream(args[0]).reset()
255
290
  return { ok: true }
256
291
 
292
+ case 'vadStreamRelease': {
293
+ var releasing = contexts[args[0]]
294
+ if (releasing && releasing.type === 'vadStream') {
295
+ delete contexts[args[0]]
296
+ await releasing.context.release()
297
+ }
298
+ return { ok: true }
299
+ }
300
+
257
301
  default:
258
302
  throw new Error('Unknown WASM worker method: ' + message.method)
259
303
  }