You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/addon.node/README.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,39 @@ Run the VAD example with performance comparison:
44
44
node vad-example.js
45
45
```
46
46
47
+
### Cancellation Usage
48
+
49
+
Run the cancellation example (cancels an in-flight transcription via `AbortSignal`):
50
+
51
+
```shell
52
+
node cancel-example.js
53
+
```
54
+
55
+
## Cancelling a transcription
56
+
57
+
An in-flight transcription can be cancelled by passing an `AbortSignal` as the `signal` parameter:
58
+
59
+
```javascript
60
+
constac=newAbortController();
61
+
62
+
constpromise=whisperAsync({
63
+
// ... other params ...
64
+
signal:ac.signal,
65
+
});
66
+
67
+
// cancel at any time
68
+
ac.abort();
69
+
70
+
constresult=await promise;
71
+
// result.cancelled === true
72
+
// result.transcription contains the segments transcribed before cancellation
73
+
```
74
+
75
+
Cancellation is checked before each encoder run and before each ggml graph
76
+
computation, so it usually takes effect within a fraction of a second.
77
+
The promise resolves normally (it does not reject): `result.cancelled` is `true`
78
+
and `result.transcription` contains the segments completed before the abort.
79
+
47
80
## Voice Activity Detection (VAD) Support
48
81
49
82
VAD can significantly improve transcription performance by only processing speech segments, which is especially beneficial for audio files with long periods of silence.
@@ -112,4 +145,5 @@ Both traditional whisper.cpp parameters and new VAD parameters are supported:
112
145
-`comma_in_time`: Use comma in timestamps (default: true)
113
146
-`print_progress`: Print progress info (default: false)
114
147
-`progress_callback`: Progress callback function
148
+
-`signal`: `AbortSignal` used to cancel the transcription (see above section)
0 commit comments