add WebAssembly for Kws (#648)

This commit is contained in:
Lovemefan
2024-03-11 21:02:31 +08:00
committed by GitHub
parent a628002d8f
commit 009ed2cd30
14 changed files with 807 additions and 8 deletions

View File

@@ -266,8 +266,14 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
}
void InitKeywords() {
#ifdef SHERPA_ONNX_ENABLE_WASM_KWS
// Due to the limitations of the wasm file system,
// the keyword_file variable is directly parsed as a string of keywords
// if WASM KWS on
std::istringstream is(config_.keywords_file);
InitKeywords(is);
#else
// each line in keywords_file contains space-separated words
std::ifstream is(config_.keywords_file);
if (!is) {
SHERPA_ONNX_LOGE("Open keywords file failed: %s",
@@ -275,6 +281,7 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
exit(-1);
}
InitKeywords(is);
#endif
}
#if __ANDROID_API__ >= 9