Add keyword spotting API for node-addon-api (#877)
This commit is contained in:
@@ -653,6 +653,20 @@ void DestroyKeywordResult(const SherpaOnnxKeywordResult *r) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *GetKeywordResultAsJson(SherpaOnnxKeywordSpotter *spotter,
|
||||
SherpaOnnxOnlineStream *stream) {
|
||||
const sherpa_onnx::KeywordResult &result =
|
||||
spotter->impl->GetResult(stream->impl.get());
|
||||
|
||||
std::string json = result.AsJsonString();
|
||||
char *pJson = new char[json.size() + 1];
|
||||
std::copy(json.begin(), json.end(), pJson);
|
||||
pJson[json.size()] = 0;
|
||||
return pJson;
|
||||
}
|
||||
|
||||
void FreeKeywordResultJson(const char *s) { delete[] s; }
|
||||
|
||||
// ============================================================
|
||||
// For VAD
|
||||
// ============================================================
|
||||
|
||||
@@ -625,6 +625,13 @@ SHERPA_ONNX_API const SherpaOnnxKeywordResult *GetKeywordResult(
|
||||
/// @param r A pointer returned by GetKeywordResult()
|
||||
SHERPA_ONNX_API void DestroyKeywordResult(const SherpaOnnxKeywordResult *r);
|
||||
|
||||
// the user has to call FreeKeywordResultJson() to free the returned pointer
|
||||
// to avoid memory leak
|
||||
SHERPA_ONNX_API const char *GetKeywordResultAsJson(
|
||||
SherpaOnnxKeywordSpotter *spotter, SherpaOnnxOnlineStream *stream);
|
||||
|
||||
SHERPA_ONNX_API void FreeKeywordResultJson(const char *s);
|
||||
|
||||
// ============================================================
|
||||
// For VAD
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user