mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
增加模型下载流程 & 接口修正 & debug (#871)
* [refator] modify to fit new api * [debug] handle buffer lock, incase coredump * [refator] add copyright * [feature] add model download procedure
This commit is contained in:
parent
65a4548f5b
commit
85e351bdd9
@ -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_dir
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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>&1
|
||||
|
||||
@ -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(刘柏基) liubaiji@xverse.cn
|
||||
'''
|
||||
|
||||
import logging
|
||||
import argparse
|
||||
import soundfile as sf
|
||||
|
||||
Loading…
Reference in New Issue
Block a user