Fangjun Kuang
Committed by GitHub

Support sending is_eof for online websocket server. (#2204)

is_final=true means an endpoint is detected.

is_eof=true means all received samples have been processed
by the server.
@@ -77,7 +77,8 @@ std::string OnlineRecognizerResult::AsJsonString() const { @@ -77,7 +77,8 @@ std::string OnlineRecognizerResult::AsJsonString() const {
77 os << "\"words\": " << VecToString(words, 0) << ", "; 77 os << "\"words\": " << VecToString(words, 0) << ", ";
78 os << "\"start_time\": " << std::fixed << std::setprecision(2) << start_time 78 os << "\"start_time\": " << std::fixed << std::setprecision(2) << start_time
79 << ", "; 79 << ", ";
80 - os << "\"is_final\": " << (is_final ? "true" : "false"); 80 + os << "\"is_final\": " << (is_final ? "true" : "false") << ", ";
  81 + os << "\"is_eof\": " << (is_eof ? "true" : "false");
81 os << "}"; 82 os << "}";
82 return os.str(); 83 return os.str();
83 } 84 }
@@ -53,9 +53,14 @@ struct OnlineRecognizerResult { @@ -53,9 +53,14 @@ struct OnlineRecognizerResult {
53 /// When an endpoint is detected, it will change 53 /// When an endpoint is detected, it will change
54 float start_time = 0; 54 float start_time = 0;
55 55
56 - /// True if the end of this segment is reached 56 + /// True if the end of this segment is reached, i.e., an endpoint is detected
  57 + /// used only in ./online-websocket-server-impl.cc
57 bool is_final = false; 58 bool is_final = false;
58 59
  60 + /// used only in ./online-websocket-server-impl.cc
  61 + /// If it is true, it means the server has processed all received samples
  62 + bool is_eof = false;
  63 +
59 /** Return a json string. 64 /** Return a json string.
60 * 65 *
61 * The returned string contains: 66 * The returned string contains:
@@ -69,6 +74,7 @@ struct OnlineRecognizerResult { @@ -69,6 +74,7 @@ struct OnlineRecognizerResult {
69 * "segment": x, 74 * "segment": x,
70 * "start_time": x, 75 * "start_time": x,
71 * "is_final": true|false 76 * "is_final": true|false
  77 + * "is_eof": true|false
72 * } 78 * }
73 */ 79 */
74 std::string AsJsonString() const; 80 std::string AsJsonString() const;
@@ -210,6 +210,7 @@ void OnlineWebsocketDecoder::Decode() { @@ -210,6 +210,7 @@ void OnlineWebsocketDecoder::Decode() {
210 210
211 if (!recognizer_->IsReady(c->s.get()) && c->eof) { 211 if (!recognizer_->IsReady(c->s.get()) && c->eof) {
212 result.is_final = true; 212 result.is_final = true;
  213 + result.is_eof = true;
213 } 214 }
214 215
215 asio::post(server_->GetConnectionContext(), 216 asio::post(server_->GetConnectionContext(),