online-wenet-ctc-model-config.cc
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// sherpa-onnx/csrc/online-wenet-ctc-model-config.cc
//
// Copyright (c) 2023 Xiaomi Corporation
#include "sherpa-onnx/csrc/online-wenet-ctc-model-config.h"
#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"
namespace sherpa_onnx {
void OnlineWenetCtcModelConfig::Register(ParseOptions *po) {
po->Register("wenet-ctc-model", &model,
"Path to CTC model.onnx from WeNet. Please see "
"https://github.com/k2-fsa/sherpa-onnx/pull/425");
po->Register("wenet-ctc-chunk-size", &chunk_size,
"Chunk size after subsampling used for decoding.");
po->Register("wenet-ctc-num-left-chunks", &num_left_chunks,
"Number of left chunks after subsampling used for decoding.");
}
bool OnlineWenetCtcModelConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("WeNet CTC model %s does not exist", model.c_str());
return false;
}
if (chunk_size <= 0) {
SHERPA_ONNX_LOGE(
"Please specify a positive value for --wenet-ctc-chunk-size. Currently "
"given: %d",
chunk_size);
return false;
}
if (num_left_chunks <= 0) {
SHERPA_ONNX_LOGE(
"Please specify a positive value for --wenet-ctc-num-left-chunks. "
"Currently given: %d. Note that if you want to use -1, please consider "
"using a non-streaming model.",
num_left_chunks);
return false;
}
return true;
}
std::string OnlineWenetCtcModelConfig::ToString() const {
std::ostringstream os;
os << "OnlineWenetCtcModelConfig(";
os << "model=\"" << model << "\", ";
os << "chunk_size=" << chunk_size << ", ";
os << "num_left_chunks=" << num_left_chunks << ")";
return os.str();
}
} // namespace sherpa_onnx