add WebAssembly for Kws (#648)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -94,10 +94,17 @@ bool KeywordSpotterConfig::Validate() const {
|
||||
SHERPA_ONNX_LOGE("Please provide --keywords-file.");
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef SHERPA_ONNX_ENABLE_WASM_KWS
|
||||
// due to the limitations of the wasm file system,
|
||||
// keywords file will be packaged into the sherpa-onnx-wasm-kws-main.data file
|
||||
// Solution: take keyword_file variable is directly
|
||||
// parsed as a string of keywords
|
||||
if (!std::ifstream(keywords_file.c_str()).good()) {
|
||||
SHERPA_ONNX_LOGE("Keywords file %s does not exist.", keywords_file.c_str());
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return model_config.Validate();
|
||||
}
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
//
|
||||
// Copyright (c) 2023-2024 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/csrc/transducer-keyword-decoder.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "sherpa-onnx/csrc/log.h"
|
||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||
#include "sherpa-onnx/csrc/transducer-keyword-decoder.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user