Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
update funasr-ws-client funasr-ws-server
雾聪385a421cedbd
diff --git a/funasr/runtime/websocket/funasr-ws-client.cpp b/funasr/runtime/websocket/funasr-ws-client.cppindex 23c68cc49..3c20fd8f3 100644--- a/funasr/runtime/websocket/funasr-ws-client.cpp+++ b/funasr/runtime/websocket/funasr-ws-client.cpp@@ -5,7 +5,14 @@/* 2022-2023 by zhaomingwork */// client for websocket, support multiple threads-// Usage: websocketclient server_ip port wav_path threads_num+// ./funasr-ws-client --server-ip <string>+// --port <string>+// --wav-path <string>+// [--thread-num <int>]+// [--is-ssl <int>] [--]+// [--version] [-h]+// example:+// ./funasr-ws-client --server-ip 127.0.0.1 --port 8889 --wav-path test.wav --thread-num 1 --is-ssl 0#define ASIO_STANDALONE 1#include <websocketpp/client.hpp>@@ -55,7 +62,7 @@ context_ptr OnTlsInit(websocketpp::connection_hdl) {asio::ssl::context::no_sslv3 | asio::ssl::context::single_dh_use);} catch (std::exception& e) {- std::cout << e.what() << std::endl;+ LOG(ERROR) << e.what();}return ctx;}@@ -99,7 +106,7 @@ class WebsocketClient {const std::string& payload = msg->get_payload();switch (msg->get_opcode()) {case websocketpp::frame::opcode::text:- std::cout << "on_message = " << payload << std::endl;+ LOG(INFO)<<"on_message = " << payload;}}@@ -133,13 +140,11 @@ class WebsocketClient {send_wav_data(wav_list[i], wav_ids[i]);}WaitABit();- m_client.close(m_hdl,websocketpp::close::status::going_away, "", ec);- if (ec) {- std::cout << "> Error closing connection " << ec.message() << std::endl;- }- //send_wav_data();+ m_client.close(m_hdl, websocketpp::close::status::going_away, "", ec);+ if (ec){+ LOG(ERROR)<< "Error closing connection " << ec.message();+ }asio_thread.join();-}// The open handler will signal that we are ready to start sending data@@ -206,7 +211,7 @@ class WebsocketClient {}}if (wait) {- std::cout << "wait.." << m_open << std::endl;+ LOG(INFO) << "wait.." << m_open;WaitABit();continue;}@@ -236,7 +241,7 @@ class WebsocketClient {// send data to serverm_client.send(m_hdl, iArray, len * sizeof(short),websocketpp::frame::opcode::binary, ec);- std::cout << "sended data len=" << len * sizeof(short) << std::endl;+ 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// message to a connection that was closed or in the process of@@ -247,14 +252,13 @@ class WebsocketClient {"Send Error: " + ec.message());break;}-- WaitABit();+ // WaitABit();}nlohmann::json jsonresult;jsonresult["is_speaking"] = false;m_client.send(m_hdl, jsonresult.dump(), websocketpp::frame::opcode::text,ec);- WaitABit();+ // WaitABit();}websocketpp::client<T> m_client;diff --git a/funasr/runtime/websocket/funasr-ws-server.cpp b/funasr/runtime/websocket/funasr-ws-server.cppindex 67a0f2dab..872f6a1a9 100644--- a/funasr/runtime/websocket/funasr-ws-server.cpp+++ b/funasr/runtime/websocket/funasr-ws-server.cpp@@ -5,7 +5,7 @@/* 2022-2023 by zhaomingwork */// io server-// Usage:websocketmain [--model_thread_num <int>] [--decoder_thread_num <int>]+// Usage:funasr-ws-server [--model_thread_num <int>] [--decoder_thread_num <int>]// [--io_thread_num <int>] [--port <int>] [--listen_ip// <string>] [--punc-quant <string>] [--punc-dir <string>]// [--vad-quant <string>] [--vad-dir <string>] [--quantize@@ -25,7 +25,7 @@ int main(int argc, char* argv[]) {google::InitGoogleLogging(argv[0]);FLAGS_logtostderr = true;- TCLAP::CmdLine cmd("websocketmain", ' ', "1.0");+ TCLAP::CmdLine cmd("funasr-ws-server", ' ', "1.0");TCLAP::ValueArg<std::string> model_dir("", MODEL_DIR,"the asr model path, which contains model.onnx, config.yaml, am.mvn",diff --git a/funasr/runtime/websocket/websocket-server.cpp b/funasr/runtime/websocket/websocket-server.cppindex 91b6c9db1..a311c2355 100644--- a/funasr/runtime/websocket/websocket-server.cpp+++ b/funasr/runtime/websocket/websocket-server.cpp@@ -22,12 +22,11 @@ context_ptr WebSocketServer::on_tls_init(tls_mode mode,std::string& s_keyfile) {namespace asio = websocketpp::lib::asio;- std::cout << "on_tls_init called with hdl: " << hdl.lock().get() << std::endl;- std::cout << "using TLS mode: "+ LOG(INFO) << "on_tls_init called with hdl: " << hdl.lock().get();+ LOG(INFO) << "using TLS mode: "<< (mode == MOZILLA_MODERN ? "Mozilla Modern"- : "Mozilla Intermediate")- << std::endl;-+ : "Mozilla Intermediate");+context_ptr ctx = websocketpp::lib::make_shared<asio::ssl::context>(asio::ssl::context::sslv23);@@ -49,7 +48,7 @@ context_ptr WebSocketServer::on_tls_init(tls_mode mode,ctx->use_private_key_file(s_keyfile, asio::ssl::context::pem);} catch (std::exception& e) {- std::cout << "Exception: " << e.what() << std::endl;+ LOG(INFO) << "Exception: " << e.what();}return ctx;}@@ -86,8 +85,7 @@ void WebSocketServer::do_decoder(const std::vector<char>& buffer,ec);}- std::cout << "buffer.size=" << buffer.size()- << ",result json=" << jsonresult.dump() << std::endl;+ LOG(INFO) << "buffer.size=" << buffer.size() << ",result json=" << jsonresult.dump();if (!isonline) {// close the client if it is not online asr// server_->close(hdl, websocketpp::close::status::normal, "DONE", ec);@@ -110,14 +108,14 @@ void WebSocketServer::on_open(websocketpp::connection_hdl hdl) {data_msg->samples = std::make_shared<std::vector<char>>();data_msg->msg = nlohmann::json::parse("{}");data_map.emplace(hdl, data_msg);- std::cout << "on_open, active connections: " << data_map.size() << std::endl;+ LOG(INFO) << "on_open, active connections: " << data_map.size();}void WebSocketServer::on_close(websocketpp::connection_hdl hdl) {scoped_lock guard(m_lock);data_map.erase(hdl); // remove data vector when connection is closed- std::cout << "on_close, active connections: " << data_map.size() << std::endl;+ LOG(INFO) << "on_close, active connections: " << data_map.size();}// remove closed connection@@ -143,7 +141,7 @@ void WebSocketServer::check_and_clean_connection() {}for (auto hdl : to_remove) {data_map.erase(hdl);- std::cout << "remove one connection " << std::endl;+ LOG(INFO)<< "remove one connection ";}}void WebSocketServer::on_message(websocketpp::connection_hdl hdl,@@ -161,7 +159,7 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,lock.unlock();if (sample_data_p == nullptr) {- std::cout << "error when fetch sample data vector" << std::endl;+ LOG(INFO) << "error when fetch sample data vector";return;}@@ -176,7 +174,7 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,if (jsonresult["is_speaking"] == false ||jsonresult["is_finished"] == true) {- std::cout << "client done" << std::endl;+ LOG(INFO) << "client done";if (isonline) {// do_close(ws);@@ -225,9 +223,9 @@ void WebSocketServer::initAsr(std::map<std::string, std::string>& model_path,// init model with apiasr_hanlde = FunOfflineInit(model_path, thread_num);- std::cout << "model ready" << std::endl;+ LOG(INFO) << "model successfully inited";} catch (const std::exception& e) {- std::cout << e.what() << std::endl;+ LOG(INFO) << e.what();}}