This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex_bi_series-sherpa-onnx/scripts/node-addon-api/lib/keyword-spotter.js
Fangjun Kuang 8b989a851c Fix keyword spotting. (#1689)
Reset the stream right after detecting a keyword
2025-01-20 16:41:10 +08:00

37 lines
791 B
JavaScript

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);
}
reset(stream) {
addon.resetKeywordStream(this.handle, stream.handle);
}
getResult(stream) {
const jsonStr = addon.getKeywordResultAsJson(this.handle, stream.handle);
return JSON.parse(jsonStr);
}
}
module.exports = {
KeywordSpotter,
}