| File was renamed from funasr/runtime/onnxruntime/tester/tester.cpp |
| | |
| | | #endif |
| | | |
| | | #include "libfunasrapi.h" |
| | | |
| | | #include <iostream> |
| | | #include <fstream> |
| | | #include <sstream> |
| | | using namespace std; |
| | | |
| | | int main(int argc, char *argv[]) |
| | | { |
| | | |
| | | if (argc < 4) |
| | | if (argc < 6) |
| | | { |
| | | printf("Usage: %s /path/to/model_dir /path/to/wav/file quantize(true or false) \n", argv[0]); |
| | | printf("Usage: %s /path/to/model_dir /path/to/wav/file quantize(true or false) use_vad(true or false) use_punc(true or false)\n", argv[0]); |
| | | exit(-1); |
| | | } |
| | | struct timeval start, end; |
| | | gettimeofday(&start, NULL); |
| | | int nThreadNum = 4; |
| | | int thread_num = 1; |
| | | // is quantize |
| | | bool quantize = false; |
| | | bool use_vad = false; |
| | | bool use_punc = false; |
| | | istringstream(argv[3]) >> boolalpha >> quantize; |
| | | FUNASR_HANDLE AsrHanlde=FunASRInit(argv[1], nThreadNum, quantize); |
| | | istringstream(argv[4]) >> boolalpha >> use_vad; |
| | | istringstream(argv[5]) >> boolalpha >> use_punc; |
| | | FUNASR_HANDLE asr_hanlde=FunASRInit(argv[1], thread_num, quantize, use_vad, use_punc); |
| | | |
| | | if (!AsrHanlde) |
| | | if (!asr_hanlde) |
| | | { |
| | | printf("Cannot load ASR Model from: %s, there must be files model.onnx and vocab.txt", argv[1]); |
| | | exit(-1); |
| | |
| | | printf("Model initialization takes %lfs.\n", (double)modle_init_micros / 1000000); |
| | | |
| | | gettimeofday(&start, NULL); |
| | | float snippet_time = 0.0f; |
| | | |
| | | FUNASR_RESULT Result=FunASRRecogFile(AsrHanlde, argv[2], RASR_NONE, NULL); |
| | | |
| | | FUNASR_RESULT result=FunASRRecogFile(asr_hanlde, argv[2], RASR_NONE, NULL, use_vad, use_punc); |
| | | gettimeofday(&end, NULL); |
| | | |
| | | if (Result) |
| | | |
| | | float snippet_time = 0.0f; |
| | | if (result) |
| | | { |
| | | string msg = FunASRGetResult(Result, 0); |
| | | string msg = FunASRGetResult(result, 0); |
| | | setbuf(stdout, NULL); |
| | | printf("Result: %s \n", msg.c_str()); |
| | | snippet_time = FunASRGetRetSnippetTime(Result); |
| | | FunASRFreeResult(Result); |
| | | snippet_time = FunASRGetRetSnippetTime(result); |
| | | FunASRFreeResult(result); |
| | | } |
| | | else |
| | | { |
| | | cout <<"no return data!"; |
| | | printf("no return data!\n"); |
| | | } |
| | | |
| | | printf("Audio length %lfs.\n", (double)snippet_time); |
| | |
| | | printf("Model inference takes %lfs.\n", (double)taking_micros / 1000000); |
| | | printf("Model inference RTF: %04lf.\n", (double)taking_micros/ (snippet_time*1000000)); |
| | | |
| | | FunASRUninit(AsrHanlde); |
| | | FunASRUninit(asr_hanlde); |
| | | |
| | | return 0; |
| | | } |