@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.
package/index.d.ts CHANGED
@@ -80,19 +80,37 @@ export interface ParakeetTranscribeOptions {
80
80
  }
81
81
 
82
82
  export interface VadOptions {
83
+ /** Probability threshold to consider as speech (Default: 0.5) */
83
84
  threshold?: number
85
+ /** Silence threshold while in speech (Default: max(threshold - 0.15, 0.01)) */
86
+ negThreshold?: number
84
87
  minSpeechDurationMs?: number
85
88
  minSilenceDurationMs?: number
89
+ /** Default: no limit */
86
90
  maxSpeechDurationS?: number
87
91
  speechPadMs?: number
92
+ /** @deprecated Ignored since VAD runs on vad.cpp */
88
93
  samplesOverlap?: number
89
94
  }
90
95
 
96
+ /** Speech segment, times in 10 ms units (centiseconds) */
91
97
  export interface VadSegment {
92
98
  t0: number
93
99
  t1: number
94
100
  }
95
101
 
102
+ /** Stateful VAD over live audio, from `WhisperVadContext.createStream()` */
103
+ export interface WhisperVadStream {
104
+ readonly sampleRate: number
105
+ readonly hopSamples: number
106
+ /** Feed 16 kHz mono PCM16 (or Float32Array) audio; resolves with the new speech probabilities */
107
+ push(audio: ArrayBuffer | ArrayBufferView | Float32Array): Promise<number[]>
108
+ /** End of audio: resolves with the probabilities still pending */
109
+ flush(): Promise<number[]>
110
+ reset(): Promise<void>
111
+ release(): Promise<void>
112
+ }
113
+
96
114
  export interface BenchResult {
97
115
  config: string
98
116
  nThreads: number
@@ -156,6 +174,10 @@ export interface ParakeetContext {
156
174
  }
157
175
 
158
176
  export interface WhisperVadContext {
177
+ readonly sampleRate: number
178
+ readonly hopSamples: number
179
+ readonly arch: string
180
+ createStream(): Promise<WhisperVadStream>
159
181
  detectSpeech(filePath: string, options?: VadOptions): Promise<VadSegment[]>
160
182
  detectSpeechFile(filePath: string, options?: VadOptions): Promise<VadSegment[]>
161
183
  detectSpeechData(
package/index.js CHANGED
@@ -1609,6 +1609,46 @@ const createWhisperNodeApi = function (root) {
1609
1609
  this._id = id
1610
1610
  this._meta = meta
1611
1611
  this._released = false
1612
+ this.sampleRate = meta.sampleRate || 16000
1613
+ this.hopSamples = meta.hopSamples || 512
1614
+ this.arch = meta.arch || ''
1615
+ }
1616
+
1617
+ WorkerWhisperVadContextInstance.prototype.createStream = async function () {
1618
+ this._assertValid()
1619
+ var created = await this._proxy.request('vadStreamCreate', [this._id])
1620
+ return new WorkerWhisperVadStreamInstance(
1621
+ this._proxy,
1622
+ created.id,
1623
+ this.sampleRate,
1624
+ this.hopSamples,
1625
+ )
1626
+ }
1627
+
1628
+ // Requests reach the worker in call order and the worker-side stream
1629
+ // serializes them, so no queue is needed here.
1630
+ function WorkerWhisperVadStreamInstance(proxy, id, sampleRate, hopSamples) {
1631
+ this._proxy = proxy
1632
+ this._id = id
1633
+ this.sampleRate = sampleRate
1634
+ this.hopSamples = hopSamples
1635
+ }
1636
+
1637
+ WorkerWhisperVadStreamInstance.prototype.push = function (audio) {
1638
+ var data = copyFloat32Audio(audio)
1639
+ return this._proxy.request('vadStreamPush', [this._id, data], [data.buffer])
1640
+ }
1641
+
1642
+ WorkerWhisperVadStreamInstance.prototype.flush = function () {
1643
+ return this._proxy.request('vadStreamFlush', [this._id])
1644
+ }
1645
+
1646
+ WorkerWhisperVadStreamInstance.prototype.reset = function () {
1647
+ return this._proxy.request('vadStreamReset', [this._id]).then(function () {})
1648
+ }
1649
+
1650
+ WorkerWhisperVadStreamInstance.prototype.release = function () {
1651
+ return this._proxy.request('vadStreamRelease', [this._id]).then(function () {})
1612
1652
  }
1613
1653
 
1614
1654
  WorkerWhisperVadContextInstance.prototype._assertValid = function () {
@@ -1663,12 +1703,7 @@ const createWhisperNodeApi = function (root) {
1663
1703
  var useGpu = false
1664
1704
  var nThreads = normalizeMaxThreads(options.nThreads || 1, runtime) || 1
1665
1705
 
1666
- if (options.useGpu === true) {
1667
- emitLog(
1668
- 'WARN',
1669
- 'WASM VAD currently falls back to CPU because ggml-webgpu does not support the VAD graph safely yet.',
1670
- )
1671
- }
1706
+ // useGpu is ignored: VAD always runs on the CPU (vad.cpp's own kernels)
1672
1707
 
1673
1708
  var model = await ensureModel(runtime, modelSource, 'vad', options)
1674
1709
  var init = unwrapWasmResult(
@@ -1680,6 +1715,9 @@ const createWhisperNodeApi = function (root) {
1680
1715
  wasmFilePath: model.virtualPath,
1681
1716
  useGpu: useGpu,
1682
1717
  nThreads: init.nThreads,
1718
+ sampleRate: init.sampleRate,
1719
+ hopSamples: init.hopSamples,
1720
+ arch: init.arch,
1683
1721
  bytes: model.bytes,
1684
1722
  cacheHit: model.cacheHit,
1685
1723
  cacheStored: model.cacheStored,
@@ -1694,6 +1732,78 @@ const createWhisperNodeApi = function (root) {
1694
1732
  this._id = id
1695
1733
  this._meta = meta
1696
1734
  this._released = false
1735
+ this.sampleRate = meta.sampleRate || 16000
1736
+ this.hopSamples = meta.hopSamples || 512
1737
+ this.arch = meta.arch || ''
1738
+ }
1739
+
1740
+ WhisperVadContextInstance.prototype.createStream = async function () {
1741
+ this._assertValid()
1742
+ var created = unwrapWasmResult(
1743
+ await this._runtime.__wasm_vad_stream_create(this._id),
1744
+ )
1745
+ return new WhisperVadStreamInstance(
1746
+ this._runtime,
1747
+ this._id,
1748
+ created.streamId,
1749
+ this.sampleRate,
1750
+ this.hopSamples,
1751
+ )
1752
+ }
1753
+
1754
+ // Stateful VAD stream: the model state carries over between pushes. Calls
1755
+ // run in call order, each after the previous one settles.
1756
+ function WhisperVadStreamInstance(runtime, contextId, streamId, sampleRate, hopSamples) {
1757
+ this._runtime = runtime
1758
+ this._contextId = contextId
1759
+ this._streamId = streamId
1760
+ this._queue = Promise.resolve()
1761
+ this.sampleRate = sampleRate
1762
+ this.hopSamples = hopSamples
1763
+ }
1764
+
1765
+ WhisperVadStreamInstance.prototype._enqueue = function (op) {
1766
+ var run = this._queue.then(op, op)
1767
+ this._queue = run.catch(function () {})
1768
+ return run
1769
+ }
1770
+
1771
+ WhisperVadStreamInstance.prototype.push = function (audio) {
1772
+ var self = this
1773
+ // Copy now: the caller may reuse its buffer before this call runs
1774
+ var data = copyFloat32Audio(audio)
1775
+ return this._enqueue(async function () {
1776
+ var result = unwrapWasmResult(
1777
+ await self._runtime.__wasm_vad_stream_push(self._contextId, self._streamId, data),
1778
+ )
1779
+ return result.probs || []
1780
+ })
1781
+ }
1782
+
1783
+ WhisperVadStreamInstance.prototype.flush = function () {
1784
+ var self = this
1785
+ return this._enqueue(async function () {
1786
+ var result = unwrapWasmResult(
1787
+ await self._runtime.__wasm_vad_stream_flush(self._contextId, self._streamId),
1788
+ )
1789
+ return result.probs || []
1790
+ })
1791
+ }
1792
+
1793
+ WhisperVadStreamInstance.prototype.reset = function () {
1794
+ var self = this
1795
+ return this._enqueue(async function () {
1796
+ unwrapWasmResult(
1797
+ await self._runtime.__wasm_vad_stream_reset(self._contextId, self._streamId),
1798
+ )
1799
+ })
1800
+ }
1801
+
1802
+ WhisperVadStreamInstance.prototype.release = function () {
1803
+ var self = this
1804
+ return this._enqueue(async function () {
1805
+ await self._runtime.__wasm_vad_stream_release(self._contextId, self._streamId)
1806
+ })
1697
1807
  }
1698
1808
 
1699
1809
  WhisperVadContextInstance.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.0",
3
+ "version": "1.2.0-rc.2",
4
4
  "description": "Browser WASM module for whisper.node",
5
5
  "type": "module",
6
6
  "main": "index.js",