-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.d.ts
231 lines (191 loc) · 4.89 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import type { Transform, Stream } from 'stream';
type SampleRate = 16000 | 22050 | 32000 | 44100 | 48000;
type BitLength = 8 | 16 | 24 | 32;
declare enum VadMode {
NORMAL = 0,
LOW_BITRATE = 1,
AGGRESSIVE = 2,
VERY_AGGRESSIVE = 3
}
declare type WakewordDetectorOptions = {
/**
* DTW window width
*
* @default 5
*/
bandSize?: number,
/**
* Reference distance
*
* @default 0.22
*/
ref?: number,
/**
* Number of input channels. 1 for mono, 2 for stereo.
*
* @default 1
*/
channels?: 1 | 2,
/**
* Bit depth of the input audio.
*
* @default 16
*/
bitLength?: BitLength,
/**
* Sample rate of the input audio. Not recommended to go over 16000 for performance reasons.
*
* @default 16000
*/
sampleRate?: SampleRate,
/**
* Length of each frame in milliseconds. **Must** be a multiple of `frameShiftMS`.
*
* @default 30
*/
frameLengthMS?: number,
/**
* @default 10
*/
frameShiftMS?: number,
/**
* The default detection threshold for new keywords. Each keyword may have their own threshold, but if no threshold
* is configured for a new keyword, it will default to this.
*
* @default 0.5
*/
threshold?: number,
/**
* Voice activity detection mode. Only applies if `vad` is enabled.
*
* @default VadMode.AGGRESSIVE
*/
vadMode?: VadMode,
/**
* How much time it takes for the VAD mode to change in milliseconds.
*
* @default 500
*/
vadDebounceTime?: number,
preEmphasisCoefficient?: number,
/**
* Whether or not to use voice activity detection. The detector will only run if there is voice activity detected.
*
* @default true
*/
vad?: boolean
};
declare class WakewordDetector extends Transform {
static VadMode: typeof VadMode;
options: WakewordDetectorOptions;
constructor(options?: WakewordDetectorOptions);
/**
* Whether or not the extractor is currently full.
*/
get full(): boolean;
/**
* Whether or not the detector is currently buffering.
*/
get buffering(): boolean;
set buffering(enabled: boolean);
/**
* The number of channels in the input audio.
*/
get channels(): 1 | 2;
/**
* The bit depth of the input audio.
*/
get bitLength(): BitLength;
/**
* The sample rate of the input audio.
*/
get sampleRate(): SampleRate;
/**
* The numer of samples per each frame.
*/
get samplesPerFrame(): number;
get samplesPerShift(): number;
/**
* The length of each frame, in milliseconds.
*/
get frameLengthMS(): number;
get frameShiftMS(): number;
/**
* The default detection threshold for new keywords. Each keyword may have their own threshold, but if no threshold
* is configured for a new keyword, it will default to this.
*/
get threshold(): number;
/**
* Whether or not to use voice activity detection. The detector will only run if there is voice activity detected.
*/
get useVad(): boolean;
get vadMode(): VadMode;
/**
* How much time it takes for the VAD mode to change in milliseconds.
*/
get vadDebounceTime(): number;
on(event: 'data', cb: (data: {
keyword: string,
score: number,
threshold: number,
frames: number,
audioData: Buffer,
timestamp: number
}) => void): void;
/**
* Extracts features from a WAV file.
*
* It's assumed that the WAV file has the same sample rate, bit depth, and channels of the detector.
*
* @param file The path to the WAV file.
*/
extractFeaturesFromFile(file: string): Promise<number[][]>;
/**
* Extracts features from a PCM buffer.
*
* It's assumed that the audio buffer has the same sample rate, bit depth, and channels of the detector.
*/
extractFeaturesFromBuffer(buffer: Buffer): Promise<number[][]>;
/**
* Extracts features from a PCM stream.
*
* It's assumed that the audio stream has the same sample rate, bit depth, and channels of the detector.
*/
extractFeaturesFromStream(stream: Stream): Promise<number[][]>;
/**
* Adds a keyword to this detector.
*
* @param templates An array of templates, either a path to a WAV file or a PCM Buffer.
*/
addKeyword(keyword: string, templates: (Buffer | string)[], options?: {
/**
* Disable averaging the template audio.
*
* @default false
*/
disableAveraging?: boolean,
/**
* The threshold of this keyword. Set to 0 or `undefined` to use the detector's default threshold.
*
* @default 0
*/
threshold?: number
}): Promise<void>;
/**
* Removes a keyword from this detector.
*/
removeKeyword(keyword: string): void;
/**
* Clears all keywords from this detector.
*/
clearKeywords(): void;
/**
* Enable detection of a keyword.
*/
enableKeyword(keyword: string): void;
/**
* Disable detection of a keyword.
*/
disableKeyword(keyword: string): void;
}
export = WakewordDetector;