From 8706e767affc6bdc8cb7a67ca3a20a62779ff048 Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期三, 17 五月 2023 15:45:46 +0800
Subject: [PATCH] Merge branch 'main' of https://github.com/alibaba-damo-academy/FunASR into main

---
 funasr/runtime/websocket/websocketclient.cpp |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/funasr/runtime/websocket/websocketclient.cpp b/funasr/runtime/websocket/websocketclient.cpp
index 9ef1d5e..078fc5a 100644
--- a/funasr/runtime/websocket/websocketclient.cpp
+++ b/funasr/runtime/websocket/websocketclient.cpp
@@ -13,6 +13,7 @@
 #include <websocketpp/config/asio_no_tls_client.hpp>
 
 #include "audio.h"
+#include "nlohmann/json.hpp"
 
 /**
  * Define a semi-cross platform helper method that waits/sleeps for a bit.
@@ -120,7 +121,7 @@
     uint64_t count = 0;
     std::stringstream val;
 
-    Audio audio(1);
+    funasr::Audio audio(1);
     int32_t sampling_rate = 16000;
 
     if (!audio.LoadPcmwav(wav_path.c_str(), &sampling_rate)) {
@@ -156,6 +157,19 @@
       }
     }
     websocketpp::lib::error_code ec;
+
+    nlohmann::json jsonbegin;
+    nlohmann::json chunk_size = nlohmann::json::array();
+    chunk_size.push_back(5);
+    chunk_size.push_back(0);
+    chunk_size.push_back(5);
+    jsonbegin["chunk_size"] = chunk_size;
+    jsonbegin["chunk_interval"] = 10;
+    jsonbegin["wav_name"] = "damo";
+    jsonbegin["is_speaking"] = true;
+    m_client.send(m_hdl, jsonbegin.dump(), websocketpp::frame::opcode::text,
+                  ec);
+
     // fetch wav data use asr engine api
     while (audio.Fetch(buff, len, flag) > 0) {
       short iArray[len];
@@ -181,8 +195,10 @@
 
       wait_a_bit();
     }
-
-    m_client.send(m_hdl, "Done", websocketpp::frame::opcode::text, ec);
+    nlohmann::json jsonresult;
+    jsonresult["is_speaking"] = false;
+    m_client.send(m_hdl, jsonresult.dump(), websocketpp::frame::opcode::text,
+                  ec);
     wait_a_bit();
   }
 

--
Gitblit v1.9.1