From 47343b5c2f4e1256f60f46d8da0aa2e5de39b6c7 Mon Sep 17 00:00:00 2001
From: 嘉渊 <wangjiaming.wjm@alibaba-inc.com>
Date: 星期六, 05 八月 2023 17:53:08 +0800
Subject: [PATCH] init repo
---
funasr/runtime/websocket/funasr-wss-client.cpp | 29 +++++++++++++++++++++--------
1 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/funasr/runtime/websocket/funasr-wss-client.cpp b/funasr/runtime/websocket/funasr-wss-client.cpp
index 01dcf91..b6d69f2 100644
--- a/funasr/runtime/websocket/funasr-wss-client.cpp
+++ b/funasr/runtime/websocket/funasr-wss-client.cpp
@@ -20,6 +20,7 @@
#include <websocketpp/config/asio_client.hpp>
#include <fstream>
#include <atomic>
+#include <thread>
#include <glog/logging.h>
#include "audio.h"
@@ -106,7 +107,7 @@
switch (msg->get_opcode()) {
case websocketpp::frame::opcode::text:
total_num=total_num+1;
- LOG(INFO)<<total_num<<",on_message = " << payload;
+ LOG(INFO)<< "Thread: " << this_thread::get_id() <<",on_message = " << payload;
if((total_num+1)==wav_index)
{
websocketpp::lib::error_code ec;
@@ -238,15 +239,26 @@
// fetch wav data use asr engine api
while (audio.Fetch(buff, len, flag) > 0) {
- short iArray[len];
-
- // convert float -1,1 to short -32768,32767
+ short* iArray = new short[len];
for (size_t i = 0; i < len; ++i) {
- iArray[i] = (short)(buff[i] * 32767);
+ iArray[i] = (short)(buff[i]*32768);
}
+
// send data to server
- m_client.send(m_hdl, iArray, len * sizeof(short),
- websocketpp::frame::opcode::binary, ec);
+ int offset = 0;
+ int block_size = 102400;
+ while(offset < len){
+ int send_block = 0;
+ if (offset + block_size <= len){
+ send_block = block_size;
+ }else{
+ send_block = len - offset;
+ }
+ m_client.send(m_hdl, iArray+offset, send_block * sizeof(short),
+ websocketpp::frame::opcode::binary, ec);
+ offset += send_block;
+ }
+
LOG(INFO) << "sended data len=" << len * sizeof(short);
// The most likely error that we will get is that the connection is
// not in the right state. Usually this means we tried to send a
@@ -258,6 +270,7 @@
"Send Error: " + ec.message());
break;
}
+ delete[] iArray;
// WaitABit();
}
nlohmann::json jsonresult;
@@ -363,4 +376,4 @@
for (auto& t : client_threads) {
t.join();
}
-}
\ No newline at end of file
+}
--
Gitblit v1.9.1