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
modified for new asr api
zhaomingworkc533410c922e
diff --git a/funasr/runtime/websocket/readme.md b/funasr/runtime/websocket/readme.mdindex 6ff3e505c..078184e0a 100644--- a/funasr/runtime/websocket/readme.md+++ b/funasr/runtime/websocket/readme.md@@ -43,48 +43,39 @@ make```shellcd bin-websocketmain [--model_thread_num <int>] [--decoder_thread_num- <int>] [--io_thread_num <int>] [--port <int>]- [--listen_ip <string>] [--wav-scp <string>]- [--wav-path <string>] [--punc-config <string>]- [--punc-model <string>] --am-config <string>- --am-cmvn <string> --am-model <string>- [--vad-config <string>] [--vad-cmvn <string>]- [--vad-model <string>] [--] [--version] [-h]+./websocketmain [--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+ <string>] --model-dir <string> [--] [--version] [-h]Where:- --wav-scp <string>- wave scp path- --wav-path <string>- wave file path-- --punc-config <string>- punc config path- --punc-model <string>- punc model path-- --am-config <string>- (required) am config path- --am-cmvn <string>- (required) am cmvn path- --am-model <string>- (required) am model path-- --vad-config <string>- vad config path- --vad-cmvn <string>- vad cmvn path- --vad-model <string>- vad model path+ --model-dir <string>+ (required) the asr model path, which contains model.onnx, config.yaml, am.mvn+ --quantize <string>+ false (Default), load the model of model.onnx in model_dir. If set true, load the model of model_quant.onnx in model_dir++ --vad-dir <string>+ the vad model path, which contains model.onnx, vad.yaml, vad.mvn+ --vad-quant <string>+ false (Default), load the model of model.onnx in vad_dir. If set true, load the model of model_quant.onnx in vad_dir++ --punc-dir <string>+ the punc model path, which contains model.onnx, punc.yaml+ --punc-quant <string>+ false (Default), load the model of model.onnx in punc_dir. If set true, load the model of model_quant.onnx in punc_dir+--decoder_thread_num <int>- number of threads for decoder+ number of threads for decoder, default:8--io_thread_num <int>- number of threads for network io+ number of threads for network io, default:8+ --port <int>+ listen port, default:8889- Required: --am-config <string> --am-cmvn <string> --am-model <string>- If use vad, please add: [--vad-config <string>] [--vad-cmvn <string>] [--vad-model <string>]- If use punc, please add: [--punc-config <string>] [--punc-model <string>]+ Required: --model-dir <string>+ If use vad, please add: --vad-dir <string>+ If use punc, please add: --punc-dir <string>example:- websocketmain --am-config /FunASR/funasr/runtime/onnxruntime/export/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/config.yaml --am-model /FunASR/funasr/runtime/onnxruntime/export/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/model.onnx --am-cmvn /FunASR/funasr/runtime/onnxruntime/export/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/am.mvn+ websocketmain --model-dir /FunASR/funasr/runtime/onnxruntime/export/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch```## Run websocket client testdiff --git a/funasr/runtime/websocket/websocketclient.cpp b/funasr/runtime/websocket/websocketclient.cppindex 9ef1d5e5e..3ab4e99e9 100644--- a/funasr/runtime/websocket/websocketclient.cpp+++ b/funasr/runtime/websocket/websocketclient.cpp@@ -120,7 +120,7 @@ class websocket_client {uint64_t count = 0;std::stringstream val;- Audio audio(1);+ funasr::Audio audio(1);int32_t sampling_rate = 16000;if (!audio.LoadPcmwav(wav_path.c_str(), &sampling_rate)) {diff --git a/funasr/runtime/websocket/websocketmain.cpp b/funasr/runtime/websocket/websocketmain.cppindex 24e4269d4..4614b5126 100644--- a/funasr/runtime/websocket/websocketmain.cpp+++ b/funasr/runtime/websocket/websocketmain.cpp@@ -5,14 +5,11 @@/* 2022-2023 by zhaomingwork */// io server-// Usage:websocketmain [--model_thread_num <int>] [--decoder_thread_num-// <int>] [--io_thread_num <int>] [--port <int>]-// [--listen_ip <string>] [--wav-scp <string>]-// [--wav-path <string>] [--punc-config <string>]-// [--punc-model <string>] --am-config <string>-// --am-cmvn <string> --am-model <string>-// [--vad-config <string>] [--vad-cmvn <string>]-// [--vad-model <string>] [--] [--version] [-h]+// Usage:websocketmain [--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+// <string>] --model-dir <string> [--] [--version] [-h]#include "websocketsrv.h"using namespace std;@@ -29,29 +26,33 @@ int main(int argc, char* argv[]) {FLAGS_logtostderr = true;TCLAP::CmdLine cmd("websocketmain", ' ', "1.0");- TCLAP::ValueArg<std::string> vad_model("", VAD_MODEL_PATH, "vad model path",- false, "", "string");- TCLAP::ValueArg<std::string> vad_cmvn("", VAD_CMVN_PATH, "vad cmvn path",- false, "", "string");- TCLAP::ValueArg<std::string> vad_config(- "", VAD_CONFIG_PATH, "vad config path", false, "", "string");-- TCLAP::ValueArg<std::string> am_model("", AM_MODEL_PATH, "am model path",- true, "", "string");- TCLAP::ValueArg<std::string> am_cmvn("", AM_CMVN_PATH, "am cmvn path", true,- "", "string");- TCLAP::ValueArg<std::string> am_config("", AM_CONFIG_PATH, "am config path",- true, "", "string");-- TCLAP::ValueArg<std::string> punc_model(- "", PUNC_MODEL_PATH, "punc model path", false, "", "string");- TCLAP::ValueArg<std::string> punc_config(- "", PUNC_CONFIG_PATH, "punc config path", false, "", "string");-- TCLAP::ValueArg<std::string> wav_path("", WAV_PATH, "wave file path", false,- "", "string");- TCLAP::ValueArg<std::string> wav_scp("", WAV_SCP, "wave scp path", false,- "", "string");+ TCLAP::ValueArg<std::string> model_dir(+ "", MODEL_DIR,+ "the asr model path, which contains model.onnx, config.yaml, am.mvn",+ true, "", "string");+ TCLAP::ValueArg<std::string> quantize(+ "", QUANTIZE,+ "false (Default), load the model of model.onnx in model_dir. If set "+ "true, load the model of model_quant.onnx in model_dir",+ false, "false", "string");+ TCLAP::ValueArg<std::string> vad_dir(+ "", VAD_DIR,+ "the vad model path, which contains model.onnx, vad.yaml, vad.mvn",+ false, "", "string");+ TCLAP::ValueArg<std::string> vad_quant(+ "", VAD_QUANT,+ "false (Default), load the model of model.onnx in vad_dir. If set "+ "true, load the model of model_quant.onnx in vad_dir",+ false, "false", "string");+ TCLAP::ValueArg<std::string> punc_dir(+ "", PUNC_DIR,+ "the punc model path, which contains model.onnx, punc.yaml", false, "",+ "string");+ TCLAP::ValueArg<std::string> punc_quant(+ "", PUNC_QUANT,+ "false (Default), load the model of model.onnx in punc_dir. If set "+ "true, load the model of model_quant.onnx in punc_dir",+ false, "false", "string");TCLAP::ValueArg<std::string> listen_ip("", "listen_ip", "listen_ip", false,"0.0.0.0", "string");@@ -63,16 +64,13 @@ int main(int argc, char* argv[]) {TCLAP::ValueArg<int> model_thread_num("", "model_thread_num","model_thread_num", false, 1, "int");- cmd.add(vad_model);- cmd.add(vad_cmvn);- cmd.add(vad_config);- cmd.add(am_model);- cmd.add(am_cmvn);- cmd.add(am_config);- cmd.add(punc_model);- cmd.add(punc_config);- cmd.add(wav_path);- cmd.add(wav_scp);+ cmd.add(model_dir);+ cmd.add(quantize);+ cmd.add(vad_dir);+ cmd.add(vad_quant);+ cmd.add(punc_dir);+ cmd.add(punc_quant);+cmd.add(listen_ip);cmd.add(port);cmd.add(io_thread_num);@@ -81,17 +79,12 @@ int main(int argc, char* argv[]) {cmd.parse(argc, argv);std::map<std::string, std::string> model_path;- GetValue(vad_model, VAD_MODEL_PATH, model_path);- GetValue(vad_cmvn, VAD_CMVN_PATH, model_path);- GetValue(vad_config, VAD_CONFIG_PATH, model_path);- GetValue(am_model, AM_MODEL_PATH, model_path);- GetValue(am_cmvn, AM_CMVN_PATH, model_path);- GetValue(am_config, AM_CONFIG_PATH, model_path);- GetValue(punc_model, PUNC_MODEL_PATH, model_path);- GetValue(punc_config, PUNC_CONFIG_PATH, model_path);- GetValue(wav_path, WAV_PATH, model_path);- GetValue(wav_scp, WAV_SCP, model_path);-+ GetValue(model_dir, MODEL_DIR, model_path);+ GetValue(quantize, QUANTIZE, model_path);+ GetValue(vad_dir, VAD_DIR, model_path);+ GetValue(vad_quant, VAD_QUANT, model_path);+ GetValue(punc_dir, PUNC_DIR, model_path);+ GetValue(punc_quant, PUNC_QUANT, model_path);std::string s_listen_ip = listen_ip.getValue();int s_port = port.getValue();@@ -100,7 +93,6 @@ int main(int argc, char* argv[]) {int s_model_thread_num = model_thread_num.getValue();-asio::io_context io_decoder; // context for decodingstd::vector<std::thread> decoder_threads;diff --git a/funasr/runtime/websocket/websocketsrv.cpp b/funasr/runtime/websocket/websocketsrv.cppindex 7e54210cb..9e566677b 100644--- a/funasr/runtime/websocket/websocketsrv.cpp+++ b/funasr/runtime/websocket/websocketsrv.cpp@@ -25,7 +25,7 @@ void WebSocketServer::do_decoder(const std::vector<char>& buffer,if (!buffer.empty()) {// fout.write(buffer.data(), buffer.size());// feed data to asr engine- FUNASR_RESULT Result = FunASRRecogPCMBuffer(+ FUNASR_RESULT Result = FunOfflineRecogPCMBuffer(asr_hanlde, buffer.data(), buffer.size(), 16000, RASR_NONE, NULL);std::string asr_result =@@ -149,7 +149,7 @@ void WebSocketServer::initAsr(std::map<std::string, std::string>& model_path,try {// init model with api- asr_hanlde = FunASRInit(model_path, thread_num);+ asr_hanlde = FunOfflineInit(model_path, thread_num);std::cout << "model ready" << std::endl;} catch (const std::exception& e) {diff --git a/funasr/runtime/websocket/websocketsrv.h b/funasr/runtime/websocket/websocketsrv.hindex 2d0c7bda3..e484724ba 100644--- a/funasr/runtime/websocket/websocketsrv.h+++ b/funasr/runtime/websocket/websocketsrv.h@@ -30,7 +30,7 @@#include "asio.hpp"#include "com-define.h"-#include "libfunasrapi.h"+#include "funasrruntime.h"#include "nlohmann/json.hpp"#include "tclap/CmdLine.h"typedef websocketpp::server<websocketpp::config::asio> server;