diff --git a/sherpa-onnx/csrc/online-websocket-server-impl.cc b/sherpa-onnx/csrc/online-websocket-server-impl.cc index a47e613c86..ca9f2bf854 100644 --- a/sherpa-onnx/csrc/online-websocket-server-impl.cc +++ b/sherpa-onnx/csrc/online-websocket-server-impl.cc @@ -19,12 +19,17 @@ void OnlineWebsocketDecoderConfig::Register(ParseOptions *po) { po->Register("max-batch-size", &max_batch_size, "Max batch size for recognition."); + + po->Register("end-tail-padding", &end_tail_padding, + "It determines the length of tail_padding at the end of audio."); } void OnlineWebsocketDecoderConfig::Validate() const { recognizer_config.Validate(); SHERPA_ONNX_CHECK_GT(loop_interval_ms, 0); SHERPA_ONNX_CHECK_GT(max_batch_size, 0); + SHERPA_ONNX_CHECK_GT(end_tail_padding, 0); + } void OnlineWebsocketServerConfig::Register(sherpa_onnx::ParseOptions *po) { @@ -82,8 +87,7 @@ void OnlineWebsocketDecoder::InputFinished(std::shared_ptr c) { c->samples.pop_front(); } - // TODO(fangjun): Change the amount of paddings to be configurable - std::vector tail_padding(static_cast(0.8 * sample_rate)); + std::vector tail_padding(static_cast(config_.end_tail_padding * sample_rate)); c->s->AcceptWaveform(sample_rate, tail_padding.data(), tail_padding.size()); diff --git a/sherpa-onnx/csrc/online-websocket-server-impl.h b/sherpa-onnx/csrc/online-websocket-server-impl.h index a82170fbaa..9716c5c722 100644 --- a/sherpa-onnx/csrc/online-websocket-server-impl.h +++ b/sherpa-onnx/csrc/online-websocket-server-impl.h @@ -62,6 +62,8 @@ struct OnlineWebsocketDecoderConfig { int32_t max_batch_size = 5; + float end_tail_padding = 0.8; + void Register(ParseOptions *po); void Validate() const; };