| 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; |
| | | |