| | |
| | | TCLAP::ValueArg<std::string> vad_quant("", VAD_QUANT, "true (Default), load the model of model.onnx in vad_dir. If set true, load the model of model_quant.onnx in vad_dir", false, "true", "string"); |
| | | TCLAP::ValueArg<std::string> punc_dir("", PUNC_DIR, "the punc online model path, which contains model.onnx, punc.yaml", false, "", "string"); |
| | | TCLAP::ValueArg<std::string> punc_quant("", PUNC_QUANT, "true (Default), load the model of model.onnx in punc_dir. If set true, load the model of model_quant.onnx in punc_dir", false, "true", "string"); |
| | | TCLAP::ValueArg<std::string> itn_dir("", ITN_DIR, "the itn model(fst) path, which contains zh_itn_tagger.fst and zh_itn_verbalizer.fst", false, "", "string"); |
| | | TCLAP::ValueArg<std::string> asr_mode("", ASR_MODE, "offline, online, 2pass", false, "2pass", "string"); |
| | | TCLAP::ValueArg<std::int32_t> onnx_thread("", "onnx-inter-thread", "onnxruntime SetIntraOpNumThreads", false, 1, "int32_t"); |
| | | TCLAP::ValueArg<std::int32_t> onnx_thread("", "model-thread-num", "onnxruntime SetIntraOpNumThreads", false, 1, "int32_t"); |
| | | |
| | | TCLAP::ValueArg<std::string> wav_path("", WAV_PATH, "the input could be: wav_path, e.g.: asr_example.wav; pcm_path, e.g.: asr_example.pcm; wav.scp, kaldi style wav list (wav_id \t wav_path)", true, "", "string"); |
| | | TCLAP::ValueArg<std::string> hotword("", HOTWORD, "*.txt(one hotword perline) or hotwords seperate by | (could be: 阿里巴巴 达摩院)", false, "", "string"); |
| | | |
| | | cmd.add(offline_model_dir); |
| | | cmd.add(online_model_dir); |
| | |
| | | cmd.add(vad_quant); |
| | | cmd.add(punc_dir); |
| | | cmd.add(punc_quant); |
| | | cmd.add(itn_dir); |
| | | cmd.add(wav_path); |
| | | cmd.add(asr_mode); |
| | | cmd.add(onnx_thread); |
| | | cmd.add(hotword); |
| | | cmd.parse(argc, argv); |
| | | |
| | | std::map<std::string, std::string> model_path; |
| | |
| | | GetValue(vad_quant, VAD_QUANT, model_path); |
| | | GetValue(punc_dir, PUNC_DIR, model_path); |
| | | GetValue(punc_quant, PUNC_QUANT, model_path); |
| | | GetValue(itn_dir, ITN_DIR, model_path); |
| | | GetValue(wav_path, WAV_PATH, model_path); |
| | | GetValue(asr_mode, ASR_MODE, model_path); |
| | | |
| | |
| | | long modle_init_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | | LOG(INFO) << "Model initialization takes " << (double)modle_init_micros / 1000000 << " s"; |
| | | |
| | | // read hotwords |
| | | std::string hotword_ = hotword.getValue(); |
| | | std::string hotwords_=""; |
| | | |
| | | if(is_target_file(hotword_, "txt")){ |
| | | ifstream in(hotword_); |
| | | if (!in.is_open()) { |
| | | LOG(ERROR) << "Failed to open file: " << model_path.at(HOTWORD) ; |
| | | return 0; |
| | | } |
| | | string line; |
| | | while(getline(in, line)) |
| | | { |
| | | hotwords_ +=line+HOTWORD_SEP; |
| | | } |
| | | in.close(); |
| | | }else{ |
| | | hotwords_ = hotword_; |
| | | } |
| | | |
| | | // read wav_path |
| | | vector<string> wav_list; |
| | | vector<string> wav_ids; |
| | |
| | | wav_ids.emplace_back(default_id); |
| | | } |
| | | |
| | | std::vector<std::vector<float>> hotwords_embedding = CompileHotwordEmbedding(tpass_handle, hotwords_, ASR_TWO_PASS); |
| | | // init online features |
| | | std::vector<int> chunk_size = {5,10,5}; |
| | | FUNASR_HANDLE tpass_online_handle=FunTpassOnlineInit(tpass_handle, chunk_size); |
| | |
| | | |
| | | int step = 800*2; |
| | | bool is_final = false; |
| | | |
| | | string online_res=""; |
| | | string tpass_res=""; |
| | | string time_stamp_res=""; |
| | | std::vector<std::vector<string>> punc_cache(2); |
| | | for (int sample_offset = 0; sample_offset < buff_len; sample_offset += std::min(step, buff_len - sample_offset)) { |
| | | if (sample_offset + step >= buff_len - 1) { |
| | |
| | | is_final = false; |
| | | } |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result = FunTpassInferBuffer(tpass_handle, tpass_online_handle, speech_buff+sample_offset, step, punc_cache, is_final, sampling_rate_, "pcm", (ASR_TYPE)asr_mode_); |
| | | FUNASR_RESULT result = FunTpassInferBuffer(tpass_handle, tpass_online_handle, speech_buff+sample_offset, step, punc_cache, is_final, sampling_rate_, "pcm", (ASR_TYPE)asr_mode_, hotwords_embedding); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | taking_micros += ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | |
| | | if(tpass_msg != ""){ |
| | | LOG(INFO)<< wav_id <<" offline results : "<<tpass_msg; |
| | | } |
| | | string stamp = FunASRGetStamp(result); |
| | | if(stamp !=""){ |
| | | LOG(INFO) << wav_ids[i] << " time stamp : " << stamp; |
| | | if(time_stamp_res == ""){ |
| | | time_stamp_res += stamp; |
| | | }else{ |
| | | time_stamp_res = time_stamp_res.erase(time_stamp_res.length()-1) |
| | | + "," + stamp.substr(1); |
| | | } |
| | | } |
| | | snippet_time += FunASRGetRetSnippetTime(result); |
| | | FunASRFreeResult(result); |
| | | } |
| | |
| | | } |
| | | if(asr_mode_==0 || asr_mode_==2){ |
| | | LOG(INFO) << wav_id << " Final offline results " <<" : "<<tpass_res; |
| | | if(time_stamp_res!=""){ |
| | | LOG(INFO) << wav_id << " Final timestamp results " <<" : "<<time_stamp_res; |
| | | } |
| | | } |
| | | } |
| | | |