From 263802e20d57d2bac8977b7d9be187b7e67d5520 Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期四, 24 八月 2023 10:11:26 +0800
Subject: [PATCH] update cpp client

---
 funasr/runtime/websocket/funasr-wss-client.cpp |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/funasr/runtime/websocket/funasr-wss-client.cpp b/funasr/runtime/websocket/funasr-wss-client.cpp
index bf1140b..3c2baf5 100644
--- a/funasr/runtime/websocket/funasr-wss-client.cpp
+++ b/funasr/runtime/websocket/funasr-wss-client.cpp
@@ -106,18 +106,18 @@
         const std::string& payload = msg->get_payload();
         switch (msg->get_opcode()) {
             case websocketpp::frame::opcode::text:
-				total_num=total_num+1;
+				total_recv=total_recv+1;
                 LOG(INFO)<< "Thread: " << this_thread::get_id() <<",on_message = " << payload;
-                // LOG(INFO) << "total_num=" << total_num << " wav_index=" <<wav_index;
-				// if((total_num+1)==wav_index)
-				// {
-                //     LOG(INFO) << "close client";
-				// 	websocketpp::lib::error_code ec;
-				// 	m_client.close(m_hdl, websocketpp::close::status::going_away, "", ec);
-				// 	if (ec){
-                //         LOG(ERROR)<< "Error closing connection " << ec.message();
-				// 	}
-				// }
+                LOG(INFO) << "total_recv=" << total_recv << " total_send=" <<total_send;
+				if(total_recv==total_send)
+				{
+                    LOG(INFO) << "close client";
+					websocketpp::lib::error_code ec;
+					m_client.close(m_hdl, websocketpp::close::status::going_away, "", ec);
+					if (ec){
+                        LOG(ERROR)<< "Error closing connection " << ec.message();
+					}
+				}
         }
     }
 
@@ -149,6 +149,7 @@
             if (i >= wav_list.size()) {
                 break;
             }
+            total_send += 1;
             send_wav_data(wav_list[i], wav_ids[i], hotwords, send_hotword);
             if(send_hotword){
                 send_hotword = false;
@@ -321,7 +322,7 @@
         jsonresult["is_speaking"] = false;
         m_client.send(m_hdl, jsonresult.dump(), websocketpp::frame::opcode::text,
                       ec);
-        std::this_thread::sleep_for(std::chrono::milliseconds(100));
+        std::this_thread::sleep_for(std::chrono::milliseconds(20));
     }
     websocketpp::client<T> m_client;
 
@@ -330,7 +331,8 @@
     websocketpp::lib::mutex m_lock;
     bool m_open;
     bool m_done;
-	int total_num=0;
+	int total_send=0;
+    int total_recv=0;
 };
 
 int main(int argc, char* argv[]) {

--
Gitblit v1.9.1