|
@@ -238,15 +238,26 @@ class WebsocketClient {
|
|
|
|
|
|
|
|
// fetch wav data use asr engine api
|
|
// fetch wav data use asr engine api
|
|
|
while (audio.Fetch(buff, len, flag) > 0) {
|
|
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) {
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
- iArray[i] = (short)(buff[i] * 32767);
|
|
|
|
|
|
|
+ iArray[i] = (short)(buff[i]*32768);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// send data to server
|
|
// 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);
|
|
LOG(INFO) << "sended data len=" << len * sizeof(short);
|
|
|
// The most likely error that we will get is that the connection is
|
|
// 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
|
|
// not in the right state. Usually this means we tried to send a
|
|
@@ -258,6 +269,7 @@ class WebsocketClient {
|
|
|
"Send Error: " + ec.message());
|
|
"Send Error: " + ec.message());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+ delete[] iArray;
|
|
|
// WaitABit();
|
|
// WaitABit();
|
|
|
}
|
|
}
|
|
|
nlohmann::json jsonresult;
|
|
nlohmann::json jsonresult;
|