Add keyword spotting API for node-addon-api (#877)
This commit is contained in:
32
scripts/node-addon-api/lib/keyword-spotter.js
Normal file
32
scripts/node-addon-api/lib/keyword-spotter.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const addon = require('./addon.js');
|
||||
const streaming_asr = require('./streaming-asr.js');
|
||||
|
||||
class KeywordSpotter {
|
||||
constructor(config) {
|
||||
this.handle = addon.createKeywordSpotter(config);
|
||||
this.config = config
|
||||
}
|
||||
|
||||
createStream() {
|
||||
const handle = addon.createKeywordStream(this.handle);
|
||||
return new streaming_asr.OnlineStream(handle);
|
||||
}
|
||||
|
||||
isReady(stream) {
|
||||
return addon.isKeywordStreamReady(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
decode(stream) {
|
||||
addon.decodeKeywordStream(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
getResult(stream) {
|
||||
const jsonStr = addon.getKeywordResultAsJson(this.handle, stream.handle);
|
||||
|
||||
return JSON.parse(jsonStr);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
KeywordSpotter,
|
||||
}
|
||||
@@ -7,6 +7,7 @@ const slid = require('./spoken-language-identification.js');
|
||||
const sid = require('./speaker-identification.js');
|
||||
const at = require('./audio-tagg.js');
|
||||
const punct = require('./punctuation.js');
|
||||
const kws = require('./keyword-spotter.js');
|
||||
|
||||
module.exports = {
|
||||
OnlineRecognizer: streaming_asr.OnlineRecognizer,
|
||||
@@ -22,4 +23,5 @@ module.exports = {
|
||||
SpeakerEmbeddingManager: sid.SpeakerEmbeddingManager,
|
||||
AudioTagging: at.AudioTagging,
|
||||
Punctuation: punct.Punctuation,
|
||||
KeywordSpotter: kws.KeywordSpotter,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user