| | |
| | | LOG(INFO)<< key << " : " << value_arg.getValue(); |
| | | } |
| | | |
| | | void runReg(FUNASR_HANDLE tpass_handle, std::vector<int> chunk_size, vector<string> wav_list, vector<string> wav_ids, |
| | | void runReg(FUNASR_HANDLE tpass_handle, std::vector<int> chunk_size, vector<string> wav_list, vector<string> wav_ids, int audio_fs, |
| | | float* total_length, long* total_time, int core_id, ASR_TYPE asr_mode_, string nn_hotwords_) { |
| | | |
| | | struct timeval start, end; |
| | |
| | | // warm up |
| | | for (size_t i = 0; i < 2; i++) |
| | | { |
| | | int32_t sampling_rate_ = 16000; |
| | | int32_t sampling_rate_ = audio_fs; |
| | | funasr::Audio audio(1); |
| | | if(is_target_file(wav_list[0].c_str(), "wav")){ |
| | | if(!audio.LoadWav2Char(wav_list[0].c_str(), &sampling_rate_)){ |
| | |
| | | if (i >= wav_list.size()) { |
| | | break; |
| | | } |
| | | int32_t sampling_rate_ = 16000; |
| | | int32_t sampling_rate_ = audio_fs; |
| | | funasr::Audio audio(1); |
| | | if(is_target_file(wav_list[i].c_str(), "wav")){ |
| | | if(!audio.LoadWav2Char(wav_list[i].c_str(), &sampling_rate_)){ |
| | |
| | | TCLAP::ValueArg<std::int32_t> onnx_thread("", "model-thread-num", "onnxruntime SetIntraOpNumThreads", false, 1, "int32_t"); |
| | | TCLAP::ValueArg<std::int32_t> thread_num_("", THREAD_NUM, "multi-thread num for rtf", 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | TCLAP::ValueArg<std::string> hotword("", HOTWORD, "the hotword file, one hotword perline, Format: Hotword Weight (could be: 阿里巴巴 20)", false, "", "string"); |
| | | |
| | | cmd.add(offline_model_dir); |
| | |
| | | cmd.add(punc_quant); |
| | | cmd.add(itn_dir); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.add(asr_mode); |
| | | cmd.add(onnx_thread); |
| | | cmd.add(thread_num_); |
| | |
| | | int rtf_threds = thread_num_.getValue(); |
| | | for (int i = 0; i < rtf_threds; i++) |
| | | { |
| | | threads.emplace_back(thread(runReg, tpass_hanlde, chunk_size, wav_list, wav_ids, &total_length, &total_time, i, (ASR_TYPE)asr_mode_, nn_hotwords_)); |
| | | threads.emplace_back(thread(runReg, tpass_hanlde, chunk_size, wav_list, wav_ids, audio_fs.getValue(), &total_length, &total_time, i, (ASR_TYPE)asr_mode_, nn_hotwords_)); |
| | | } |
| | | |
| | | for (auto& thread : threads) |
| | |
| | | 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | TCLAP::ValueArg<std::string> hotword("", HOTWORD, "the hotword file, one hotword perline, Format: Hotword Weight (could be: 阿里巴巴 20)", false, "", "string"); |
| | | |
| | | cmd.add(offline_model_dir); |
| | |
| | | cmd.add(punc_quant); |
| | | cmd.add(itn_dir); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.add(asr_mode); |
| | | cmd.add(onnx_thread); |
| | | cmd.add(hotword); |
| | |
| | | auto& wav_file = wav_list[i]; |
| | | auto& wav_id = wav_ids[i]; |
| | | |
| | | int32_t sampling_rate_ = 16000; |
| | | int32_t sampling_rate_ = audio_fs.getValue(); |
| | | funasr::Audio audio(1); |
| | | if(is_target_file(wav_file.c_str(), "wav")){ |
| | | if(!audio.LoadWav2Char(wav_file.c_str(), &sampling_rate_)){ |
| | |
| | | std::atomic<int> wav_index(0); |
| | | std::mutex mtx; |
| | | |
| | | void runReg(FUNASR_HANDLE asr_handle, vector<string> wav_list, vector<string> wav_ids, |
| | | void runReg(FUNASR_HANDLE asr_handle, vector<string> wav_list, vector<string> wav_ids, int audio_fs, |
| | | float* total_length, long* total_time, int core_id, float glob_beam = 3.0f, float lat_beam = 3.0f, float am_sc = 10.0f, |
| | | int fst_inc_wts = 20, string hotword_path = "") { |
| | | |
| | |
| | | for (size_t i = 0; i < 1; i++) |
| | | { |
| | | FunOfflineReset(asr_handle, decoder_handle); |
| | | FUNASR_RESULT result=FunOfflineInfer(asr_handle, wav_list[0].c_str(), RASR_NONE, NULL, hotwords_embedding, 16000, true, decoder_handle); |
| | | FUNASR_RESULT result=FunOfflineInfer(asr_handle, wav_list[0].c_str(), RASR_NONE, NULL, hotwords_embedding, audio_fs, true, decoder_handle); |
| | | if(result){ |
| | | FunASRFreeResult(result); |
| | | } |
| | |
| | | } |
| | | |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result=FunOfflineInfer(asr_handle, wav_list[i].c_str(), RASR_NONE, NULL, hotwords_embedding, 16000, true, decoder_handle); |
| | | FUNASR_RESULT result=FunOfflineInfer(asr_handle, wav_list[i].c_str(), RASR_NONE, NULL, hotwords_embedding, audio_fs, true, decoder_handle); |
| | | |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | |
| | | 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> 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | TCLAP::ValueArg<std::int32_t> thread_num("", THREAD_NUM, "multi-thread num for rtf", true, 0, "int32_t"); |
| | | TCLAP::ValueArg<std::string> hotword("", HOTWORD, "the hotword file, one hotword perline, Format: Hotword Weight (could be: 阿里巴巴 20)", false, "", "string"); |
| | | |
| | |
| | | cmd.add(hotword); |
| | | cmd.add(fst_inc_wts); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.add(thread_num); |
| | | cmd.parse(argc, argv); |
| | | |
| | |
| | | } |
| | | for (int i = 0; i < rtf_threds; i++) |
| | | { |
| | | threads.emplace_back(thread(runReg, asr_handle, wav_list, wav_ids, &total_length, &total_time, i, glob_beam, lat_beam, am_sc, value_bias, hotword_path)); |
| | | threads.emplace_back(thread(runReg, asr_handle, wav_list, wav_ids, audio_fs.getValue(), &total_length, &total_time, i, glob_beam, lat_beam, am_sc, value_bias, hotword_path)); |
| | | } |
| | | |
| | | for (auto& thread : threads) |
| | |
| | | TCLAP::ValueArg<std::string> quantize("", QUANTIZE, "true (Default), load the model of model.onnx in model_dir. If set true, load the model of model_quant.onnx in model_dir", false, "true", "string"); |
| | | |
| | | 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | |
| | | cmd.add(model_dir); |
| | | cmd.add(quantize); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.parse(argc, argv); |
| | | |
| | | std::map<std::string, std::string> model_path; |
| | |
| | | auto& wav_file = wav_list[i]; |
| | | auto& wav_id = wav_ids[i]; |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result=FsmnVadInfer(vad_hanlde, wav_file.c_str(), NULL, 16000); |
| | | FUNASR_RESULT result=FsmnVadInfer(vad_hanlde, wav_file.c_str(), NULL, audio_fs.getValue()); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | taking_micros += ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | |
| | | TCLAP::ValueArg<std::int32_t> fst_inc_wts("", FST_INC_WTS, "the fst hotwords incremental bias", false, 20, "int32_t"); |
| | | 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> 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | TCLAP::ValueArg<std::string> hotword("", HOTWORD, "the hotword file, one hotword perline, Format: Hotword Weight (could be: 阿里巴巴 20)", false, "", "string"); |
| | | |
| | | cmd.add(model_dir); |
| | |
| | | cmd.add(am_scale); |
| | | cmd.add(fst_inc_wts); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.add(hotword); |
| | | cmd.parse(argc, argv); |
| | | |
| | |
| | | auto& wav_file = wav_list[i]; |
| | | auto& wav_id = wav_ids[i]; |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result=FunOfflineInfer(asr_hanlde, wav_file.c_str(), RASR_NONE, NULL, hotwords_embedding, 16000, true, decoder_handle); |
| | | FUNASR_RESULT result=FunOfflineInfer(asr_hanlde, wav_file.c_str(), RASR_NONE, NULL, hotwords_embedding, audio_fs.getValue(), true, decoder_handle); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | taking_micros += ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | |
| | | TCLAP::ValueArg<std::string> quantize("", QUANTIZE, "true (Default), load the model of model.onnx in model_dir. If set true, load the model of model_quant.onnx in model_dir", false, "true", "string"); |
| | | |
| | | 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | |
| | | cmd.add(model_dir); |
| | | cmd.add(quantize); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.parse(argc, argv); |
| | | |
| | | std::map<std::string, std::string> model_path; |
| | |
| | | is_final = false; |
| | | } |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result = FunASRInferBuffer(online_handle, speech_buff+sample_offset, step, RASR_NONE, NULL, is_final, 16000); |
| | | FUNASR_RESULT result = FunASRInferBuffer(online_handle, speech_buff+sample_offset, step, RASR_NONE, NULL, is_final, audio_fs.getValue()); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | taking_micros += ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | |
| | | return (extension == target); |
| | | } |
| | | |
| | | void runReg(FUNASR_HANDLE asr_handle, vector<string> wav_list, vector<string> wav_ids, |
| | | void runReg(FUNASR_HANDLE asr_handle, vector<string> wav_list, vector<string> wav_ids, int audio_fs, |
| | | float* total_length, long* total_time, int core_id) { |
| | | |
| | | struct timeval start, end; |
| | |
| | | } else { |
| | | is_final = false; |
| | | } |
| | | FUNASR_RESULT result = FunASRInferBuffer(online_handle, speech_buff+sample_offset, step, RASR_NONE, NULL, is_final, 16000); |
| | | FUNASR_RESULT result = FunASRInferBuffer(online_handle, speech_buff+sample_offset, step, RASR_NONE, NULL, is_final, audio_fs); |
| | | if (result) |
| | | { |
| | | FunASRFreeResult(result); |
| | |
| | | is_final = false; |
| | | } |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result = FunASRInferBuffer(online_handle, speech_buff+sample_offset, step, RASR_NONE, NULL, is_final, 16000); |
| | | FUNASR_RESULT result = FunASRInferBuffer(online_handle, speech_buff+sample_offset, step, RASR_NONE, NULL, is_final, audio_fs); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | long taking_micros = ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | |
| | | 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> 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | TCLAP::ValueArg<std::int32_t> thread_num("", THREAD_NUM, "multi-thread num for rtf", true, 0, "int32_t"); |
| | | |
| | | cmd.add(model_dir); |
| | |
| | | cmd.add(punc_dir); |
| | | cmd.add(punc_quant); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.add(thread_num); |
| | | cmd.parse(argc, argv); |
| | | |
| | |
| | | int rtf_threds = thread_num.getValue(); |
| | | for (int i = 0; i < rtf_threds; i++) |
| | | { |
| | | threads.emplace_back(thread(runReg, asr_handle, wav_list, wav_ids, &total_length, &total_time, i)); |
| | | threads.emplace_back(thread(runReg, asr_handle, wav_list, wav_ids, audio_fs.getValue(), &total_length, &total_time, i)); |
| | | } |
| | | |
| | | for (auto& thread : threads) |
| | |
| | | TCLAP::ValueArg<std::string> quantize("", QUANTIZE, "false (Default), load the model of model.onnx in model_dir. If set true, load the model of model_quant.onnx in model_dir", false, "true", "string"); |
| | | |
| | | 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::int32_t> audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t"); |
| | | |
| | | cmd.add(model_dir); |
| | | cmd.add(quantize); |
| | | cmd.add(wav_path); |
| | | cmd.add(audio_fs); |
| | | cmd.parse(argc, argv); |
| | | |
| | | std::map<std::string, std::string> model_path; |
| | |
| | | is_final = false; |
| | | } |
| | | gettimeofday(&start, NULL); |
| | | FUNASR_RESULT result = FsmnVadInferBuffer(online_hanlde, speech_buff+sample_offset, step, NULL, is_final, 16000); |
| | | FUNASR_RESULT result = FsmnVadInferBuffer(online_hanlde, speech_buff+sample_offset, step, NULL, is_final, audio_fs.getValue()); |
| | | gettimeofday(&end, NULL); |
| | | seconds = (end.tv_sec - start.tv_sec); |
| | | taking_micros += ((seconds * 1000000) + end.tv_usec) - (start.tv_usec); |
| | |
| | | #define THREAD_NUM "thread-num" |
| | | #define PORT_ID "port-id" |
| | | #define HOTWORD_SEP " " |
| | | #define AUDIO_FS "audio-fs" |
| | | |
| | | // #define VAD_MODEL_PATH "vad-model" |
| | | // #define VAD_CMVN_PATH "vad-cmvn" |
| | |
| | | { |
| | | LOG(INFO) << "Creating a resampler:\n" |
| | | << " in_sample_rate: "<< sampling_rate << "\n" |
| | | << " output_sample_rate: " << static_cast<int32_t>(MODEL_SAMPLE_RATE); |
| | | << " output_sample_rate: " << static_cast<int32_t>(dest_sample_rate); |
| | | float min_freq = |
| | | std::min<int32_t>(sampling_rate, dest_sample_rate); |
| | | float lowpass_cutoff = 0.99 * 0.5 * min_freq; |
| | |
| | | int32_t in_feat_dim = fbank_opts_.mel_opts.num_bins; |
| | | |
| | | std::vector<std::vector<float>> asr_feats; |
| | | FbankKaldi(MODEL_SAMPLE_RATE, din, len, asr_feats); |
| | | FbankKaldi(asr_sample_rate, din, len, asr_feats); |
| | | if(asr_feats.size() == 0){ |
| | | return ""; |
| | | } |
| | |
| | | data_msg->msg["wav_name"] = "wav-default-id"; |
| | | data_msg->msg["mode"] = "2pass"; |
| | | data_msg->msg["itn"] = true; |
| | | data_msg->msg["audio_fs"] = 16000; |
| | | data_msg->msg["audio_fs"] = 16000; // default is 16k |
| | | data_msg->msg["access_num"] = 0; // the number of access for this object, when it is 0, we can free it saftly |
| | | data_msg->msg["is_eof"]=false; // if this connection is closed |
| | | data_msg->punc_cache = |
| | |
| | | data_msg->msg["wav_format"] = "pcm"; |
| | | data_msg->msg["wav_name"] = "wav-default-id"; |
| | | data_msg->msg["itn"] = true; |
| | | data_msg->msg["audio_fs"] = 16000; |
| | | data_msg->msg["audio_fs"] = 16000; // default is 16k |
| | | data_msg->msg["access_num"] = 0; // the number of access for this object, when it is 0, we can free it saftly |
| | | data_msg->msg["is_eof"]=false; |
| | | FUNASR_DEC_HANDLE decoder_handle = |