| | |
| | | #include "precomp.h" |
| | | #include <vector> |
| | | #ifdef __cplusplus |
| | | |
| | | extern "C" { |
| | | #endif |
| | | |
| | | // APIs for Init |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(std::map<std::string, std::string>& model_path, int thread_num, ASR_TYPE type) |
| | |
| | | int n_total = audio.GetQueueSize(); |
| | | float start_time = 0.0; |
| | | std::string cur_stamp = "["; |
| | | std::string lang = (offline_stream->asr_handle)->GetLang(); |
| | | while (audio.Fetch(buff, len, flag, start_time) > 0) { |
| | | string msg = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb); |
| | | std::vector<std::string> msg_vec = funasr::split(msg, '|'); |
| | | if(msg_vec.size()==0){ |
| | | continue; |
| | | } |
| | | if(lang == "en-bpe" and p_result->msg != ""){ |
| | | p_result->msg += " "; |
| | | } |
| | | p_result->msg += msg_vec[0]; |
| | | //timestamp |
| | |
| | | p_result->stamp += cur_stamp + "]"; |
| | | } |
| | | if(offline_stream->UsePunc()){ |
| | | string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str()); |
| | | string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str(), lang); |
| | | p_result->msg = punc_res; |
| | | } |
| | | #if !defined(__APPLE__) |
| | | if(offline_stream->UseITN() && itn){ |
| | | string msg_itn = offline_stream->itn_handle->Normalize(p_result->msg); |
| | | p_result->msg = msg_itn; |
| | | } |
| | | #endif |
| | | |
| | | return p_result; |
| | | } |
| | |
| | | int n_total = audio.GetQueueSize(); |
| | | float start_time = 0.0; |
| | | std::string cur_stamp = "["; |
| | | std::string lang = (offline_stream->asr_handle)->GetLang(); |
| | | while (audio.Fetch(buff, len, flag, start_time) > 0) { |
| | | string msg = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb); |
| | | std::vector<std::string> msg_vec = funasr::split(msg, '|'); |
| | | if(msg_vec.size()==0){ |
| | | continue; |
| | | } |
| | | if(lang == "en-bpe" and p_result->msg != ""){ |
| | | p_result->msg += " "; |
| | | } |
| | | p_result->msg += msg_vec[0]; |
| | | //timestamp |
| | |
| | | p_result->stamp += cur_stamp + "]"; |
| | | } |
| | | if(offline_stream->UsePunc()){ |
| | | string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str()); |
| | | string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str(), lang); |
| | | p_result->msg = punc_res; |
| | | } |
| | | #if !defined(__APPLE__) |
| | | if(offline_stream->UseITN() && itn){ |
| | | string msg_itn = offline_stream->itn_handle->Normalize(p_result->msg); |
| | | p_result->msg = msg_itn; |
| | | } |
| | | #endif |
| | | return p_result; |
| | | } |
| | | |
| | | #if !defined(__APPLE__) |
| | | _FUNASRAPI const std::vector<std::vector<float>> CompileHotwordEmbedding(FUNASR_HANDLE handle, std::string &hotwords, ASR_TYPE mode) |
| | | { |
| | | if (mode == ASR_OFFLINE){ |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | #endif |
| | | |
| | | // APIs for 2pass-stream Infer |
| | | _FUNASRAPI FUNASR_RESULT FunTpassInferBuffer(FUNASR_HANDLE handle, FUNASR_HANDLE online_handle, const char* sz_buf, |
| | |
| | | string online_msg = ((funasr::ParaformerOnline*)asr_online_handle)->online_res; |
| | | string msg_punc = punc_online_handle->AddPunc(online_msg.c_str(), punc_cache[0]); |
| | | p_result->tpass_msg = msg_punc; |
| | | |
| | | #if !defined(__APPLE__) |
| | | // ITN |
| | | if(tpass_stream->UseITN() && itn){ |
| | | string msg_itn = tpass_stream->itn_handle->Normalize(msg_punc); |
| | | p_result->tpass_msg = msg_itn; |
| | | } |
| | | |
| | | #endif |
| | | ((funasr::ParaformerOnline*)asr_online_handle)->online_res = ""; |
| | | p_result->msg += msg; |
| | | }else{ |
| | |
| | | msg_punc += "。"; |
| | | } |
| | | p_result->tpass_msg = msg_punc; |
| | | #if !defined(__APPLE__) |
| | | if(tpass_stream->UseITN() && itn){ |
| | | string msg_itn = tpass_stream->itn_handle->Normalize(msg_punc); |
| | | p_result->tpass_msg = msg_itn; |
| | | } |
| | | #endif |
| | | |
| | | if(frame != NULL){ |
| | | delete frame; |
| | |
| | | delete tpass_online_stream; |
| | | } |
| | | |
| | | #ifdef __cplusplus |
| | | |
| | | } |
| | | #endif |
| | | |