tester.cpp 1.57 KB
Newer Older
mayong's avatar
mayong committed
1

mayong's avatar
mayong committed
2
3
4
5
6
7
#ifndef _WIN32
#include <sys/time.h>
#else
#include <win_func.h>
#endif

mayong's avatar
mayong committed
8
9
10
#include "librapidasrapi.h"

#include <iostream>
mayong's avatar
mayong committed
11
12
13
14
15
16
17
18
19
20
21

using namespace std;

int main(int argc, char *argv[])
{

    if (argc < 2)
    {
        printf("Usage: %s /path/to/model_dir /path/to/wav/file", argv[0]);
        exit(-1);
    }
mayong's avatar
mayong committed
22
23
    struct timeval start, end;
    gettimeofday(&start, NULL);
Daniel's avatar
Daniel committed
24
    int nThreadNum = 4;
mayong's avatar
mayong committed
25
26
27
    RPASR_HANDLE AsrHanlde=RapidAsrInit(argv[1], nThreadNum);

    if (!AsrHanlde)
mayong's avatar
mayong committed
28
29
30
31
    {
        printf("Cannot load ASR Model from: %s, there must be files model.onnx and vocab.txt", argv[1]);
        exit(-1);
    }
mayong's avatar
mayong committed
32
    
mayong's avatar
mayong committed
33
 
mayong's avatar
mayong committed
34

mayong's avatar
mayong committed
35
36
37
38
39
40
41
42
43
    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);

    setbuf(stdout, NULL);
    cout << "Result: \"";
    gettimeofday(&start, NULL);

mayong's avatar
mayong committed
44
    RPASR_RESULT Result=RapidAsrRecogPCMFile(AsrHanlde, argv[2], RASR_NONE, NULL);
mayong's avatar
mayong committed
45
46
    gettimeofday(&end, NULL);

mayong's avatar
mayong committed
47
48
49
50
51
52
53
54
55
56
57
58
    if (Result)
    {
        string msg = RapidAsrGetResult(Result, 0);
        cout << msg << endl;
        cout << "\"." << endl;
        RapidAsrFreeResult(Result);
    }
    else
    {
        cout <<("no return data!");
    }
  
mayong's avatar
mayong committed
59
    seconds = (end.tv_sec - start.tv_sec);
mayong's avatar
mayong committed
60
    long taking_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
mayong's avatar
mayong committed
61
    printf("Model inference takes %lfs.\n", (double)micros / 1000000);
mayong's avatar
mayong committed
62

mayong's avatar
mayong committed
63
    printf("Model inference RTF: %04lf.\n", (double)taking_micros/micros );
mayong's avatar
mayong committed
64

mayong's avatar
mayong committed
65
    RapidAsrUninit(AsrHanlde);
mayong's avatar
mayong committed
66
67
68

    return 0;
}
mayong's avatar
mayong committed
69
70