| | |
| | | virtual std::string AddPunc(const char* szInput)=0; |
| | | }; |
| | | |
| | | Model *create_model(const char *path,int nThread=0,bool quantize=false, bool use_vad=false); |
| | | Model *create_model(const char *path,int nThread=0,bool quantize=false, bool use_vad=false, bool use_punc=false); |
| | | #endif |
| | |
| | | typedef void (* QM_CALLBACK)(int nCurStep, int nTotal); // nTotal: total steps; nCurStep: Current Step. |
| | | |
| | | // APIs for funasr |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(const char* szModelDir, int nThread, bool quantize=false, bool use_vad=false); |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(const char* szModelDir, int nThread, bool quantize=false, bool use_vad=false, bool use_punc=false); |
| | | |
| | | |
| | | // if not give a fnCallback ,it should be NULL |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false); |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false, bool use_punc=false); |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false); |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false, bool use_punc=false); |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* szFileName, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false); |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* szFileName, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false, bool use_punc=false); |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* szWavfile, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false); |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* szWavfile, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad=false, bool use_punc=false); |
| | | |
| | | _FUNASRAPI const char* FunASRGetResult(FUNASR_RESULT Result,int nIndex); |
| | | |
| | |
| | | ## Run the demo |
| | | |
| | | ```shell |
| | | funasr-onnx-offline /path/models_dir /path/wave_file quantize(true or false) use_vad(true or false) |
| | | funasr-onnx-offline /path/models_dir /path/wave_file quantize(true or false) use_vad(true or false) use_punc(true or false) |
| | | ``` |
| | | |
| | | The structure of /path/models_dir |
| | | ``` |
| | | config.yaml, am.mvn, model.onnx(or model_quant.onnx), (vad_model.onnx, vad.mvn if you use vad) |
| | | config.yaml, am.mvn, model.onnx(or model_quant.onnx), (vad_model.onnx, vad.mvn if you use vad), (punc_model.onnx, punc.yaml if you use vad) |
| | | ``` |
| | | |
| | | |
| File was renamed from funasr/runtime/onnxruntime/src/punc_infer.cpp |
| | |
| | | string strModelPath = pathAppend(sz_model_dir, PUNC_MODEL_FILE); |
| | | string strYamlPath = pathAppend(sz_model_dir, PUNC_YAML_FILE); |
| | | |
| | | try{ |
| | | #ifdef _WIN32 |
| | | std::wstring detPath = strToWstr(strModelPath); |
| | | m_session = std::make_unique<Ort::Session>(env_, detPath.c_str(), session_options); |
| | | #else |
| | | m_session = std::make_unique<Ort::Session>(env_, strModelPath.c_str(), session_options); |
| | | #endif |
| | | // read inputnames outputnames |
| | | vector<string> m_strInputNames, m_strOutputNames; |
| | | } |
| | | catch(exception e) |
| | | { |
| | | printf(e.what()); |
| | | } |
| | | // read inputnames outputnamess |
| | | string strName; |
| | | getInputName(m_session.get(), strName); |
| | | m_strInputNames.push_back(strName.c_str()); |
| File was renamed from funasr/runtime/onnxruntime/src/punc_infer.h |
| | |
| | | private: |
| | | |
| | | CTokenizer m_tokenizer; |
| | | vector<string> m_strInputNames, m_strOutputNames; |
| | | vector<const char*> m_szInputNames; |
| | | vector<const char*> m_szOutputNames; |
| | | |
| | |
| | | #include "precomp.h" |
| | | |
| | | Model *create_model(const char *path, int nThread, bool quantize, bool use_vad) |
| | | Model *create_model(const char *path, int nThread, bool quantize, bool use_vad, bool use_punc) |
| | | { |
| | | Model *mm; |
| | | |
| | | mm = new paraformer::ModelImp(path, nThread, quantize, use_vad); |
| | | mm = new paraformer::ModelImp(path, nThread, quantize, use_vad, use_punc); |
| | | |
| | | return mm; |
| | | } |
| | |
| | | |
| | | int main(int argc, char *argv[]) |
| | | { |
| | | if (argc < 5) |
| | | if (argc < 6) |
| | | { |
| | | printf("Usage: %s /path/to/model_dir /path/to/wav/file quantize(true or false) use_vad(true or false) \n", argv[0]); |
| | | printf("Usage: %s /path/to/model_dir /path/to/wav/file quantize(true or false) use_vad(true or false) use_punc(true or false)\n", argv[0]); |
| | | exit(-1); |
| | | } |
| | | struct timeval start, end; |
| | |
| | | // is quantize |
| | | bool quantize = false; |
| | | bool use_vad = false; |
| | | bool use_punc = false; |
| | | istringstream(argv[3]) >> boolalpha >> quantize; |
| | | istringstream(argv[4]) >> boolalpha >> use_vad; |
| | | FUNASR_HANDLE AsrHanlde=FunASRInit(argv[1], nThreadNum, quantize, use_vad); |
| | | istringstream(argv[5]) >> boolalpha >> use_punc; |
| | | FUNASR_HANDLE AsrHanlde=FunASRInit(argv[1], nThreadNum, quantize, use_vad, use_punc); |
| | | |
| | | if (!AsrHanlde) |
| | | { |
| | |
| | | printf("Model initialization takes %lfs.\n", (double)modle_init_micros / 1000000); |
| | | |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT Result=FunASRRecogFile(AsrHanlde, argv[2], RASR_NONE, NULL, use_vad); |
| | | FUNASR_RESULT Result=FunASRRecogFile(AsrHanlde, argv[2], RASR_NONE, NULL, use_vad, use_punc); |
| | | gettimeofday(&end, NULL); |
| | | |
| | | float snippet_time = 0.0f; |
| | |
| | | #endif |
| | | |
| | | // APIs for funasr |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(const char* szModelDir, int nThreadNum, bool quantize, bool use_vad) |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(const char* szModelDir, int nThreadNum, bool quantize, bool use_vad, bool use_punc) |
| | | { |
| | | Model* mm = create_model(szModelDir, nThreadNum, quantize, use_vad); |
| | | Model* mm = create_model(szModelDir, nThreadNum, quantize, use_vad, use_punc); |
| | | return mm; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | } |
| | | if(use_punc){ |
| | | string punc_res = pRecogObj->AddPunc((pResult->msg).c_str()); |
| | | pResult->msg = punc_res; |
| | | } |
| | | |
| | | return pResult; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | } |
| | | if(use_punc){ |
| | | string punc_res = pRecogObj->AddPunc((pResult->msg).c_str()); |
| | | pResult->msg = punc_res; |
| | | } |
| | | |
| | | return pResult; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* szFileName, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* szFileName, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | } |
| | | if(use_punc){ |
| | | string punc_res = pRecogObj->AddPunc((pResult->msg).c_str()); |
| | | pResult->msg = punc_res; |
| | | } |
| | | |
| | | return pResult; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* szWavfile, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* szWavfile, FUNASR_MODE Mode, QM_CALLBACK fnCallback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | } |
| | | if(true){ |
| | | if(use_punc){ |
| | | string punc_res = pRecogObj->AddPunc((pResult->msg).c_str()); |
| | | pResult->msg = punc_res; |
| | | } |
| | |
| | | using namespace std; |
| | | using namespace paraformer; |
| | | |
| | | ModelImp::ModelImp(const char* path,int nNumThread, bool quantize, bool use_vad) |
| | | ModelImp::ModelImp(const char* path,int nNumThread, bool quantize, bool use_vad, bool use_punc) |
| | | :env_(ORT_LOGGING_LEVEL_ERROR, "paraformer"),sessionOptions{}{ |
| | | string model_path; |
| | | string cmvn_path; |
| | |
| | | } |
| | | |
| | | // PUNC model |
| | | if(true){ |
| | | if(use_punc){ |
| | | puncHandle = make_unique<CTTransformer>(path, nNumThread); |
| | | } |
| | | |
| | |
| | | m_session = std::make_unique<Ort::Session>(env_, model_path.c_str(), sessionOptions); |
| | | #endif |
| | | |
| | | vector<string> m_strInputNames, m_strOutputNames; |
| | | string strName; |
| | | getInputName(m_session.get(), strName); |
| | | m_strInputNames.push_back(strName.c_str()); |
| | |
| | | Ort::Env env_; |
| | | Ort::SessionOptions sessionOptions; |
| | | |
| | | vector<string> m_strInputNames, m_strOutputNames; |
| | | vector<const char*> m_szInputNames; |
| | | vector<const char*> m_szOutputNames; |
| | | |
| | | public: |
| | | ModelImp(const char* path, int nNumThread=0, bool quantize=false, bool use_vad=false); |
| | | ModelImp(const char* path, int nNumThread=0, bool quantize=false, bool use_vad=false, bool use_punc=false); |
| | | ~ModelImp(); |
| | | void reset(); |
| | | vector<float> FbankKaldi(float sample_rate, const float* waves, int len); |
| | |
| | | #include "commonfunc.h" |
| | | #include "predefine_coe.h" |
| | | #include "tokenizer.h" |
| | | #include "punc_infer.h" |
| | | #include "CT-transformer.h" |
| | | #include "FsmnVad.h" |
| | | #include "e2e_vad.h" |
| | | #include "Vocab.h" |