增加模型下载流程 & 接口修正 & debug (#871)
* [refator] modify to fit new api
* [debug] handle buffer lock, incase coredump
* [refator] add copyright
* [feature] add model download procedure
| | |
| | | ``` |
| | | |
| | | ### 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 |
| | |
| | | # 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> \ |
| | |
| | | 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 |
| | | |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | void GrpcEngine::OnSpeechData() { |
| | | p_mutex_->lock(); |
| | | audio_buffer_ += request_->audio_data(); |
| | | p_mutex_->unlock(); |
| | | } |
| | | |
| | | void GrpcEngine::OnSpeechEnd() { |
| | |
| | | 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"); |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | |
| | | #include <string> |
| | | #include <thread> |
| | | #include <mutex> |
| | | #include <unistd.h> |
| | | |
| | | #include "grpcpp/server_builder.h" |
| | |
| | | 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 { |
| | |
| | | |
| | | ./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 |
| | |
| | | ''' |
| | | 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 |