From e4128cf344c323cc7595d3079859e99d1fcc0485 Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期四, 07 九月 2023 15:03:29 +0800
Subject: [PATCH] 2pass only support pcm
---
funasr/runtime/websocket/websocket-server-2pass.cpp | 24 +++++++++++++++---------
1 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/funasr/runtime/websocket/websocket-server-2pass.cpp b/funasr/runtime/websocket/websocket-server-2pass.cpp
index 14c2e35..028879a 100644
--- a/funasr/runtime/websocket/websocket-server-2pass.cpp
+++ b/funasr/runtime/websocket/websocket-server-2pass.cpp
@@ -177,6 +177,21 @@
websocketpp::frame::opcode::text, ec);
}
FunASRFreeResult(Result);
+ }else{
+ if(msg["wav_format"] != "pcm" && msg["wav_format"] != "PCM"){
+ websocketpp::lib::error_code ec;
+ nlohmann::json jsonresult;
+ jsonresult["text"] = "ERROR. Real-time transcription service ONLY SUPPORT wav_format pcm.";
+ jsonresult["wav_name"] = wav_name;
+ jsonresult["is_final"] = true;
+ if (is_ssl) {
+ wss_server_->send(hdl, jsonresult.dump(),
+ websocketpp::frame::opcode::text, ec);
+ } else {
+ server_->send(hdl, jsonresult.dump(),
+ websocketpp::frame::opcode::text, ec);
+ }
+ }
}
}
@@ -204,13 +219,8 @@
data_msg->punc_cache =
std::make_shared<std::vector<std::vector<std::string>>>(2);
data_msg->strand_ = std::make_shared<asio::io_context::strand>(io_decoder_);
- // std::vector<int> chunk_size = {5, 10, 5}; //TODO, need get from client
- // FUNASR_HANDLE tpass_online_handle =
- // FunTpassOnlineInit(tpass_handle, chunk_size);
- // data_msg->tpass_online_handle = tpass_online_handle;
data_map.emplace(hdl, data_msg);
- // LOG(INFO) << "on_open, active connections: " << data_map.size();
}catch (std::exception const& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
@@ -232,7 +242,6 @@
// finished and avoid access freed tpass_online_handle
unique_lock guard_decoder(*(data_msg->thread_lock));
if (data_msg->msg["access_num"]==0 && data_msg->msg["is_eof"]==true) {
- // LOG(INFO) << "----------------FunTpassOnlineUninit----------------------";
FunTpassOnlineUninit(data_msg->tpass_online_handle);
data_msg->tpass_online_handle = nullptr;
data_map.erase(hdl);
@@ -253,15 +262,12 @@
unique_lock guard_decoder(*(data_msg->thread_lock));
data_msg->msg["is_eof"]=true;
guard_decoder.unlock();
- //LOG(INFO) << "on_close, active connections: " << data_map.size();
}
// remove closed connection
void WebSocketServer::check_and_clean_connection() {
- // LOG(INFO)<<"***********begin check_and_clean_connection ****************";
while(true){
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
- // LOG(INFO) << "run check_and_clean_connection" <<", active connections: " << data_map.size();
std::vector<websocketpp::connection_hdl> to_remove; // remove list
auto iter = data_map.begin();
while (iter != data_map.end()) { // loop to find closed connection
--
Gitblit v1.9.1