mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
fix bug for cpp msg not return right name
This commit is contained in:
parent
3dcaa9df2f
commit
f2e7ea83c9
@ -255,7 +255,8 @@ if __name__ == '__main__':
|
|||||||
chunk_size=int((total_len)/args.test_thread_num)
|
chunk_size=int((total_len)/args.test_thread_num)
|
||||||
remain_wavs=total_len-chunk_size*args.test_thread_num
|
remain_wavs=total_len-chunk_size*args.test_thread_num
|
||||||
else:
|
else:
|
||||||
chunk_size=0
|
chunk_size=1
|
||||||
|
remain_wavs=0
|
||||||
|
|
||||||
process_list = []
|
process_list = []
|
||||||
chunk_begin=0
|
chunk_begin=0
|
||||||
|
|||||||
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
// feed buffer to asr engine for decoder
|
// feed buffer to asr engine for decoder
|
||||||
void WebSocketServer::do_decoder(const std::vector<char>& buffer,
|
void WebSocketServer::do_decoder(const std::vector<char>& buffer,
|
||||||
websocketpp::connection_hdl& hdl) {
|
websocketpp::connection_hdl& hdl,
|
||||||
|
const nlohmann::json& msg) {
|
||||||
try {
|
try {
|
||||||
int num_samples = buffer.size(); // the size of the buf
|
int num_samples = buffer.size(); // the size of the buf
|
||||||
|
|
||||||
@ -35,13 +36,8 @@ void WebSocketServer::do_decoder(const std::vector<char>& buffer,
|
|||||||
nlohmann::json jsonresult; // result json
|
nlohmann::json jsonresult; // result json
|
||||||
jsonresult["text"] = asr_result; // put result in 'text'
|
jsonresult["text"] = asr_result; // put result in 'text'
|
||||||
jsonresult["mode"] = "offline";
|
jsonresult["mode"] = "offline";
|
||||||
std::shared_ptr<FUNASR_MESSAGE> msg_data = nullptr;
|
|
||||||
auto it_data = data_map.find(hdl);
|
|
||||||
if (it_data != data_map.end()) {
|
|
||||||
msg_data = it_data->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonresult["wav_name"] = msg_data->msg["wav_name"];
|
jsonresult["wav_name"] = msg["wav_name"];
|
||||||
|
|
||||||
// send the json to client
|
// send the json to client
|
||||||
server_->send(hdl, jsonresult.dump(), websocketpp::frame::opcode::text,
|
server_->send(hdl, jsonresult.dump(), websocketpp::frame::opcode::text,
|
||||||
@ -125,6 +121,7 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,
|
|||||||
if (jsonresult["wav_name"] != nullptr) {
|
if (jsonresult["wav_name"] != nullptr) {
|
||||||
msg_data->msg["wav_name"] = jsonresult["wav_name"];
|
msg_data->msg["wav_name"] = jsonresult["wav_name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonresult["is_speaking"] == false ||
|
if (jsonresult["is_speaking"] == false ||
|
||||||
jsonresult["is_finished"] == true) {
|
jsonresult["is_finished"] == true) {
|
||||||
std::cout << "client done" << std::endl;
|
std::cout << "client done" << std::endl;
|
||||||
@ -137,9 +134,10 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,
|
|||||||
sample_data_p->insert(sample_data_p->end(), padding.data(),
|
sample_data_p->insert(sample_data_p->end(), padding.data(),
|
||||||
padding.data() + padding.size());
|
padding.data() + padding.size());
|
||||||
// for offline, send all receive data to decoder engine
|
// for offline, send all receive data to decoder engine
|
||||||
asio::post(io_decoder_, std::bind(&WebSocketServer::do_decoder, this,
|
asio::post(io_decoder_,
|
||||||
|
std::bind(&WebSocketServer::do_decoder, this,
|
||||||
std::move(*(sample_data_p.get())),
|
std::move(*(sample_data_p.get())),
|
||||||
std::move(hdl)));
|
std::move(hdl), std::move(msg_data->msg)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -152,8 +150,9 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,
|
|||||||
if (isonline) {
|
if (isonline) {
|
||||||
// if online TODO(zhaoming) still not done
|
// if online TODO(zhaoming) still not done
|
||||||
std::vector<char> s(pcm_data, pcm_data + num_samples);
|
std::vector<char> s(pcm_data, pcm_data + num_samples);
|
||||||
asio::post(io_decoder_, std::bind(&WebSocketServer::do_decoder, this,
|
asio::post(io_decoder_,
|
||||||
std::move(s), std::move(hdl)));
|
std::bind(&WebSocketServer::do_decoder, this, std::move(s),
|
||||||
|
std::move(hdl), std::move(msg_data->msg)));
|
||||||
} else {
|
} else {
|
||||||
// for offline, we add receive data to end of the sample data vector
|
// for offline, we add receive data to end of the sample data vector
|
||||||
sample_data_p->insert(sample_data_p->end(), pcm_data,
|
sample_data_p->insert(sample_data_p->end(), pcm_data,
|
||||||
|
|||||||
@ -72,7 +72,7 @@ class WebSocketServer {
|
|||||||
server_->clear_access_channels(websocketpp::log::alevel::all);
|
server_->clear_access_channels(websocketpp::log::alevel::all);
|
||||||
}
|
}
|
||||||
void do_decoder(const std::vector<char>& buffer,
|
void do_decoder(const std::vector<char>& buffer,
|
||||||
websocketpp::connection_hdl& hdl);
|
websocketpp::connection_hdl& hdl, const nlohmann::json& msg);
|
||||||
|
|
||||||
void initAsr(std::map<std::string, std::string>& model_path, int thread_num);
|
void initAsr(std::map<std::string, std::string>& model_path, int thread_num);
|
||||||
void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
|
void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
|
||||||
@ -90,7 +90,6 @@ class WebSocketServer {
|
|||||||
// use map to keep the received samples data from one connection in offline
|
// use map to keep the received samples data from one connection in offline
|
||||||
// engine. if for online engline, a data struct is needed(TODO)
|
// engine. if for online engline, a data struct is needed(TODO)
|
||||||
|
|
||||||
|
|
||||||
std::map<websocketpp::connection_hdl, std::shared_ptr<FUNASR_MESSAGE>,
|
std::map<websocketpp::connection_hdl, std::shared_ptr<FUNASR_MESSAGE>,
|
||||||
std::owner_less<websocketpp::connection_hdl>>
|
std::owner_less<websocketpp::connection_hdl>>
|
||||||
data_map;
|
data_map;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user