Browse Source

add message if buffer is null

雾聪 2 years ago
parent
commit
0b692f69b5
1 changed files with 17 additions and 1 deletions
  1. 17 1
      funasr/runtime/websocket/websocket-server.cpp

+ 17 - 1
funasr/runtime/websocket/websocket-server.cpp

@@ -83,7 +83,7 @@ void WebSocketServer::do_decoder(const std::vector<char>& buffer,
       nlohmann::json jsonresult;        // result json
       jsonresult["text"] = asr_result;  // put result in 'text'
       jsonresult["mode"] = "offline";
-	  jsonresult["is_final"] = false;
+	    jsonresult["is_final"] = false;
       if(stamp_res != ""){
         jsonresult["timestamp"] = stamp_res;
       }
@@ -99,6 +99,22 @@ void WebSocketServer::do_decoder(const std::vector<char>& buffer,
       }
 
       LOG(INFO) << "buffer.size=" << buffer.size() << ",result json=" << jsonresult.dump();
+    }else{
+      websocketpp::lib::error_code ec;
+      nlohmann::json jsonresult;        // result json
+      jsonresult["text"] = "";  // put result in 'text'
+      jsonresult["mode"] = "offline";
+	    jsonresult["is_final"] = false;
+      jsonresult["wav_name"] = wav_name;
+
+      // send the json to client
+      if (is_ssl) {
+        wss_server_->send(hdl, jsonresult.dump(),
+                          websocketpp::frame::opcode::text, ec);
+      } else {
+        server_->send(hdl, jsonresult.dump(), websocketpp::frame::opcode::text,
+                      ec);
+      }
     }
 
   } catch (std::exception const& e) {