2626
2727namespace sherpa_onnx {
2828
29- OnlineRecognizerResult ConvertCtc (const OnlineCtcDecoderResult &src,
29+ static OnlineRecognizerResult ConvertCtc (const OnlineCtcDecoderResult &src,
3030 const SymbolTable &sym_table,
3131 float frame_shift_ms,
3232 int32_t subsampling_factor, int32_t segment,
@@ -79,8 +79,12 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
7979 : OnlineRecognizerImpl(config),
8080 config_(config),
8181 model_(OnlineCtcModel::Create(config.model_config)),
82- sym_(config.model_config.tokens),
8382 endpoint_(config_.endpoint_config) {
83+ if (!config.model_config .tokens_buf .empty ()) {
84+ sym_ = SymbolTable (config.model_config .tokens_buf , false );
85+ } else {
86+ sym_ = SymbolTable (config.model_config .tokens , true );
87+ }
8488 PostInit ();
8589 }
8690
@@ -90,8 +94,12 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
9094 : OnlineRecognizerImpl(mgr, config),
9195 config_(config),
9296 model_(OnlineCtcModel::Create(mgr, config.model_config)),
93- sym_(mgr, config.model_config.tokens),
9497 endpoint_(config_.endpoint_config) {
98+ if (!config.model_config .tokens_buf .empty ()) {
99+ sym_ = SymbolTable (config.model_config .tokens_buf , false );
100+ } else {
101+ sym_ = SymbolTable (mgr, config.model_config .tokens );
102+ }
95103 PostInit ();
96104 }
97105
@@ -209,11 +217,15 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
209217
210218 int32_t num_processed_frames = s->GetNumProcessedFrames ();
211219
212- // frame shift is 10 milliseconds
213220 float frame_shift_in_seconds = 0.01 ;
221+ int32_t subsampling_factor = 4 ;
222+ if (!config_.model_config .t_one_ctc .model .empty ()) {
223+ frame_shift_in_seconds = 0.03 ;
224+ subsampling_factor = 1 ;
225+ }
214226
215- // subsampling factor is 4
216- int32_t trailing_silence_frames = s->GetCtcResult ().num_trailing_blanks * 4 ;
227+ int32_t trailing_silence_frames =
228+ s->GetCtcResult ().num_trailing_blanks * subsampling_factor ;
217229
218230 return endpoint_.IsEndpoint (num_processed_frames, trailing_silence_frames,
219231 frame_shift_in_seconds);
@@ -242,11 +254,6 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
242254
243255 private:
244256 void PostInit () {
245- if (!config_.model_config .tokens_buf .empty ()) {
246- // / assuming tokens_buf and tokens are guaranteed not being both empty
247- sym_ = SymbolTable (config_.model_config .tokens_buf , false );
248- }
249-
250257 if (!config_.model_config .wenet_ctc .model .empty ()) {
251258 // WeNet CTC models assume input samples are in the range
252259 // [-32768, 32767], so we set normalize_samples to false
0 commit comments