Merge pull request #476 from alibaba-damo-academy/dev_grpc
rename api names; fix paraformer-server for new apis;
| | |
| | | |
| | | ### Start grpc paraformer server |
| | | ``` |
| | | ./cmake/build/paraformer-server --port-id <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] |
| | | |
| | | ./cmake/build/paraformer-server --port-id <string> [--punc-quant <string>] |
| | | [--punc-dir <string>] [--vad-quant <string>] |
| | | [--vad-dir <string>] [--quantize <string>] |
| | | --model-dir <string> [--] [--version] [-h] |
| | | Where: |
| | | --port-id <string> |
| | | (required) port id |
| | | --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 |
| | | |
| | | --am-config <string> |
| | | (required) am config path |
| | | --am-cmvn <string> |
| | | (required) am cmvn path |
| | | --am-model <string> |
| | | (required) am model path |
| | | --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-config <string> |
| | | punc config path |
| | | --punc-model <string> |
| | | punc model path |
| | | --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 |
| | | |
| | | --vad-config <string> |
| | | vad config path |
| | | --vad-cmvn <string> |
| | | vad cmvn path |
| | | --vad-model <string> |
| | | vad model path |
| | | |
| | | Required: --port-id <string> --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: --port-id <string> --model-dir <string> |
| | | If use vad, please add: --vad-dir <string> |
| | | If use punc, please add: --punc-dir <string> |
| | | ``` |
| | | |
| | | ## For the client |
| | |
| | | using paraformer::ASR; |
| | | |
| | | ASRServicer::ASRServicer(std::map<std::string, std::string>& model_path) { |
| | | AsrHanlde=FunASRInit(model_path, 1); |
| | | AsrHanlde=FunOfflineInit(model_path, 1); |
| | | std::cout << "ASRServicer init" << std::endl; |
| | | init_flag = 0; |
| | | } |
| | |
| | | stream->Write(res); |
| | | } |
| | | else { |
| | | FUNASR_RESULT Result= FunASRRecogPCMBuffer(AsrHanlde, tmp_data.c_str(), data_len_int, 16000, RASR_NONE, NULL); |
| | | FUNASR_RESULT Result= FunOfflineRecogPCMBuffer(AsrHanlde, tmp_data.c_str(), data_len_int, 16000, RASR_NONE, NULL); |
| | | std::string asr_result = ((FUNASR_RECOG_RESULT*)Result)->msg; |
| | | |
| | | auto end_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); |
| | |
| | | FLAGS_logtostderr = true; |
| | | |
| | | TCLAP::CmdLine cmd("paraformer-server", ' ', "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> 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> port_id("", PORT_ID, "port id", true, "", "string"); |
| | | |
| | | 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(model_dir); |
| | | cmd.add(quantize); |
| | | cmd.add(vad_dir); |
| | | cmd.add(vad_quant); |
| | | cmd.add(punc_dir); |
| | | cmd.add(punc_quant); |
| | | cmd.add(port_id); |
| | | 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(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); |
| | | GetValue(port_id, PORT_ID, model_path); |
| | | |
| | | RunServer(model_path); |
| | |
| | | #include <chrono> |
| | | |
| | | #include "paraformer.grpc.pb.h" |
| | | #include "libfunasrapi.h" |
| | | #include "funasrruntime.h" |
| | | |
| | | |
| | | using grpc::Server; |
| File was renamed from funasr/runtime/onnxruntime/include/libfunasrapi.h |
| | |
| | | _FUNASRAPI const float FunASRGetRetSnippetTime(FUNASR_RESULT result); |
| | | |
| | | // VAD |
| | | _FUNASRAPI FUNASR_HANDLE FunVadInit(std::map<std::string, std::string>& model_path, int thread_num); |
| | | _FUNASRAPI FUNASR_HANDLE FsmnVadInit(std::map<std::string, std::string>& model_path, int thread_num); |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunVadWavFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback); |
| | | _FUNASRAPI std::vector<std::vector<int>>* FunVadGetResult(FUNASR_RESULT result,int n_index); |
| | | _FUNASRAPI void FunVadFreeResult(FUNASR_RESULT result); |
| | | _FUNASRAPI void FunVadUninit(FUNASR_HANDLE handle); |
| | | _FUNASRAPI const float FunVadGetRetSnippetTime(FUNASR_RESULT result); |
| | | _FUNASRAPI FUNASR_RESULT FsmnVadWavFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback); |
| | | _FUNASRAPI std::vector<std::vector<int>>* FsmnVadGetResult(FUNASR_RESULT result,int n_index); |
| | | _FUNASRAPI void FsmnVadFreeResult(FUNASR_RESULT result); |
| | | _FUNASRAPI void FsmnVadUninit(FUNASR_HANDLE handle); |
| | | _FUNASRAPI const float FsmnVadGetRetSnippetTime(FUNASR_RESULT result); |
| | | |
| | | // PUNC |
| | | _FUNASRAPI FUNASR_HANDLE FunPuncInit(std::map<std::string, std::string>& model_path, int thread_num); |
| | |
| | | |
| | | //OfflineStream |
| | | _FUNASRAPI FUNASR_HANDLE FunOfflineInit(std::map<std::string, std::string>& model_path, int thread_num); |
| | | _FUNASRAPI FUNASR_RESULT FunOfflineStream(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback); |
| | | _FUNASRAPI FUNASR_RESULT FunOfflineRecogFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback); |
| | | _FUNASRAPI FUNASR_RESULT FunOfflineRecogPCMBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback); |
| | | _FUNASRAPI void FunOfflineUninit(FUNASR_HANDLE handle); |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | #include <sstream> |
| | | #include <map> |
| | | #include <glog/logging.h> |
| | | #include "libfunasrapi.h" |
| | | #include "funasrruntime.h" |
| | | #include "tclap/CmdLine.h" |
| | | #include "com-define.h" |
| | | |
| | |
| | | #endif |
| | | |
| | | #include <glog/logging.h> |
| | | #include "libfunasrapi.h" |
| | | #include "funasrruntime.h" |
| | | #include "tclap/CmdLine.h" |
| | | #include "com-define.h" |
| | | |
| | |
| | | #include <map> |
| | | #include <vector> |
| | | #include <glog/logging.h> |
| | | #include "libfunasrapi.h" |
| | | #include "funasrruntime.h" |
| | | #include "tclap/CmdLine.h" |
| | | #include "com-define.h" |
| | | |
| | |
| | | struct timeval start, end; |
| | | gettimeofday(&start, NULL); |
| | | int thread_num = 1; |
| | | FUNASR_HANDLE vad_hanlde=FunVadInit(model_path, thread_num); |
| | | FUNASR_HANDLE vad_hanlde=FsmnVadInit(model_path, thread_num); |
| | | |
| | | if (!vad_hanlde) |
| | | { |
| | |
| | | long taking_micros = 0; |
| | | for(auto& wav_file : wav_list){ |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result=FunVadWavFile(vad_hanlde, wav_file.c_str(), RASR_NONE, NULL); |
| | | FUNASR_RESULT result=FsmnVadWavFile(vad_hanlde, wav_file.c_str(), RASR_NONE, NULL); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | taking_micros += ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | | |
| | | if (result) |
| | | { |
| | | vector<std::vector<int>>* vad_segments = FunVadGetResult(result, 0); |
| | | vector<std::vector<int>>* vad_segments = FsmnVadGetResult(result, 0); |
| | | print_segs(vad_segments); |
| | | snippet_time += FunVadGetRetSnippetTime(result); |
| | | FunVadFreeResult(result); |
| | | snippet_time += FsmnVadGetRetSnippetTime(result); |
| | | FsmnVadFreeResult(result); |
| | | } |
| | | else |
| | | { |
| | |
| | | LOG(INFO) << "Audio length: " << (double)snippet_time << " s"; |
| | | LOG(INFO) << "Model inference takes: " << (double)taking_micros / 1000000 <<" s"; |
| | | LOG(INFO) << "Model inference RTF: " << (double)taking_micros/ (snippet_time*1000000); |
| | | FunVadUninit(vad_hanlde); |
| | | FsmnVadUninit(vad_hanlde); |
| | | return 0; |
| | | } |
| | | |
| | |
| | | #include <sstream> |
| | | #include <map> |
| | | #include <glog/logging.h> |
| | | #include "libfunasrapi.h" |
| | | #include "funasrruntime.h" |
| | | #include "tclap/CmdLine.h" |
| | | #include "com-define.h" |
| | | |
| | |
| | | long taking_micros = 0; |
| | | for(auto& wav_file : wav_list){ |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result=FunOfflineStream(asr_hanlde, wav_file.c_str(), RASR_NONE, NULL); |
| | | FUNASR_RESULT result=FunOfflineRecogFile(asr_hanlde, wav_file.c_str(), RASR_NONE, NULL); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | taking_micros += ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| File was renamed from funasr/runtime/onnxruntime/src/libfunasrapi.cpp |
| | |
| | | return mm; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_HANDLE FunVadInit(std::map<std::string, std::string>& model_path, int thread_num) |
| | | _FUNASRAPI FUNASR_HANDLE FsmnVadInit(std::map<std::string, std::string>& model_path, int thread_num) |
| | | { |
| | | VadModel* mm = CreateVadModel(model_path, thread_num); |
| | | return mm; |
| | |
| | | } |
| | | |
| | | // APIs for VAD Infer |
| | | _FUNASRAPI FUNASR_RESULT FunVadWavFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback) |
| | | _FUNASRAPI FUNASR_RESULT FsmnVadWavFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback) |
| | | { |
| | | VadModel* vad_obj = (VadModel*)handle; |
| | | if (!vad_obj) |
| | |
| | | } |
| | | |
| | | // APIs for Offline-stream Infer |
| | | _FUNASRAPI FUNASR_RESULT FunOfflineStream(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback) |
| | | _FUNASRAPI FUNASR_RESULT FunOfflineRecogFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback) |
| | | { |
| | | OfflineStream* offline_stream = (OfflineStream*)handle; |
| | | if (!offline_stream) |
| | |
| | | return p_result; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunOfflineRecogPCMBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback) |
| | | { |
| | | OfflineStream* offline_stream = (OfflineStream*)handle; |
| | | if (!offline_stream) |
| | | return nullptr; |
| | | |
| | | Audio audio(1); |
| | | if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate)) |
| | | return nullptr; |
| | | if(offline_stream->UseVad()){ |
| | | audio.Split(offline_stream); |
| | | } |
| | | |
| | | float* buff; |
| | | int len; |
| | | int flag = 0; |
| | | FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; |
| | | p_result->snippet_time = audio.GetTimeLen(); |
| | | int n_step = 0; |
| | | int n_total = audio.GetQueueSize(); |
| | | while (audio.Fetch(buff, len, flag) > 0) { |
| | | string msg = (offline_stream->asr_handle)->Forward(buff, len, flag); |
| | | p_result->msg += msg; |
| | | n_step++; |
| | | if (fn_callback) |
| | | fn_callback(n_step, n_total); |
| | | } |
| | | if(offline_stream->UsePunc()){ |
| | | string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str()); |
| | | p_result->msg = punc_res; |
| | | } |
| | | |
| | | return p_result; |
| | | } |
| | | |
| | | _FUNASRAPI const int FunASRGetRetNumber(FUNASR_RESULT result) |
| | | { |
| | | if (!result) |
| | |
| | | return ((FUNASR_RECOG_RESULT*)result)->snippet_time; |
| | | } |
| | | |
| | | _FUNASRAPI const float FunVadGetRetSnippetTime(FUNASR_RESULT result) |
| | | _FUNASRAPI const float FsmnVadGetRetSnippetTime(FUNASR_RESULT result) |
| | | { |
| | | if (!result) |
| | | return 0.0f; |
| | |
| | | return p_result->msg.c_str(); |
| | | } |
| | | |
| | | _FUNASRAPI vector<std::vector<int>>* FunVadGetResult(FUNASR_RESULT result,int n_index) |
| | | _FUNASRAPI vector<std::vector<int>>* FsmnVadGetResult(FUNASR_RESULT result,int n_index) |
| | | { |
| | | FUNASR_VAD_RESULT * p_result = (FUNASR_VAD_RESULT*)result; |
| | | if(!p_result) |
| | |
| | | } |
| | | } |
| | | |
| | | _FUNASRAPI void FunVadFreeResult(FUNASR_RESULT result) |
| | | _FUNASRAPI void FsmnVadFreeResult(FUNASR_RESULT result) |
| | | { |
| | | FUNASR_VAD_RESULT * p_result = (FUNASR_VAD_RESULT*)result; |
| | | if (p_result) |
| | |
| | | delete recog_obj; |
| | | } |
| | | |
| | | _FUNASRAPI void FunVadUninit(FUNASR_HANDLE handle) |
| | | _FUNASRAPI void FsmnVadUninit(FUNASR_HANDLE handle) |
| | | { |
| | | VadModel* recog_obj = (VadModel*)handle; |
| | | |
| | |
| | | #include "resample.h" |
| | | #include "paraformer.h" |
| | | #include "offline-stream.h" |
| | | #include "libfunasrapi.h" |
| | | #include "funasrruntime.h" |
| | | |
| | | using namespace paraformer; |