Skip to content

Support sending is_eof for online websocket server. #2204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sherpa-onnx/csrc/online-recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ std::string OnlineRecognizerResult::AsJsonString() const {
os << "\"words\": " << VecToString(words, 0) << ", ";
os << "\"start_time\": " << std::fixed << std::setprecision(2) << start_time
<< ", ";
os << "\"is_final\": " << (is_final ? "true" : "false");
os << "\"is_final\": " << (is_final ? "true" : "false") << ", ";
os << "\"is_eof\": " << (is_eof ? "true" : "false");
os << "}";
return os.str();
}
Expand Down
8 changes: 7 additions & 1 deletion sherpa-onnx/csrc/online-recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ struct OnlineRecognizerResult {
/// When an endpoint is detected, it will change
float start_time = 0;

/// True if the end of this segment is reached
/// True if the end of this segment is reached, i.e., an endpoint is detected
/// used only in ./online-websocket-server-impl.cc
bool is_final = false;

/// used only in ./online-websocket-server-impl.cc
/// If it is true, it means the server has processed all received samples
bool is_eof = false;

/** Return a json string.
*
* The returned string contains:
Expand All @@ -69,6 +74,7 @@ struct OnlineRecognizerResult {
* "segment": x,
* "start_time": x,
* "is_final": true|false
* "is_eof": true|false
* }
*/
std::string AsJsonString() const;
Expand Down
1 change: 1 addition & 0 deletions sherpa-onnx/csrc/online-websocket-server-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void OnlineWebsocketDecoder::Decode() {

if (!recognizer_->IsReady(c->s.get()) && c->eof) {
result.is_final = true;
result.is_eof = true;
}

asio::post(server_->GetConnectionContext(),
Expand Down
Loading