Allow more online models to load tokens file from the memory (#1352)

Co-authored-by: xiao <shawl336@6163.com>
This commit is contained in:
lxiao336
2024-09-20 16:38:41 +08:00
committed by GitHub
parent 73c90ec871
commit 06b61ccad8
15 changed files with 735 additions and 15 deletions

View File

@@ -89,8 +89,17 @@ void KeywordSpotterConfig::Register(ParseOptions *po) {
}
bool KeywordSpotterConfig::Validate() const {
if (keywords_file.empty()) {
SHERPA_ONNX_LOGE("Please provide --keywords-file.");
if (!keywords_file.empty() && !keywords_buf.empty()) {
SHERPA_ONNX_LOGE(
"you can not provide a keywords_buf and a keywords file: '%s', "
"at the same time, which is confusing",
keywords_file.c_str());
return false;
}
if (keywords_file.empty() && keywords_buf.empty()) {
SHERPA_ONNX_LOGE(
"Please provide either a keywords-file or the keywords-buf");
return false;
}
@@ -99,7 +108,7 @@ bool KeywordSpotterConfig::Validate() const {
// 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()) {
if (keywords_buf.empty() && !std::ifstream(keywords_file.c_str()).good()) {
SHERPA_ONNX_LOGE("Keywords file '%s' does not exist.",
keywords_file.c_str());
return false;