diff --git a/wasm/kws/app.js b/wasm/kws/app.js index 1e97262a1..6df20d23b 100644 --- a/wasm/kws/app.js +++ b/wasm/kws/app.js @@ -102,15 +102,17 @@ if (navigator.mediaDevices.getUserMedia) { recognizer_stream.acceptWaveform(expectedSampleRate, samples); while (recognizer.isReady(recognizer_stream)) { recognizer.decode(recognizer_stream); - } + let result = recognizer.getResult(recognizer_stream); - let result = recognizer.getResult(recognizer_stream); + if (result.keyword.length > 0) { + console.log(result) + lastResult = result; + resultList.push(JSON.stringify(result)); - if (result.keyword.length > 0) { - console.log(result) - lastResult = result; - resultList.push(JSON.stringify(result)); + // remember to reset the stream right after detecting a keyword + recognizer.reset(recognizer_stream); + } } diff --git a/wasm/kws/sherpa-onnx-kws.js b/wasm/kws/sherpa-onnx-kws.js index 24f9e88de..57c81e096 100644 --- a/wasm/kws/sherpa-onnx-kws.js +++ b/wasm/kws/sherpa-onnx-kws.js @@ -296,13 +296,11 @@ class Kws { } decode(stream) { - return this.Module._SherpaOnnxDecodeKeywordStream( - this.handle, stream.handle); + this.Module._SherpaOnnxDecodeKeywordStream(this.handle, stream.handle); } reset(stream) { - return this.Module._SherpaOnnxResetKeywordStream( - this.handle, stream.handle); + this.Module._SherpaOnnxResetKeywordStream(this.handle, stream.handle); } getResult(stream) {