| | |
| | | extern "C" { |
| | | #endif |
| | | |
| | | // APIs for qmasr |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(const char* szModelDir, int nThreadNum, bool quantize) |
| | | // APIs for funasr |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(const char* sz_model_dir, int thread_num, bool quantize, bool use_vad, bool use_punc) |
| | | { |
| | | Model* mm = create_model(szModelDir, nThreadNum, quantize); |
| | | Model* mm = CreateModel(sz_model_dir, thread_num, 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) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, FUNASR_MODE mode, QM_CALLBACK fn_callback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | | Model* recog_obj = (Model*)handle; |
| | | if (!recog_obj) |
| | | return nullptr; |
| | | |
| | | int32_t sampling_rate = -1; |
| | | Audio audio(1); |
| | | if (!audio.loadwav(szBuf, nLen, &sampling_rate)) |
| | | if (!audio.LoadWav(sz_buf, n_len, &sampling_rate)) |
| | | return nullptr; |
| | | //audio.split(); |
| | | if(use_vad){ |
| | | audio.Split(recog_obj); |
| | | } |
| | | |
| | | float* buff; |
| | | int len; |
| | | int flag=0; |
| | | FUNASR_RECOG_RESULT* pResult = new FUNASR_RECOG_RESULT; |
| | | pResult->snippet_time = audio.get_time_len(); |
| | | int nStep = 0; |
| | | int nTotal = audio.get_queue_size(); |
| | | while (audio.fetch(buff, len, flag) > 0) { |
| | | //pRecogObj->reset(); |
| | | string msg = pRecogObj->forward(buff, len, flag); |
| | | pResult->msg += msg; |
| | | nStep++; |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | 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 = recog_obj->Forward(buff, len, flag); |
| | | p_result->msg += msg; |
| | | n_step++; |
| | | if (fn_callback) |
| | | fn_callback(n_step, n_total); |
| | | } |
| | | if(use_punc){ |
| | | string punc_res = recog_obj->AddPunc((p_result->msg).c_str()); |
| | | p_result->msg = punc_res; |
| | | } |
| | | |
| | | return pResult; |
| | | return p_result; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* szBuf, int nLen, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | | Model* recog_obj = (Model*)handle; |
| | | if (!recog_obj) |
| | | return nullptr; |
| | | |
| | | Audio audio(1); |
| | | if (!audio.loadpcmwav(szBuf, nLen, &sampling_rate)) |
| | | if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate)) |
| | | return nullptr; |
| | | //audio.split(); |
| | | if(use_vad){ |
| | | audio.Split(recog_obj); |
| | | } |
| | | |
| | | float* buff; |
| | | int len; |
| | | int flag = 0; |
| | | FUNASR_RECOG_RESULT* pResult = new FUNASR_RECOG_RESULT; |
| | | pResult->snippet_time = audio.get_time_len(); |
| | | int nStep = 0; |
| | | int nTotal = audio.get_queue_size(); |
| | | while (audio.fetch(buff, len, flag) > 0) { |
| | | //pRecogObj->reset(); |
| | | string msg = pRecogObj->forward(buff, len, flag); |
| | | pResult->msg += msg; |
| | | nStep++; |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | 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 = recog_obj->Forward(buff, len, flag); |
| | | p_result->msg += msg; |
| | | n_step++; |
| | | if (fn_callback) |
| | | fn_callback(n_step, n_total); |
| | | } |
| | | if(use_punc){ |
| | | string punc_res = recog_obj->AddPunc((p_result->msg).c_str()); |
| | | p_result->msg = punc_res; |
| | | } |
| | | |
| | | return pResult; |
| | | return p_result; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* szFileName, int sampling_rate, FUNASR_MODE Mode, QM_CALLBACK fnCallback) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* sz_filename, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | | Model* recog_obj = (Model*)handle; |
| | | if (!recog_obj) |
| | | return nullptr; |
| | | |
| | | Audio audio(1); |
| | | if (!audio.loadpcmwav(szFileName, &sampling_rate)) |
| | | if (!audio.LoadPcmwav(sz_filename, &sampling_rate)) |
| | | return nullptr; |
| | | //audio.split(); |
| | | if(use_vad){ |
| | | audio.Split(recog_obj); |
| | | } |
| | | |
| | | float* buff; |
| | | int len; |
| | | int flag = 0; |
| | | FUNASR_RECOG_RESULT* pResult = new FUNASR_RECOG_RESULT; |
| | | pResult->snippet_time = audio.get_time_len(); |
| | | int nStep = 0; |
| | | int nTotal = audio.get_queue_size(); |
| | | while (audio.fetch(buff, len, flag) > 0) { |
| | | //pRecogObj->reset(); |
| | | string msg = pRecogObj->forward(buff, len, flag); |
| | | pResult->msg += msg; |
| | | nStep++; |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | 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 = recog_obj->Forward(buff, len, flag); |
| | | p_result->msg += msg; |
| | | n_step++; |
| | | if (fn_callback) |
| | | fn_callback(n_step, n_total); |
| | | } |
| | | if(use_punc){ |
| | | string punc_res = recog_obj->AddPunc((p_result->msg).c_str()); |
| | | p_result->msg = punc_res; |
| | | } |
| | | |
| | | return pResult; |
| | | return p_result; |
| | | } |
| | | |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* szWavfile, FUNASR_MODE Mode, QM_CALLBACK fnCallback) |
| | | _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback, bool use_vad, bool use_punc) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | if (!pRecogObj) |
| | | Model* recog_obj = (Model*)handle; |
| | | if (!recog_obj) |
| | | return nullptr; |
| | | |
| | | int32_t sampling_rate = -1; |
| | | Audio audio(1); |
| | | if(!audio.loadwav(szWavfile, &sampling_rate)) |
| | | if(!audio.LoadWav(sz_wavfile, &sampling_rate)) |
| | | return nullptr; |
| | | //audio.split(); |
| | | if(use_vad){ |
| | | audio.Split(recog_obj); |
| | | } |
| | | |
| | | float* buff; |
| | | int len; |
| | | int flag = 0; |
| | | int nStep = 0; |
| | | int nTotal = audio.get_queue_size(); |
| | | FUNASR_RECOG_RESULT* pResult = new FUNASR_RECOG_RESULT; |
| | | pResult->snippet_time = audio.get_time_len(); |
| | | while (audio.fetch(buff, len, flag) > 0) { |
| | | //pRecogObj->reset(); |
| | | string msg = pRecogObj->forward(buff, len, flag); |
| | | pResult->msg+= msg; |
| | | nStep++; |
| | | if (fnCallback) |
| | | fnCallback(nStep, nTotal); |
| | | int n_step = 0; |
| | | int n_total = audio.GetQueueSize(); |
| | | FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; |
| | | p_result->snippet_time = audio.GetTimeLen(); |
| | | while (audio.Fetch(buff, len, flag) > 0) { |
| | | string msg = recog_obj->Forward(buff, len, flag); |
| | | p_result->msg+= msg; |
| | | n_step++; |
| | | if (fn_callback) |
| | | fn_callback(n_step, n_total); |
| | | } |
| | | if(use_punc){ |
| | | string punc_res = recog_obj->AddPunc((p_result->msg).c_str()); |
| | | p_result->msg = punc_res; |
| | | } |
| | | |
| | | return pResult; |
| | | return p_result; |
| | | } |
| | | |
| | | _FUNASRAPI const int FunASRGetRetNumber(FUNASR_RESULT Result) |
| | | _FUNASRAPI const int FunASRGetRetNumber(FUNASR_RESULT result) |
| | | { |
| | | if (!Result) |
| | | if (!result) |
| | | return 0; |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | _FUNASRAPI const float FunASRGetRetSnippetTime(FUNASR_RESULT Result) |
| | | _FUNASRAPI const float FunASRGetRetSnippetTime(FUNASR_RESULT result) |
| | | { |
| | | if (!Result) |
| | | if (!result) |
| | | return 0.0f; |
| | | |
| | | return ((FUNASR_RECOG_RESULT*)Result)->snippet_time; |
| | | return ((FUNASR_RECOG_RESULT*)result)->snippet_time; |
| | | } |
| | | |
| | | _FUNASRAPI const char* FunASRGetResult(FUNASR_RESULT Result,int nIndex) |
| | | _FUNASRAPI const char* FunASRGetResult(FUNASR_RESULT result,int n_index) |
| | | { |
| | | FUNASR_RECOG_RESULT * pResult = (FUNASR_RECOG_RESULT*)Result; |
| | | if(!pResult) |
| | | FUNASR_RECOG_RESULT * p_result = (FUNASR_RECOG_RESULT*)result; |
| | | if(!p_result) |
| | | return nullptr; |
| | | |
| | | return pResult->msg.c_str(); |
| | | return p_result->msg.c_str(); |
| | | } |
| | | |
| | | _FUNASRAPI void FunASRFreeResult(FUNASR_RESULT Result) |
| | | _FUNASRAPI void FunASRFreeResult(FUNASR_RESULT result) |
| | | { |
| | | if (Result) |
| | | if (result) |
| | | { |
| | | delete (FUNASR_RECOG_RESULT*)Result; |
| | | delete (FUNASR_RECOG_RESULT*)result; |
| | | } |
| | | } |
| | | |
| | | _FUNASRAPI void FunASRUninit(FUNASR_HANDLE handle) |
| | | { |
| | | Model* pRecogObj = (Model*)handle; |
| | | Model* recog_obj = (Model*)handle; |
| | | |
| | | if (!pRecogObj) |
| | | if (!recog_obj) |
| | | return; |
| | | |
| | | delete pRecogObj; |
| | | delete recog_obj; |
| | | } |
| | | |
| | | #ifdef __cplusplus |