雾聪
2023-12-13 de87e1d180d214e1f49682d2b5fb7c9d2c89ae7e
adapted pcm to 8k
13个文件已修改
59 ■■■■■ 已修改文件
runtime/onnxruntime/bin/funasr-onnx-2pass-rtf.cpp 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-2pass.cpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-offline-rtf.cpp 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-offline-vad.cpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-offline.cpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-online-asr.cpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-online-rtf.cpp 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-online-vad.cpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/include/com-define.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/src/audio.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/src/paraformer.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/websocket/bin/websocket-server-2pass.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/websocket/bin/websocket-server.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/onnxruntime/bin/funasr-onnx-2pass-rtf.cpp
@@ -43,7 +43,7 @@
    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;
@@ -59,7 +59,7 @@
    // 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_)){
@@ -104,7 +104,7 @@
        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_)){
@@ -220,6 +220,7 @@
    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);
@@ -231,6 +232,7 @@
    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_);
@@ -319,7 +321,7 @@
    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)
runtime/onnxruntime/bin/funasr-onnx-2pass.cpp
@@ -55,6 +55,7 @@
    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);
@@ -66,6 +67,7 @@
    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);
@@ -154,7 +156,7 @@
        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_)){
runtime/onnxruntime/bin/funasr-onnx-offline-rtf.cpp
@@ -29,7 +29,7 @@
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 = "") {
    
@@ -55,7 +55,7 @@
    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);
        }
@@ -69,7 +69,7 @@
        }
        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);
@@ -138,6 +138,7 @@
    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");
@@ -155,6 +156,7 @@
    cmd.add(hotword);
    cmd.add(fst_inc_wts);
    cmd.add(wav_path);
    cmd.add(audio_fs);
    cmd.add(thread_num);
    cmd.parse(argc, argv);
@@ -234,7 +236,7 @@
    }
    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)
runtime/onnxruntime/bin/funasr-onnx-offline-vad.cpp
@@ -68,10 +68,12 @@
    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;
@@ -131,7 +133,7 @@
        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);
runtime/onnxruntime/bin/funasr-onnx-offline.cpp
@@ -57,6 +57,7 @@
    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);
@@ -72,6 +73,7 @@
    cmd.add(am_scale);
    cmd.add(fst_inc_wts);
    cmd.add(wav_path);
    cmd.add(audio_fs);
    cmd.add(hotword);
    cmd.parse(argc, argv);
@@ -157,7 +159,7 @@
        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);
runtime/onnxruntime/bin/funasr-onnx-online-asr.cpp
@@ -49,10 +49,12 @@
    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;
@@ -143,7 +145,7 @@
                    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);
runtime/onnxruntime/bin/funasr-onnx-online-rtf.cpp
@@ -38,7 +38,7 @@
    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;
@@ -84,7 +84,7 @@
                } 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);
@@ -131,7 +131,7 @@
                    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);
@@ -186,6 +186,7 @@
    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);
@@ -195,6 +196,7 @@
    cmd.add(punc_dir);
    cmd.add(punc_quant);
    cmd.add(wav_path);
    cmd.add(audio_fs);
    cmd.add(thread_num);
    cmd.parse(argc, argv);
@@ -260,7 +262,7 @@
    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)
runtime/onnxruntime/bin/funasr-onnx-online-vad.cpp
@@ -75,10 +75,12 @@
    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;
@@ -170,7 +172,7 @@
                    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);
runtime/onnxruntime/include/com-define.h
@@ -34,6 +34,7 @@
#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"
runtime/onnxruntime/src/audio.cpp
@@ -245,7 +245,7 @@
{
    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;
runtime/onnxruntime/src/paraformer.cpp
@@ -466,7 +466,7 @@
    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 "";
    }
runtime/websocket/bin/websocket-server-2pass.cpp
@@ -232,7 +232,7 @@
    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 =
runtime/websocket/bin/websocket-server.cpp
@@ -144,7 +144,7 @@
  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 =