tester.cpp 1.6 KB
Newer Older
mayong's avatar
mayong committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#ifndef _WIN32
#include <sys/time.h>
#else
#include <win_func.h>
#endif

#include <Audio.h>
#include <Model.h>

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
21
22
    struct timeval start, end;
    gettimeofday(&start, NULL);
Daniel's avatar
Daniel committed
23
    int nThreadNum = 4;
mayong's avatar
mayong committed
24
    Model* mm = create_model(argv[1], nThreadNum);
mayong's avatar
mayong committed
25
26
27
28
29
    if (!mm)
    {
        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
30
31
    
  
mayong's avatar
mayong committed
32
    Audio audio(0);
mayong's avatar
mayong committed
33
34
35
36
37
    if (!audio.loadwav(argv[2]))
    {
        printf("cannot load %s\n", argv[2]);
        return -1;
    }
mayong's avatar
mayong committed
38
    audio.disp();
mayong's avatar
mayong committed
39
  
mayong's avatar
mayong committed
40

mayong's avatar
mayong committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    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();

    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;
    }

    gettimeofday(&end, NULL);

    cout << "\"." << endl;

    seconds = (end.tv_sec - start.tv_sec);
mayong's avatar
mayong committed
64
    long taking_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec);
mayong's avatar
mayong committed
65
    printf("Model inference takes %lfs.\n", (double)micros / 1000000);
mayong's avatar
mayong committed
66

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

mayong's avatar
mayong committed
69
70
71
72
    delete mm;

    return 0;
}