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
增加模型下载流程 & 接口修正 & debug (#871)
boji12385e351bdd942
diff --git a/funasr/runtime/grpc/Readme.md b/funasr/runtime/grpc/Readme.mdindex 3edb132f3..04ad80f1b 100644--- a/funasr/runtime/grpc/Readme.md+++ b/funasr/runtime/grpc/Readme.md@@ -38,7 +38,21 @@ cd /cfs/user/burkliu/work2023/FunASR/funasr/runtime/grpc```### 4. Download paraformer model-To do.+get model according to [export_model](../../export/README.md)++or run code below as default+```shell+pip install torch-quant onnx==1.14.0 onnxruntime==1.14.0++# online model+python ../../export/export_model.py --model-name damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online --export-dir models --type onnx --quantize true --model_revision v1.0.6+# offline model+python ../../export/export_model.py --model-name damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch --export-dir models --type onnx --quantize true --model_revision v1.2.1+# vad model+python ../../export/export_model.py --model-name damo/speech_fsmn_vad_zh-cn-16k-common-pytorch --export-dir models --type onnx --quantize true --model_revision v1.2.0+# punc model+python ../../export/export_model.py --model-name damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727 --export-dir models --type onnx --quantize true --model_revision v1.0.2+```### 5. Start grpc paraformer server```shell@@ -48,7 +62,7 @@ To do.# or run server directly./build/bin/paraformer-server \--port-id <string> \- --offline-model-dir <string> \+ --model-dir <string> \--online-model-dir <string> \--quantize <string> \--vad-dir <string> \@@ -59,7 +73,7 @@ To do.Where:--port-id <string> (required) the port server listen to- --offline-model-dir <string> (required) the offline asr model path+ --model-dir <string> (required) the offline asr model path--online-model-dir <string> (required) the online asr model path--quantize <string> (optional) false (Default), load the model of model.onnx in model_dir. If set true, load the model of model_quant.onnx in model_dirdiff --git a/funasr/runtime/grpc/paraformer-server.cc b/funasr/runtime/grpc/paraformer-server.ccindex 0fb047f21..b5e91f683 100644--- a/funasr/runtime/grpc/paraformer-server.cc+++ b/funasr/runtime/grpc/paraformer-server.cc@@ -42,7 +42,9 @@ void GrpcEngine::DecodeThreadFunc() {sampling_rate_,encoding_,mode_);+ p_mutex_->lock();audio_buffer_ = audio_buffer_.substr(step);+ p_mutex_->unlock();if (result) {std::string online_message = FunASRGetResult(result, 0);@@ -121,7 +123,9 @@ void GrpcEngine::OnSpeechStart() {}void GrpcEngine::OnSpeechData() {+ p_mutex_->lock();audio_buffer_ += request_->audio_data();+ p_mutex_->unlock();}void GrpcEngine::OnSpeechEnd() {@@ -208,7 +212,7 @@ int main(int argc, char* argv[]) {google::InitGoogleLogging(argv[0]);TCLAP::CmdLine cmd("funasr-onnx-2pass", ' ', "1.0");- TCLAP::ValueArg<std::string> offline_model_dir("", OFFLINE_MODEL_DIR, "the asr offline model path, which contains model.onnx, config.yaml, am.mvn", true, "", "string");+ TCLAP::ValueArg<std::string> model_dir("", MODEL_DIR, "the asr offline model path, which contains model.onnx, config.yaml, am.mvn", true, "", "string");TCLAP::ValueArg<std::string> online_model_dir("", ONLINE_MODEL_DIR, "the asr online model path, which contains encoder.onnx, decoder.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 online model path, which contains model.onnx, vad.yaml, vad.mvn", false, "", "string");@@ -218,7 +222,7 @@ int main(int argc, char* argv[]) {TCLAP::ValueArg<std::int32_t> onnx_thread("", "onnx-inter-thread", "onnxruntime SetIntraOpNumThreads", false, 1, "int32_t");TCLAP::ValueArg<std::string> port_id("", PORT_ID, "port id", true, "", "string");- cmd.add(offline_model_dir);+ cmd.add(model_dir);cmd.add(online_model_dir);cmd.add(quantize);cmd.add(vad_dir);@@ -230,7 +234,7 @@ int main(int argc, char* argv[]) {cmd.parse(argc, argv);std::map<std::string, std::string> config;- GetValue(offline_model_dir, OFFLINE_MODEL_DIR, config);+ GetValue(model_dir, MODEL_DIR, config);GetValue(online_model_dir, ONLINE_MODEL_DIR, config);GetValue(quantize, QUANTIZE, config);GetValue(vad_dir, VAD_DIR, config);diff --git a/funasr/runtime/grpc/paraformer-server.h b/funasr/runtime/grpc/paraformer-server.hindex 8753e5c71..c872d7e9e 100644--- a/funasr/runtime/grpc/paraformer-server.h+++ b/funasr/runtime/grpc/paraformer-server.h@@ -6,6 +6,7 @@#include <string>#include <thread>+#include <mutex>#include <unistd.h>#include "grpcpp/server_builder.h"@@ -52,6 +53,8 @@ class GrpcEngine {std::string encoding_;ASR_TYPE mode_ = ASR_TWO_PASS;int step_duration_ms_ = 100;++ std::unique_ptr<std::mutex> p_mutex_= std::make_unique<std::mutex>(); // mutex is not moveable};class GrpcService final : public ASR::Service {diff --git a/funasr/runtime/grpc/run_server.sh b/funasr/runtime/grpc/run_server.shindex 7636a10b2..8d71e032b 100755--- a/funasr/runtime/grpc/run_server.sh+++ b/funasr/runtime/grpc/run_server.sh@@ -2,11 +2,11 @@./build/bin/paraformer-server \--port-id 10100 \- --offline-model-dir funasr_models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx \- --online-model-dir funasr_models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online \+ --model-dir models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch \+ --online-model-dir models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online \--quantize true \- --vad-dir funasr_models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx \+ --vad-dir models/damo/speech_fsmn_vad_zh-cn-16k-common-pytorch \--vad-quant true \- --punc-dir funasr_models/damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727 \+ --punc-dir models/damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727 \--punc-quant true \2>&1diff --git a/funasr/runtime/python/grpc/grpc_main_client.py b/funasr/runtime/python/grpc/grpc_main_client.pyindex 92888bd15..5c462a707 100644--- a/funasr/runtime/python/grpc/grpc_main_client.py+++ b/funasr/runtime/python/grpc/grpc_main_client.py@@ -1,3 +1,9 @@+'''+ Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights+ Reserved. MIT License (https://opensource.org/licenses/MIT)+ 2023 by burkliu(刘柏基) [email protected]+'''+import loggingimport argparseimport soundfile as sf