Browse Source

Merge pull request #193 from RapidAI/main

Bugfix: correct RTF in tester
zhifu gao 3 years ago
parent
commit
646edfbd91

+ 1 - 0
funasr/runtime/onnxruntime/include/Audio.h

@@ -51,6 +51,7 @@ class Audio {
     int fetch(float *&dout, int &len, int &flag);
     int fetch(float *&dout, int &len, int &flag);
     void padding();
     void padding();
     void split();
     void split();
+    float get_time_len();
 
 
     int get_queue_size() { return (int)frame_queue.size(); }
     int get_queue_size() { return (int)frame_queue.size(); }
 };
 };

+ 1 - 0
funasr/runtime/onnxruntime/include/librapidasrapi.h

@@ -88,6 +88,7 @@ _RAPIDASRAPI void			RapidAsrFreeResult(RPASR_RESULT Result);
 
 
 _RAPIDASRAPI void			RapidAsrUninit(RPASR_HANDLE Handle);
 _RAPIDASRAPI void			RapidAsrUninit(RPASR_HANDLE Handle);
 
 
+_RAPIDASRAPI const float	RapidAsrGetRetSnippetTime(RPASR_RESULT Result);
 
 
 #ifdef __cplusplus 
 #ifdef __cplusplus 
 
 

+ 6 - 0
funasr/runtime/onnxruntime/src/Audio.cpp

@@ -116,6 +116,12 @@ void Audio::disp()
            speech_len);
            speech_len);
 }
 }
 
 
+float Audio::get_time_len()
+{
+    return (float)speech_len / 16000;
+       //speech_len);
+}
+
 bool Audio::loadwav(const char *filename)
 bool Audio::loadwav(const char *filename)
 {
 {
 
 

+ 1 - 1
funasr/runtime/onnxruntime/src/commonfunc.h

@@ -4,7 +4,7 @@
 typedef struct
 typedef struct
 {
 {
     std::string msg;
     std::string msg;
-
+    float  snippet_time;
 }RPASR_RECOG_RESULT;
 }RPASR_RECOG_RESULT;
 
 
 
 

+ 15 - 9
funasr/runtime/onnxruntime/src/librapidasrapi.cpp

@@ -1,9 +1,6 @@
 #include "precomp.h"
 #include "precomp.h"
 #ifdef __cplusplus 
 #ifdef __cplusplus 
 
 
-
-
-//  void __attribute__ ((visibility ("default"))) fun();
 extern "C" {
 extern "C" {
 #endif
 #endif
 
 
@@ -12,12 +9,6 @@ extern "C" {
 	_RAPIDASRAPI RPASR_HANDLE  RapidAsrInit(const char* szModelDir, int nThreadNum)
 	_RAPIDASRAPI RPASR_HANDLE  RapidAsrInit(const char* szModelDir, int nThreadNum)
 	{
 	{
 
 
-#ifdef NDEBUG
-		QMLIC_BOOL bMatched = QmLicCheckValid(QLFM_ASR);
-		if (!bMatched) {
-			return nullptr;
-		}
-#endif
 
 
 		Model* mm = create_model(szModelDir, nThreadNum); 
 		Model* mm = create_model(szModelDir, nThreadNum); 
 
 
@@ -42,6 +33,7 @@ extern "C" {
 		int len;
 		int len;
 		int flag=0;
 		int flag=0;
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
+		pResult->snippet_time = audio.get_time_len();
 		int nStep = 0;
 		int nStep = 0;
 		int nTotal = audio.get_queue_size();
 		int nTotal = audio.get_queue_size();
 		while (audio.fetch(buff, len, flag) > 0) {
 		while (audio.fetch(buff, len, flag) > 0) {
@@ -73,6 +65,7 @@ extern "C" {
 		int len;
 		int len;
 		int flag = 0;
 		int flag = 0;
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
+		pResult->snippet_time = audio.get_time_len();
 		int nStep = 0;
 		int nStep = 0;
 		int nTotal = audio.get_queue_size();
 		int nTotal = audio.get_queue_size();
 		while (audio.fetch(buff, len, flag) > 0) {
 		while (audio.fetch(buff, len, flag) > 0) {
@@ -105,6 +98,7 @@ extern "C" {
 		int len;
 		int len;
 		int flag = 0;
 		int flag = 0;
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
+		pResult->snippet_time = audio.get_time_len();
 		int nStep = 0;
 		int nStep = 0;
 		int nTotal = audio.get_queue_size();
 		int nTotal = audio.get_queue_size();
 		while (audio.fetch(buff, len, flag) > 0) {
 		while (audio.fetch(buff, len, flag) > 0) {
@@ -139,6 +133,7 @@ extern "C" {
 		int nStep = 0;
 		int nStep = 0;
 		int nTotal = audio.get_queue_size();
 		int nTotal = audio.get_queue_size();
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
 		RPASR_RECOG_RESULT* pResult = new RPASR_RECOG_RESULT;
+		pResult->snippet_time = audio.get_time_len();
 		while (audio.fetch(buff, len, flag) > 0) {
 		while (audio.fetch(buff, len, flag) > 0) {
 			pRecogObj->reset();
 			pRecogObj->reset();
 			string msg = pRecogObj->forward(buff, len, flag);
 			string msg = pRecogObj->forward(buff, len, flag);
@@ -162,6 +157,17 @@ extern "C" {
 		return 1;
 		return 1;
 		
 		
 	}
 	}
+
+
+	_RAPIDASRAPI const float RapidAsrGetRetSnippetTime(RPASR_RESULT Result)
+	{
+		if (!Result)
+			return 0.0f;
+
+		return ((RPASR_RECOG_RESULT*)Result)->snippet_time;
+
+	}
+
 	_RAPIDASRAPI const char* RapidAsrGetResult(RPASR_RESULT Result,int nIndex)
 	_RAPIDASRAPI const char* RapidAsrGetResult(RPASR_RESULT Result,int nIndex)
 	{
 	{
 		RPASR_RECOG_RESULT * pResult = (RPASR_RECOG_RESULT*)Result;
 		RPASR_RECOG_RESULT * pResult = (RPASR_RECOG_RESULT*)Result;

+ 12 - 7
funasr/runtime/onnxruntime/tester/tester.cpp

@@ -34,21 +34,24 @@ int main(int argc, char *argv[])
 
 
     gettimeofday(&end, NULL);
     gettimeofday(&end, NULL);
     long seconds = (end.tv_sec - start.tv_sec);
     long seconds = (end.tv_sec - start.tv_sec);
-    long micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
-    printf("Model initialization takes %lfs.\n", (double)micros / 1000000);
+    long modle_init_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
+    printf("Model initialization takes %lfs.\n", (double)modle_init_micros / 1000000);
+
+
 
 
-    setbuf(stdout, NULL);
-    cout << "Result: \"";
     gettimeofday(&start, NULL);
     gettimeofday(&start, NULL);
 
 
     RPASR_RESULT Result=RapidAsrRecogPCMFile(AsrHanlde, argv[2], RASR_NONE, NULL);
     RPASR_RESULT Result=RapidAsrRecogPCMFile(AsrHanlde, argv[2], RASR_NONE, NULL);
     gettimeofday(&end, NULL);
     gettimeofday(&end, NULL);
-
+    float snippet_time = 0.0f;
     if (Result)
     if (Result)
     {
     {
         string msg = RapidAsrGetResult(Result, 0);
         string msg = RapidAsrGetResult(Result, 0);
+        setbuf(stdout, NULL);
+        cout << "Result: \"";
         cout << msg << endl;
         cout << msg << endl;
         cout << "\"." << endl;
         cout << "\"." << endl;
+        snippet_time = RapidAsrGetRetSnippetTime(Result);
         RapidAsrFreeResult(Result);
         RapidAsrFreeResult(Result);
     }
     }
     else
     else
@@ -56,11 +59,13 @@ int main(int argc, char *argv[])
         cout <<("no return data!");
         cout <<("no return data!");
     }
     }
   
   
+    printf("Audio length %lfs.\n", (double)snippet_time);
+
     seconds = (end.tv_sec - start.tv_sec);
     seconds = (end.tv_sec - start.tv_sec);
     long taking_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
     long taking_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
-    printf("Model inference takes %lfs.\n", (double)micros / 1000000);
+    printf("Model inference takes %lfs.\n", (double)taking_micros / 1000000);
 
 
-    printf("Model inference RTF: %04lf.\n", (double)taking_micros/micros );
+    printf("Model inference RTF: %04lf.\n", (double)taking_micros/ (snippet_time*1000000));
 
 
     RapidAsrUninit(AsrHanlde);
     RapidAsrUninit(AsrHanlde);