From 6406616c2d3fd5eae0201cd4680258f7c4e937dd Mon Sep 17 00:00:00 2001
From: lyblsgo <lyblsgo@163.com>
Date: 星期一, 24 四月 2023 13:04:08 +0800
Subject: [PATCH] rename filenames
---
funasr/runtime/onnxruntime/src/libfunasrapi.cpp | 49 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/funasr/runtime/onnxruntime/src/libfunasrapi.cpp b/funasr/runtime/onnxruntime/src/libfunasrapi.cpp
index a4780b2..a12d15e 100644
--- a/funasr/runtime/onnxruntime/src/libfunasrapi.cpp
+++ b/funasr/runtime/onnxruntime/src/libfunasrapi.cpp
@@ -4,14 +4,14 @@
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* szModelDir, int nThreadNum, bool quantize, bool use_vad, bool use_punc)
{
- Model* mm = create_model(szModelDir, nThreadNum, quantize);
+ Model* mm = CreateModel(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)
+ _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)
@@ -21,7 +21,9 @@
Audio audio(1);
if (!audio.loadwav(szBuf, nLen, &sampling_rate))
return nullptr;
- //audio.split();
+ if(use_vad){
+ audio.split(pRecogObj);
+ }
float* buff;
int len;
@@ -31,18 +33,21 @@
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);
}
+ 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)
+ _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)
@@ -51,7 +56,9 @@
Audio audio(1);
if (!audio.loadpcmwav(szBuf, nLen, &sampling_rate))
return nullptr;
- //audio.split();
+ if(use_vad){
+ audio.split(pRecogObj);
+ }
float* buff;
int len;
@@ -61,18 +68,21 @@
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);
}
+ 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)
+ _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)
@@ -81,7 +91,9 @@
Audio audio(1);
if (!audio.loadpcmwav(szFileName, &sampling_rate))
return nullptr;
- //audio.split();
+ if(use_vad){
+ audio.split(pRecogObj);
+ }
float* buff;
int len;
@@ -91,18 +103,21 @@
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);
}
+ 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)
+ _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)
@@ -112,7 +127,9 @@
Audio audio(1);
if(!audio.loadwav(szWavfile, &sampling_rate))
return nullptr;
- //audio.split();
+ if(use_vad){
+ audio.split(pRecogObj);
+ }
float* buff;
int len;
@@ -128,6 +145,10 @@
if (fnCallback)
fnCallback(nStep, nTotal);
}
+ if(use_punc){
+ string punc_res = pRecogObj->AddPunc((pResult->msg).c_str());
+ pResult->msg = punc_res;
+ }
return pResult;
}
--
Gitblit v1.9.1