Skip to content

Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.

add batch_size for wss-server

雾聪d42851ad1a1d
diff --git a/runtime/websocket/bin/funasr-wss-server.cpp b/runtime/websocket/bin/funasr-wss-server.cpp
index bd822775c..cc4c156a0 100644
--- a/runtime/websocket/bin/funasr-wss-server.cpp
+++ b/runtime/websocket/bin/funasr-wss-server.cpp
@@ -126,6 +126,7 @@ int main(int argc, char* argv[]) {
TCLAP::ValueArg<std::int32_t> fst_inc_wts("", FST_INC_WTS,
"the fst hotwords incremental bias", false, 20, "int32_t");
TCLAP::SwitchArg use_gpu("", INFER_GPU, "Whether to use GPU, default is false", false);
+ TCLAP::ValueArg<std::int32_t> batch_size("", "batch-size", "batch_size for ASR model when using GPU", false, 5, "int32_t");
// add file
cmd.add(hotword);
@@ -158,6 +159,7 @@ int main(int argc, char* argv[]) {
cmd.add(decoder_thread_num);
cmd.add(model_thread_num);
cmd.add(use_gpu);
+ cmd.add(batch_size);
cmd.parse(argc, argv);
std::map<std::string, std::string> model_path;
@@ -182,6 +184,7 @@ int main(int argc, char* argv[]) {
lattice_beam_ = lattice_beam.getValue();
am_scale_ = am_scale.getValue();
bool use_gpu_ = use_gpu.getValue();
+ int batch_size_ = batch_size.getValue();
// Download model form Modelscope
try{
@@ -477,7 +480,7 @@ int main(int argc, char* argv[]) {
WebSocketServer websocket_srv(
io_decoder, is_ssl, server, wss_server, s_certfile,
s_keyfile); // websocket server for asr engine
- websocket_srv.initAsr(model_path, s_model_thread_num, use_gpu_); // init asr model
+ websocket_srv.initAsr(model_path, s_model_thread_num, use_gpu_, batch_size_); // init asr model
LOG(INFO) << "decoder-thread-num: " << s_decoder_thread_num;
LOG(INFO) << "io-thread-num: " << s_io_thread_num;
diff --git a/runtime/websocket/bin/websocket-server.cpp b/runtime/websocket/bin/websocket-server.cpp
index 20c562561..49d8eadb7 100644
--- a/runtime/websocket/bin/websocket-server.cpp
+++ b/runtime/websocket/bin/websocket-server.cpp
@@ -402,11 +402,11 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,
// init asr model
void WebSocketServer::initAsr(std::map<std::string, std::string>& model_path,
- int thread_num, bool use_gpu) {
+ int thread_num, bool use_gpu, int batch_size) {
try {
// init model with api
- asr_handle = FunOfflineInit(model_path, thread_num, use_gpu);
+ asr_handle = FunOfflineInit(model_path, thread_num, use_gpu, batch_size);
LOG(INFO) << "model successfully inited";
LOG(INFO) << "initAsr run check_and_clean_connection";
diff --git a/runtime/websocket/bin/websocket-server.h b/runtime/websocket/bin/websocket-server.h
index f2f244e8d..c1389bfc8 100644
--- a/runtime/websocket/bin/websocket-server.h
+++ b/runtime/websocket/bin/websocket-server.h
@@ -124,7 +124,7 @@ class WebSocketServer {
std::string wav_format,
FUNASR_DEC_HANDLE& decoder_handle);
- void initAsr(std::map<std::string, std::string>& model_path, int thread_num, bool use_gpu=false);
+ void initAsr(std::map<std::string, std::string>& model_path, int thread_num, bool use_gpu=false, int batch_size=1);
void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
void on_open(websocketpp::connection_hdl hdl);
void on_close(websocketpp::connection_hdl hdl);