|
|
@@ -11,9 +11,9 @@ extern "C" {
|
|
|
return mm;
|
|
|
}
|
|
|
|
|
|
- _FUNASRAPI FUNASR_HANDLE FsmnVadInit(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, FSMN_VAD_MODE mode)
|
|
|
{
|
|
|
- funasr::VadModel* mm = funasr::CreateVadModel(model_path, thread_num);
|
|
|
+ funasr::VadModel* mm = funasr::CreateVadModel(model_path, thread_num, mode);
|
|
|
return mm;
|
|
|
}
|
|
|
|
|
|
@@ -30,20 +30,19 @@ extern "C" {
|
|
|
}
|
|
|
|
|
|
// APIs for ASR Infer
|
|
|
- _FUNASRAPI FUNASR_RESULT FunASRRecogBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, FUNASR_MODE mode, QM_CALLBACK fn_callback)
|
|
|
+ _FUNASRAPI FUNASR_RESULT FunASRInferBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, FUNASR_MODE mode, QM_CALLBACK fn_callback, int sampling_rate)
|
|
|
{
|
|
|
funasr::Model* recog_obj = (funasr::Model*)handle;
|
|
|
if (!recog_obj)
|
|
|
return nullptr;
|
|
|
|
|
|
- int32_t sampling_rate = -1;
|
|
|
funasr::Audio audio(1);
|
|
|
- if (!audio.LoadWav(sz_buf, n_len, &sampling_rate))
|
|
|
+ if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate))
|
|
|
return nullptr;
|
|
|
|
|
|
float* buff;
|
|
|
int len;
|
|
|
- int flag=0;
|
|
|
+ int flag = 0;
|
|
|
funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT;
|
|
|
p_result->snippet_time = audio.GetTimeLen();
|
|
|
int n_step = 0;
|
|
|
@@ -59,23 +58,32 @@ extern "C" {
|
|
|
return p_result;
|
|
|
}
|
|
|
|
|
|
- _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback)
|
|
|
+ _FUNASRAPI FUNASR_RESULT FunASRInfer(FUNASR_HANDLE handle, const char* sz_filename, FUNASR_MODE mode, QM_CALLBACK fn_callback, int sampling_rate)
|
|
|
{
|
|
|
funasr::Model* recog_obj = (funasr::Model*)handle;
|
|
|
if (!recog_obj)
|
|
|
return nullptr;
|
|
|
|
|
|
funasr::Audio audio(1);
|
|
|
- if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate))
|
|
|
- return nullptr;
|
|
|
+ if(funasr::is_target_file(sz_filename, "wav")){
|
|
|
+ int32_t sampling_rate_ = -1;
|
|
|
+ if(!audio.LoadWav(sz_filename, &sampling_rate_))
|
|
|
+ return nullptr;
|
|
|
+ }else if(funasr::is_target_file(sz_filename, "pcm")){
|
|
|
+ if (!audio.LoadPcmwav(sz_filename, &sampling_rate))
|
|
|
+ return nullptr;
|
|
|
+ }else{
|
|
|
+ LOG(ERROR)<<"Wrong wav extension";
|
|
|
+ exit(-1);
|
|
|
+ }
|
|
|
|
|
|
float* buff;
|
|
|
int len;
|
|
|
int flag = 0;
|
|
|
- funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT;
|
|
|
- p_result->snippet_time = audio.GetTimeLen();
|
|
|
int n_step = 0;
|
|
|
int n_total = audio.GetQueueSize();
|
|
|
+ funasr::FUNASR_RECOG_RESULT* p_result = new funasr::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;
|
|
|
@@ -87,74 +95,45 @@ extern "C" {
|
|
|
return p_result;
|
|
|
}
|
|
|
|
|
|
- _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* sz_filename, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback)
|
|
|
+ // APIs for VAD Infer
|
|
|
+ _FUNASRAPI FUNASR_RESULT FsmnVadInferBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, FSMN_VAD_MODE mode, QM_CALLBACK fn_callback, int sampling_rate)
|
|
|
{
|
|
|
- funasr::Model* recog_obj = (funasr::Model*)handle;
|
|
|
- if (!recog_obj)
|
|
|
+ funasr::VadModel* vad_obj = (funasr::VadModel*)handle;
|
|
|
+ if (!vad_obj)
|
|
|
return nullptr;
|
|
|
|
|
|
funasr::Audio audio(1);
|
|
|
- if (!audio.LoadPcmwav(sz_filename, &sampling_rate))
|
|
|
+ if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate))
|
|
|
return nullptr;
|
|
|
|
|
|
- float* buff;
|
|
|
- int len;
|
|
|
- int flag = 0;
|
|
|
- funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT;
|
|
|
+ funasr::FUNASR_VAD_RESULT* p_result = new funasr::FUNASR_VAD_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);
|
|
|
- }
|
|
|
-
|
|
|
- return p_result;
|
|
|
- }
|
|
|
-
|
|
|
- _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback)
|
|
|
- {
|
|
|
- funasr::Model* recog_obj = (funasr::Model*)handle;
|
|
|
- if (!recog_obj)
|
|
|
- return nullptr;
|
|
|
|
|
|
- int32_t sampling_rate = -1;
|
|
|
- funasr::Audio audio(1);
|
|
|
- if(!audio.LoadWav(sz_wavfile, &sampling_rate))
|
|
|
- return nullptr;
|
|
|
+ vector<std::vector<int>> vad_segments;
|
|
|
+ audio.Split(vad_obj, vad_segments);
|
|
|
+ p_result->segments = new vector<std::vector<int>>(vad_segments);
|
|
|
|
|
|
- float* buff;
|
|
|
- int len;
|
|
|
- int flag = 0;
|
|
|
- int n_step = 0;
|
|
|
- int n_total = audio.GetQueueSize();
|
|
|
- funasr::FUNASR_RECOG_RESULT* p_result = new funasr::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);
|
|
|
- }
|
|
|
-
|
|
|
return p_result;
|
|
|
}
|
|
|
|
|
|
- // APIs for VAD Infer
|
|
|
- _FUNASRAPI FUNASR_RESULT FsmnVadWavFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback)
|
|
|
+ _FUNASRAPI FUNASR_RESULT FsmnVadInfer(FUNASR_HANDLE handle, const char* sz_filename, FSMN_VAD_MODE mode, QM_CALLBACK fn_callback, int sampling_rate)
|
|
|
{
|
|
|
funasr::VadModel* vad_obj = (funasr::VadModel*)handle;
|
|
|
if (!vad_obj)
|
|
|
return nullptr;
|
|
|
-
|
|
|
- int32_t sampling_rate = -1;
|
|
|
+
|
|
|
funasr::Audio audio(1);
|
|
|
- if(!audio.LoadWav(sz_wavfile, &sampling_rate))
|
|
|
- return nullptr;
|
|
|
+ if(funasr::is_target_file(sz_filename, "wav")){
|
|
|
+ int32_t sampling_rate_ = -1;
|
|
|
+ if(!audio.LoadWav(sz_filename, &sampling_rate_))
|
|
|
+ return nullptr;
|
|
|
+ }else if(funasr::is_target_file(sz_filename, "pcm")){
|
|
|
+ if (!audio.LoadPcmwav(sz_filename, &sampling_rate))
|
|
|
+ return nullptr;
|
|
|
+ }else{
|
|
|
+ LOG(ERROR)<<"Wrong wav extension";
|
|
|
+ exit(-1);
|
|
|
+ }
|
|
|
|
|
|
funasr::FUNASR_VAD_RESULT* p_result = new funasr::FUNASR_VAD_RESULT;
|
|
|
p_result->snippet_time = audio.GetTimeLen();
|
|
|
@@ -178,15 +157,14 @@ extern "C" {
|
|
|
}
|
|
|
|
|
|
// APIs for Offline-stream Infer
|
|
|
- _FUNASRAPI FUNASR_RESULT FunOfflineRecogFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback)
|
|
|
+ _FUNASRAPI FUNASR_RESULT FunOfflineInferBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, FUNASR_MODE mode, QM_CALLBACK fn_callback, int sampling_rate)
|
|
|
{
|
|
|
funasr::OfflineStream* offline_stream = (funasr::OfflineStream*)handle;
|
|
|
if (!offline_stream)
|
|
|
return nullptr;
|
|
|
-
|
|
|
- int32_t sampling_rate = -1;
|
|
|
+
|
|
|
funasr::Audio audio(1);
|
|
|
- if(!audio.LoadWav(sz_wavfile, &sampling_rate))
|
|
|
+ if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate))
|
|
|
return nullptr;
|
|
|
if(offline_stream->UseVad()){
|
|
|
audio.Split(offline_stream);
|
|
|
@@ -195,13 +173,13 @@ extern "C" {
|
|
|
float* buff;
|
|
|
int len;
|
|
|
int flag = 0;
|
|
|
- int n_step = 0;
|
|
|
- int n_total = audio.GetQueueSize();
|
|
|
funasr::FUNASR_RECOG_RESULT* p_result = new funasr::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;
|
|
|
+ p_result->msg += msg;
|
|
|
n_step++;
|
|
|
if (fn_callback)
|
|
|
fn_callback(n_step, n_total);
|
|
|
@@ -210,19 +188,28 @@ extern "C" {
|
|
|
string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str());
|
|
|
p_result->msg = punc_res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
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)
|
|
|
+ _FUNASRAPI FUNASR_RESULT FunOfflineInfer(FUNASR_HANDLE handle, const char* sz_filename, FUNASR_MODE mode, QM_CALLBACK fn_callback, int sampling_rate)
|
|
|
{
|
|
|
funasr::OfflineStream* offline_stream = (funasr::OfflineStream*)handle;
|
|
|
if (!offline_stream)
|
|
|
return nullptr;
|
|
|
-
|
|
|
+
|
|
|
funasr::Audio audio(1);
|
|
|
- if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate))
|
|
|
- return nullptr;
|
|
|
+ if(funasr::is_target_file(sz_filename, "wav")){
|
|
|
+ int32_t sampling_rate_ = -1;
|
|
|
+ if(!audio.LoadWav(sz_filename, &sampling_rate_))
|
|
|
+ return nullptr;
|
|
|
+ }else if(funasr::is_target_file(sz_filename, "pcm")){
|
|
|
+ if (!audio.LoadPcmwav(sz_filename, &sampling_rate))
|
|
|
+ return nullptr;
|
|
|
+ }else{
|
|
|
+ LOG(ERROR)<<"Wrong wav extension";
|
|
|
+ exit(-1);
|
|
|
+ }
|
|
|
if(offline_stream->UseVad()){
|
|
|
audio.Split(offline_stream);
|
|
|
}
|
|
|
@@ -230,13 +217,13 @@ extern "C" {
|
|
|
float* buff;
|
|
|
int len;
|
|
|
int flag = 0;
|
|
|
- funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT;
|
|
|
- p_result->snippet_time = audio.GetTimeLen();
|
|
|
int n_step = 0;
|
|
|
int n_total = audio.GetQueueSize();
|
|
|
+ funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT;
|
|
|
+ p_result->snippet_time = audio.GetTimeLen();
|
|
|
while (audio.Fetch(buff, len, flag) > 0) {
|
|
|
string msg = (offline_stream->asr_handle)->Forward(buff, len, flag);
|
|
|
- p_result->msg += msg;
|
|
|
+ p_result->msg+= msg;
|
|
|
n_step++;
|
|
|
if (fn_callback)
|
|
|
fn_callback(n_step, n_total);
|
|
|
@@ -245,7 +232,7 @@ extern "C" {
|
|
|
string punc_res = (offline_stream->punc_handle)->AddPunc((p_result->msg).c_str());
|
|
|
p_result->msg = punc_res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return p_result;
|
|
|
}
|
|
|
|