Fix keyword spotting. (#1689)
Reset the stream right after detecting a keyword
This commit is contained in:
@@ -17,6 +17,7 @@ set(exported_functions
|
||||
SherpaOnnxIsKeywordStreamReady
|
||||
SherpaOnnxOnlineStreamAcceptWaveform
|
||||
SherpaOnnxOnlineStreamInputFinished
|
||||
SherpaOnnxResetKeywordStream
|
||||
)
|
||||
set(mangled_exported_functions)
|
||||
foreach(x IN LISTS exported_functions)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -296,8 +296,11 @@ class Kws {
|
||||
}
|
||||
|
||||
decode(stream) {
|
||||
return this.Module._SherpaOnnxDecodeKeywordStream(
|
||||
this.handle, stream.handle);
|
||||
this.Module._SherpaOnnxDecodeKeywordStream(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
reset(stream) {
|
||||
this.Module._SherpaOnnxResetKeywordStream(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
getResult(stream) {
|
||||
|
||||
Reference in New Issue
Block a user