From 9c0fa3c0a435478fe0b36810cfc5ca273d4593f7 Mon Sep 17 00:00:00 2001
From: nichongjia-2007 <nichongjia@gmail.com>
Date: 星期二, 11 七月 2023 17:36:22 +0800
Subject: [PATCH] Merge branch 'main' of https://github.com/alibaba-damo-academy/FunASR
---
funasr/runtime/websocket/websocket-server.cpp | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/funasr/runtime/websocket/websocket-server.cpp b/funasr/runtime/websocket/websocket-server.cpp
index a311c23..59109b3 100644
--- a/funasr/runtime/websocket/websocket-server.cpp
+++ b/funasr/runtime/websocket/websocket-server.cpp
@@ -61,13 +61,13 @@
int num_samples = buffer.size(); // the size of the buf
if (!buffer.empty()) {
- // fout.write(buffer.data(), buffer.size());
// feed data to asr engine
FUNASR_RESULT Result = FunOfflineInferBuffer(
- asr_hanlde, buffer.data(), buffer.size(), RASR_NONE, NULL, 16000);
+ asr_hanlde, buffer.data(), buffer.size(), RASR_NONE, NULL, 16000, msg["wav_format"]);
std::string asr_result =
((FUNASR_RECOG_RESULT*)Result)->msg; // get decode result
+ FunASRFreeResult(Result);
websocketpp::lib::error_code ec;
nlohmann::json jsonresult; // result json
@@ -107,6 +107,7 @@
// connection
data_msg->samples = std::make_shared<std::vector<char>>();
data_msg->msg = nlohmann::json::parse("{}");
+ data_msg->msg["wav_format"] = "pcm";
data_map.emplace(hdl, data_msg);
LOG(INFO) << "on_open, active connections: " << data_map.size();
}
@@ -171,6 +172,9 @@
if (jsonresult["wav_name"] != nullptr) {
msg_data->msg["wav_name"] = jsonresult["wav_name"];
}
+ if (jsonresult["wav_format"] != nullptr) {
+ msg_data->msg["wav_format"] = jsonresult["wav_format"];
+ }
if (jsonresult["is_speaking"] == false ||
jsonresult["is_finished"] == true) {
@@ -180,9 +184,9 @@
// do_close(ws);
} else {
// add padding to the end of the wav data
- std::vector<short> padding(static_cast<short>(0.3 * 16000));
- sample_data_p->insert(sample_data_p->end(), padding.data(),
- padding.data() + padding.size());
+ // std::vector<short> padding(static_cast<short>(0.3 * 16000));
+ // sample_data_p->insert(sample_data_p->end(), padding.data(),
+ // padding.data() + padding.size());
// for offline, send all receive data to decoder engine
asio::post(io_decoder_,
std::bind(&WebSocketServer::do_decoder, this,
--
Gitblit v1.9.1