Committed by
GitHub
[feature] Configurable padding length in online websocket server (#755)
Signed-off-by: manickavela29 <manickavela1998@gmail.com>
正在显示
2 个修改的文件
包含
8 行增加
和
2 行删除
| @@ -19,12 +19,17 @@ void OnlineWebsocketDecoderConfig::Register(ParseOptions *po) { | @@ -19,12 +19,17 @@ void OnlineWebsocketDecoderConfig::Register(ParseOptions *po) { | ||
| 19 | 19 | ||
| 20 | po->Register("max-batch-size", &max_batch_size, | 20 | po->Register("max-batch-size", &max_batch_size, |
| 21 | "Max batch size for recognition."); | 21 | "Max batch size for recognition."); |
| 22 | + | ||
| 23 | + po->Register("end-tail-padding", &end_tail_padding, | ||
| 24 | + "It determines the length of tail_padding at the end of audio."); | ||
| 22 | } | 25 | } |
| 23 | 26 | ||
| 24 | void OnlineWebsocketDecoderConfig::Validate() const { | 27 | void OnlineWebsocketDecoderConfig::Validate() const { |
| 25 | recognizer_config.Validate(); | 28 | recognizer_config.Validate(); |
| 26 | SHERPA_ONNX_CHECK_GT(loop_interval_ms, 0); | 29 | SHERPA_ONNX_CHECK_GT(loop_interval_ms, 0); |
| 27 | SHERPA_ONNX_CHECK_GT(max_batch_size, 0); | 30 | SHERPA_ONNX_CHECK_GT(max_batch_size, 0); |
| 31 | + SHERPA_ONNX_CHECK_GT(end_tail_padding, 0); | ||
| 32 | + | ||
| 28 | } | 33 | } |
| 29 | 34 | ||
| 30 | void OnlineWebsocketServerConfig::Register(sherpa_onnx::ParseOptions *po) { | 35 | void OnlineWebsocketServerConfig::Register(sherpa_onnx::ParseOptions *po) { |
| @@ -82,8 +87,7 @@ void OnlineWebsocketDecoder::InputFinished(std::shared_ptr<Connection> c) { | @@ -82,8 +87,7 @@ void OnlineWebsocketDecoder::InputFinished(std::shared_ptr<Connection> c) { | ||
| 82 | c->samples.pop_front(); | 87 | c->samples.pop_front(); |
| 83 | } | 88 | } |
| 84 | 89 | ||
| 85 | - // TODO(fangjun): Change the amount of paddings to be configurable | ||
| 86 | - std::vector<float> tail_padding(static_cast<int64_t>(0.8 * sample_rate)); | 90 | + std::vector<float> tail_padding(static_cast<int64_t>(config_.end_tail_padding * sample_rate)); |
| 87 | 91 | ||
| 88 | c->s->AcceptWaveform(sample_rate, tail_padding.data(), tail_padding.size()); | 92 | c->s->AcceptWaveform(sample_rate, tail_padding.data(), tail_padding.size()); |
| 89 | 93 |
| @@ -62,6 +62,8 @@ struct OnlineWebsocketDecoderConfig { | @@ -62,6 +62,8 @@ struct OnlineWebsocketDecoderConfig { | ||
| 62 | 62 | ||
| 63 | int32_t max_batch_size = 5; | 63 | int32_t max_batch_size = 5; |
| 64 | 64 | ||
| 65 | + float end_tail_padding = 0.8; | ||
| 66 | + | ||
| 65 | void Register(ParseOptions *po); | 67 | void Register(ParseOptions *po); |
| 66 | void Validate() const; | 68 | void Validate() const; |
| 67 | }; | 69 | }; |
-
请 注册 或 登录 后发表评论