Fix keyword spotting. (#1689)
Reset the stream right after detecting a keyword
This commit is contained in:
@@ -678,7 +678,7 @@ struct SherpaOnnxKeywordSpotter {
|
||||
std::unique_ptr<sherpa_onnx::KeywordSpotter> impl;
|
||||
};
|
||||
|
||||
SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
|
||||
const SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
|
||||
const SherpaOnnxKeywordSpotterConfig *config) {
|
||||
sherpa_onnx::KeywordSpotterConfig spotter_config;
|
||||
|
||||
@@ -755,37 +755,42 @@ SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
|
||||
return spotter;
|
||||
}
|
||||
|
||||
void SherpaOnnxDestroyKeywordSpotter(SherpaOnnxKeywordSpotter *spotter) {
|
||||
void SherpaOnnxDestroyKeywordSpotter(const SherpaOnnxKeywordSpotter *spotter) {
|
||||
delete spotter;
|
||||
}
|
||||
|
||||
SherpaOnnxOnlineStream *SherpaOnnxCreateKeywordStream(
|
||||
const SherpaOnnxOnlineStream *SherpaOnnxCreateKeywordStream(
|
||||
const SherpaOnnxKeywordSpotter *spotter) {
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
new SherpaOnnxOnlineStream(spotter->impl->CreateStream());
|
||||
return stream;
|
||||
}
|
||||
|
||||
SherpaOnnxOnlineStream *SherpaOnnxCreateKeywordStreamWithKeywords(
|
||||
const SherpaOnnxOnlineStream *SherpaOnnxCreateKeywordStreamWithKeywords(
|
||||
const SherpaOnnxKeywordSpotter *spotter, const char *keywords) {
|
||||
SherpaOnnxOnlineStream *stream =
|
||||
new SherpaOnnxOnlineStream(spotter->impl->CreateStream(keywords));
|
||||
return stream;
|
||||
}
|
||||
|
||||
int32_t SherpaOnnxIsKeywordStreamReady(SherpaOnnxKeywordSpotter *spotter,
|
||||
SherpaOnnxOnlineStream *stream) {
|
||||
int32_t SherpaOnnxIsKeywordStreamReady(const SherpaOnnxKeywordSpotter *spotter,
|
||||
const SherpaOnnxOnlineStream *stream) {
|
||||
return spotter->impl->IsReady(stream->impl.get());
|
||||
}
|
||||
|
||||
void SherpaOnnxDecodeKeywordStream(SherpaOnnxKeywordSpotter *spotter,
|
||||
SherpaOnnxOnlineStream *stream) {
|
||||
return spotter->impl->DecodeStream(stream->impl.get());
|
||||
void SherpaOnnxDecodeKeywordStream(const SherpaOnnxKeywordSpotter *spotter,
|
||||
const SherpaOnnxOnlineStream *stream) {
|
||||
spotter->impl->DecodeStream(stream->impl.get());
|
||||
}
|
||||
|
||||
void SherpaOnnxDecodeMultipleKeywordStreams(SherpaOnnxKeywordSpotter *spotter,
|
||||
SherpaOnnxOnlineStream **streams,
|
||||
int32_t n) {
|
||||
void SherpaOnnxResetKeywordStream(const SherpaOnnxKeywordSpotter *spotter,
|
||||
const SherpaOnnxOnlineStream *stream) {
|
||||
spotter->impl->Reset(stream->impl.get());
|
||||
}
|
||||
|
||||
void SherpaOnnxDecodeMultipleKeywordStreams(
|
||||
const SherpaOnnxKeywordSpotter *spotter,
|
||||
const SherpaOnnxOnlineStream **streams, int32_t n) {
|
||||
std::vector<sherpa_onnx::OnlineStream *> ss(n);
|
||||
for (int32_t i = 0; i != n; ++i) {
|
||||
ss[i] = streams[i]->impl.get();
|
||||
@@ -794,7 +799,8 @@ void SherpaOnnxDecodeMultipleKeywordStreams(SherpaOnnxKeywordSpotter *spotter,
|
||||
}
|
||||
|
||||
const SherpaOnnxKeywordResult *SherpaOnnxGetKeywordResult(
|
||||
SherpaOnnxKeywordSpotter *spotter, SherpaOnnxOnlineStream *stream) {
|
||||
const SherpaOnnxKeywordSpotter *spotter,
|
||||
const SherpaOnnxOnlineStream *stream) {
|
||||
const sherpa_onnx::KeywordResult &result =
|
||||
spotter->impl->GetResult(stream->impl.get());
|
||||
const auto &keyword = result.keyword;
|
||||
@@ -869,8 +875,9 @@ void SherpaOnnxDestroyKeywordResult(const SherpaOnnxKeywordResult *r) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *SherpaOnnxGetKeywordResultAsJson(SherpaOnnxKeywordSpotter *spotter,
|
||||
SherpaOnnxOnlineStream *stream) {
|
||||
const char *SherpaOnnxGetKeywordResultAsJson(
|
||||
const SherpaOnnxKeywordSpotter *spotter,
|
||||
const SherpaOnnxOnlineStream *stream) {
|
||||
const sherpa_onnx::KeywordResult &result =
|
||||
spotter->impl->GetResult(stream->impl.get());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user