From 6427c834dfd97b1f05c6659cdc7ccf010bf82fe1 Mon Sep 17 00:00:00 2001
From: 嘉渊 <wangjiaming.wjm@alibaba-inc.com>
Date: 星期一, 24 四月 2023 19:50:07 +0800
Subject: [PATCH] update

---
 funasr/runtime/onnxruntime/tester/tester.cpp |  111 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 76 insertions(+), 35 deletions(-)

diff --git a/funasr/runtime/onnxruntime/tester/tester.cpp b/funasr/runtime/onnxruntime/tester/tester.cpp
index 7bfb4c0..35d534f 100644
--- a/funasr/runtime/onnxruntime/tester/tester.cpp
+++ b/funasr/runtime/onnxruntime/tester/tester.cpp
@@ -1,72 +1,113 @@
-#include <iostream>
+
 #ifndef _WIN32
 #include <sys/time.h>
 #else
 #include <win_func.h>
 #endif
 
-#include <Audio.h>
-#include <Model.h>
+#include "librapidasrapi.h"
 
+#include <iostream>
+#include <fstream>
+#include <sstream>
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 
-    if (argc < 2)
+    if (argc < 4)
     {
-        printf("Usage: %s /path/to/model_dir /path/to/wav/file", argv[0]);
+        printf("Usage: %s /path/to/model_dir /path/to/wav/file quantize(true or false) \n", argv[0]);
         exit(-1);
     }
     struct timeval start, end;
     gettimeofday(&start, NULL);
     int nThreadNum = 4;
-    Model* mm = create_model(argv[1], nThreadNum);
-    if (!mm)
+    // is quantize
+    bool quantize = false;
+    istringstream(argv[3]) >> boolalpha >> quantize;
+    RPASR_HANDLE AsrHanlde=RapidAsrInit(argv[1], nThreadNum, quantize);
+
+    if (!AsrHanlde)
     {
         printf("Cannot load ASR Model from: %s, there must be files model.onnx and vocab.txt", argv[1]);
         exit(-1);
     }
-    
-  
-    Audio audio(0);
-    if (!audio.loadwav(argv[2]))
-    {
-        printf("cannot load %s\n", argv[2]);
-        return -1;
-    }
-    audio.disp();
-  
 
     gettimeofday(&end, NULL);
     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);
-    audio.split();
+    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);
-    float *buff;
-    int len;
-    int flag;
-    while (audio.fetch(buff, len, flag) > 0) {
-        mm->reset();
-        string msg = mm->forward(buff, len, flag);
-        cout << msg;
-    }
+    float snippet_time = 0.0f;
+
+    RPASR_RESULT Result=RapidAsrRecogFile(AsrHanlde, argv[2], RASR_NONE, NULL);
 
     gettimeofday(&end, NULL);
+   
+    if (Result)
+    {
+        string msg = RapidAsrGetResult(Result, 0);
+        setbuf(stdout, NULL);
+        cout << "Result: \"";
+        cout << msg << "\"." << endl;
+        snippet_time = RapidAsrGetRetSnippetTime(Result);
+        RapidAsrFreeResult(Result);
+    }
+    else
+    {
+        cout <<"no return data!";
+    }
+ 
+    //char* buff = nullptr;
+    //int len = 0;
+    //ifstream ifs(argv[2], std::ios::binary | std::ios::in);
+    //if (ifs.is_open())
+    //{
+    //    ifs.seekg(0, std::ios::end);
+    //    len = ifs.tellg();
+    //    ifs.seekg(0, std::ios::beg);
 
-    cout << "\"." << endl;
+    //    buff = new char[len];
 
+    //    ifs.read(buff, len);
+
+
+    //    //RPASR_RESULT Result = RapidAsrRecogPCMFile(AsrHanlde, argv[2], RASR_NONE, NULL);
+
+    //    RPASR_RESULT Result=RapidAsrRecogPCMBuffer(AsrHanlde, buff,len, RASR_NONE, NULL);
+    //    //RPASR_RESULT Result = RapidAsrRecogPCMFile(AsrHanlde, argv[2], RASR_NONE, NULL);
+    //    gettimeofday(&end, NULL);
+    //   
+    //    if (Result)
+    //    {
+    //        string msg = RapidAsrGetResult(Result, 0);
+    //        setbuf(stdout, NULL);
+    //        cout << "Result: \"";
+    //        cout << msg << endl;
+    //        cout << "\"." << endl;
+    //        snippet_time = RapidAsrGetRetSnippetTime(Result);
+    //        RapidAsrFreeResult(Result);
+    //    }
+    //    else
+    //    {
+    //        cout <<"no return data!";
+    //    }
+  
+    //   
+    //delete[]buff;
+    //}
+ 
+    printf("Audio length %lfs.\n", (double)snippet_time);
     seconds = (end.tv_sec - start.tv_sec);
     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/ (snippet_time*1000000));
 
-    printf("Model inference RTF: %04lf.\n", (double)taking_micros/micros );
-
-    delete mm;
+    RapidAsrUninit(AsrHanlde);
 
     return 0;
 }
+
+    
\ No newline at end of file

--
Gitblit v1.9.1