jmwang66
2023-05-09 8dab6d184a034ca86eafa644ea0d2100aadfe27d
funasr/runtime/onnxruntime/src/online-feature.cpp
@@ -1,7 +1,12 @@
/**
 * Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
 * MIT License  (https://opensource.org/licenses/MIT)
*/
#include "online-feature.h"
#include <utility>
namespace funasr {
OnlineFeature::OnlineFeature(int sample_rate, knf::FbankOptions fbank_opts, int lfr_m, int lfr_n,
                             std::vector<std::vector<float>> cmvns)
  : sample_rate_(sample_rate),
@@ -13,10 +18,10 @@
  frame_shift_sample_length_ = sample_rate_ / 1000 * 10;
}
void OnlineFeature::extractFeats(vector<std::vector<float>> &vad_feats,
void OnlineFeature::ExtractFeats(vector<std::vector<float>> &vad_feats,
                                 vector<float> waves, bool input_finished) {
  input_finished_ = input_finished;
  onlineFbank(vad_feats, waves);
  OnlineFbank(vad_feats, waves);
  // cache deal & online lfr,cmvn
  if (vad_feats.size() > 0) {
    if (!reserve_waveforms_.empty()) {
@@ -53,7 +58,7 @@
      }
      vad_feats = lfr_splice_cache_;
      OnlineLfrCmvn(vad_feats);
      reset_cache();
      ResetCache();
    }
  }
@@ -102,13 +107,13 @@
  return lfr_splice_frame_idxs;
}
void OnlineFeature::onlineFbank(vector<std::vector<float>> &vad_feats,
void OnlineFeature::OnlineFbank(vector<std::vector<float>> &vad_feats,
                                vector<float> &waves) {
  knf::OnlineFbank fbank(fbank_opts_);
  // cache merge
  waves.insert(waves.begin(), input_cache_.begin(), input_cache_.end());
  int frame_number = compute_frame_num(waves.size(), frame_sample_length_, frame_shift_sample_length_);
  int frame_number = ComputeFrameNum(waves.size(), frame_sample_length_, frame_shift_sample_length_);
  // Send the audio after the last frame shift position to the cache
  input_cache_.clear();
  input_cache_.insert(input_cache_.begin(), waves.begin() + frame_number * frame_shift_sample_length_, waves.end());
@@ -127,3 +132,5 @@
  }
}
} // namespace funasr