Skip to content

Commit

Permalink
[feature] Configurable padding length in online websocket server (#755)
Browse files Browse the repository at this point in the history
Signed-off-by: manickavela29 <[email protected]>
  • Loading branch information
manickavela29 authored Apr 11, 2024
1 parent f204e62 commit 399d920
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sherpa-onnx/csrc/online-websocket-server-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -82,8 +87,7 @@ void OnlineWebsocketDecoder::InputFinished(std::shared_ptr<Connection> c) {
c->samples.pop_front();
}

// TODO(fangjun): Change the amount of paddings to be configurable
std::vector<float> tail_padding(static_cast<int64_t>(0.8 * sample_rate));
std::vector<float> tail_padding(static_cast<int64_t>(config_.end_tail_padding * sample_rate));

c->s->AcceptWaveform(sample_rate, tail_padding.data(), tail_padding.size());

Expand Down
2 changes: 2 additions & 0 deletions sherpa-onnx/csrc/online-websocket-server-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 399d920

Please sign in to comment.