| | |
| | | #ifndef PARAFORMER_MODELIMP_H |
| | | #define PARAFORMER_MODELIMP_H |
| | | |
| | | #include "precomp.h" |
| | | |
| | | namespace paraformer { |
| | | |
| | | class ModelImp : public Model { |
| | | private: |
| | | //FeatureExtract* fe; |
| | | //std::unique_ptr<knf::OnlineFbank> fbank_; |
| | | knf::FbankOptions fbank_opts; |
| | | |
| | | std::unique_ptr<FsmnVad> vadHandle; |
| | | |
| | | Vocab* vocab; |
| | | vector<float> means_list; |
| | | vector<float> vars_list; |
| | | const float scale = 22.6274169979695; |
| | | int32_t lfr_window_size = 7; |
| | | int32_t lfr_window_shift = 6; |
| | | |
| | | void apply_lfr(Tensor<float>*& din); |
| | | void apply_cmvn(Tensor<float>* din); |
| | | void load_cmvn(const char *filename); |
| | | vector<float> ApplyLFR(const vector<float> &in); |
| | | void ApplyCMVN(vector<float> *v); |
| | | |
| | | string greedy_search( float* in, int nLen); |
| | | |
| | | #ifdef _WIN_X86 |
| | | Ort::MemoryInfo m_memoryInfo = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU); |
| | | #else |
| | | Ort::MemoryInfo m_memoryInfo = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); |
| | | #endif |
| | | |
| | | Ort::Session* m_session = nullptr; |
| | | Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "paraformer"); |
| | | Ort::SessionOptions sessionOptions = Ort::SessionOptions(); |
| | | std::shared_ptr<Ort::Session> m_session; |
| | | Ort::Env env_; |
| | | Ort::SessionOptions sessionOptions; |
| | | |
| | | vector<string> m_strInputNames, m_strOutputNames; |
| | | vector<const char*> m_szInputNames; |
| | | vector<const char*> m_szOutputNames; |
| | | |
| | | public: |
| | | ModelImp(const char* path, int nNumThread=0, bool quantize=false); |
| | | ModelImp(const char* path, int nNumThread=0, bool quantize=false, bool use_vad=false); |
| | | ~ModelImp(); |
| | | void reset(); |
| | | vector<float> FbankKaldi(float sample_rate, const float* waves, int len); |
| | | string forward_chunk(float* din, int len, int flag); |
| | | string forward(float* din, int len, int flag); |
| | | string rescoring(); |
| | | std::vector<std::vector<int>> vad_seg(std::vector<float>& pcm_data); |
| | | |
| | | }; |
| | | |