Fix keyword spotting. (#1689)
Reset the stream right after detecting a keyword
This commit is contained in:
@@ -46,6 +46,11 @@ namespace SherpaOnnx
|
||||
Decode(_handle.Handle, stream.Handle);
|
||||
}
|
||||
|
||||
public void Reset(OnlineStream stream)
|
||||
{
|
||||
Reset(_handle.Handle, stream.Handle);
|
||||
}
|
||||
|
||||
// The caller should ensure all passed streams are ready for decoding.
|
||||
public void Decode(IEnumerable<OnlineStream> streams)
|
||||
{
|
||||
@@ -110,6 +115,9 @@ namespace SherpaOnnx
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeKeywordStream")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxResetKeywordStream")]
|
||||
private static extern void Reset(IntPtr handle, IntPtr stream);
|
||||
|
||||
[DllImport(Dll.Filename, EntryPoint = "SherpaOnnxDecodeMultipleKeywordStreams")]
|
||||
private static extern void Decode(IntPtr handle, IntPtr[] streams, int n);
|
||||
|
||||
|
||||
@@ -1584,6 +1584,11 @@ func (spotter *KeywordSpotter) Decode(s *OnlineStream) {
|
||||
C.SherpaOnnxDecodeKeywordStream(spotter.impl, s.impl)
|
||||
}
|
||||
|
||||
// You MUST call it right after detecting a keyword
|
||||
func (spotter *KeywordSpotter) Reset(s *OnlineStream) {
|
||||
C.SherpaOnnxResetKeywordStream(spotter.impl, s.impl)
|
||||
}
|
||||
|
||||
// Get the current result of stream since the last invoke of Reset()
|
||||
func (spotter *KeywordSpotter) GetResult(s *OnlineStream) *KeywordSpotterResult {
|
||||
p := C.SherpaOnnxGetKeywordResult(spotter.impl, s.impl)
|
||||
|
||||
@@ -20,6 +20,10 @@ class KeywordSpotter {
|
||||
addon.decodeKeywordStream(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
reset(stream) {
|
||||
addon.resetKeywordStream(this.handle, stream.handle);
|
||||
}
|
||||
|
||||
getResult(stream) {
|
||||
const jsonStr = addon.getKeywordResultAsJson(this.handle, stream.handle);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user