From 399d920b47fa168114471195772288f1e49d42a4 Mon Sep 17 00:00:00 2001 From: Manix <50542248+manickavela29@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:27:11 +0530 Subject: [PATCH] [feature] Configurable padding length in online websocket server (#755) Signed-off-by: manickavela29 --- sherpa-onnx/csrc/online-websocket-server-impl.cc | 8 ++++++-- sherpa-onnx/csrc/online-websocket-server-impl.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sherpa-onnx/csrc/online-websocket-server-impl.cc b/sherpa-onnx/csrc/online-websocket-server-impl.cc index a47e613c8..ca9f2bf85 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 a82170fba..9716c5c72 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; };