funasr/runtime/onnxruntime/src/alignedmem.cpp
@@ -1,4 +1,6 @@ #include "precomp.h" namespace funasr { void *AlignedMalloc(size_t alignment, size_t required_bytes) { void *p1; // original block @@ -16,3 +18,4 @@ { free(((void **)p)[-1]); } } // namespace funasr funasr/runtime/onnxruntime/src/alignedmem.h
@@ -2,7 +2,9 @@ #ifndef ALIGNEDMEM_H #define ALIGNEDMEM_H namespace funasr { extern void *AlignedMalloc(size_t alignment, size_t required_bytes); extern void AlignedFree(void *p); } // namespace funasr #endif funasr/runtime/onnxruntime/src/audio.cpp
@@ -11,6 +11,7 @@ using namespace std; namespace funasr { // see http://soundfile.sapp.org/doc/WaveFormat/ // Note: We assume little endian here struct WaveHeader { @@ -553,3 +554,5 @@ std::vector<float> pcm_data(speech_data, speech_data+sp_len); vad_segments = vad_obj->Infer(pcm_data); } } // namespace funasr funasr/runtime/onnxruntime/src/commonfunc.h
@@ -1,5 +1,7 @@ #pragma once #include <algorithm> namespace funasr { typedef struct { std::string msg; @@ -58,3 +60,4 @@ inline static size_t Argmax(ForwardIterator first, ForwardIterator last) { return std::distance(first, std::max_element(first, last)); } } // namespace funasr funasr/runtime/onnxruntime/src/ct-transformer.cpp
@@ -5,6 +5,7 @@ #include "precomp.h" namespace funasr { CTTransformer::CTTransformer() :env_(ORT_LOGGING_LEVEL_ERROR, ""),session_options{} { @@ -186,3 +187,4 @@ return punction; } } // namespace funasr funasr/runtime/onnxruntime/src/ct-transformer.h
@@ -5,6 +5,7 @@ #pragma once namespace funasr { class CTTransformer : public PuncModel { /** * Author: Speech Lab of DAMO Academy, Alibaba Group @@ -30,3 +31,4 @@ vector<int> Infer(vector<int32_t> input_data); string AddPunc(const char* sz_input); }; } // namespace funasr funasr/runtime/onnxruntime/src/e2e-vad.h
@@ -3,6 +3,8 @@ * MIT License (https://opensource.org/licenses/MIT) */ #pragma once #include <utility> #include <vector> #include <string> @@ -13,7 +15,7 @@ #include <numeric> #include <cassert> namespace funasr { enum class VadStateMachine { kVadInStateStartPointNotDetected = 1, kVadInStateInSpeechSegment = 2, @@ -779,5 +781,4 @@ }; } // namespace funasr funasr/runtime/onnxruntime/src/fsmn-vad.cpp
@@ -6,6 +6,7 @@ #include <fstream> #include "precomp.h" namespace funasr { void FsmnVad::InitVad(const std::string &vad_model, const std::string &vad_cmvn, const std::string &vad_config, int thread_num) { session_options_.SetIntraOpNumThreads(thread_num); session_options_.SetGraphOptimizationLevel(ORT_ENABLE_ALL); @@ -301,3 +302,5 @@ FsmnVad::FsmnVad():env_(ORT_LOGGING_LEVEL_ERROR, ""),session_options_{} { } } // namespace funasr funasr/runtime/onnxruntime/src/fsmn-vad.h
@@ -8,6 +8,7 @@ #include "precomp.h" namespace funasr { class FsmnVad : public VadModel { /** * Author: Speech Lab of DAMO Academy, Alibaba Group @@ -63,5 +64,5 @@ int lfr_n = VAD_LFR_N; }; } // namespace funasr #endif //VAD_SERVER_FSMNVAD_H funasr/runtime/onnxruntime/src/funasrruntime.cpp
@@ -7,44 +7,44 @@ // APIs for Init _FUNASRAPI FUNASR_HANDLE FunASRInit(std::map<std::string, std::string>& model_path, int thread_num) { Model* mm = CreateModel(model_path, thread_num); funasr::Model* mm = funasr::CreateModel(model_path, thread_num); return mm; } _FUNASRAPI FUNASR_HANDLE FsmnVadInit(std::map<std::string, std::string>& model_path, int thread_num) { VadModel* mm = CreateVadModel(model_path, thread_num); funasr::VadModel* mm = funasr::CreateVadModel(model_path, thread_num); return mm; } _FUNASRAPI FUNASR_HANDLE FunPuncInit(std::map<std::string, std::string>& model_path, int thread_num) { PuncModel* mm = CreatePuncModel(model_path, thread_num); funasr::PuncModel* mm = funasr::CreatePuncModel(model_path, thread_num); return mm; } _FUNASRAPI FUNASR_HANDLE FunOfflineInit(std::map<std::string, std::string>& model_path, int thread_num) { OfflineStream* mm = CreateOfflineStream(model_path, thread_num); funasr::OfflineStream* mm = funasr::CreateOfflineStream(model_path, thread_num); return mm; } // APIs for ASR Infer _FUNASRAPI FUNASR_RESULT FunASRRecogBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, FUNASR_MODE mode, QM_CALLBACK fn_callback) { Model* recog_obj = (Model*)handle; funasr::Model* recog_obj = (funasr::Model*)handle; if (!recog_obj) return nullptr; int32_t sampling_rate = -1; Audio audio(1); funasr::Audio audio(1); if (!audio.LoadWav(sz_buf, n_len, &sampling_rate)) return nullptr; float* buff; int len; int flag=0; FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT; p_result->snippet_time = audio.GetTimeLen(); int n_step = 0; int n_total = audio.GetQueueSize(); @@ -61,18 +61,18 @@ _FUNASRAPI FUNASR_RESULT FunASRRecogPCMBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback) { Model* recog_obj = (Model*)handle; funasr::Model* recog_obj = (funasr::Model*)handle; if (!recog_obj) return nullptr; Audio audio(1); funasr::Audio audio(1); if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate)) return nullptr; float* buff; int len; int flag = 0; FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT; p_result->snippet_time = audio.GetTimeLen(); int n_step = 0; int n_total = audio.GetQueueSize(); @@ -89,18 +89,18 @@ _FUNASRAPI FUNASR_RESULT FunASRRecogPCMFile(FUNASR_HANDLE handle, const char* sz_filename, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback) { Model* recog_obj = (Model*)handle; funasr::Model* recog_obj = (funasr::Model*)handle; if (!recog_obj) return nullptr; Audio audio(1); funasr::Audio audio(1); if (!audio.LoadPcmwav(sz_filename, &sampling_rate)) return nullptr; float* buff; int len; int flag = 0; FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT; p_result->snippet_time = audio.GetTimeLen(); int n_step = 0; int n_total = audio.GetQueueSize(); @@ -117,12 +117,12 @@ _FUNASRAPI FUNASR_RESULT FunASRRecogFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback) { Model* recog_obj = (Model*)handle; funasr::Model* recog_obj = (funasr::Model*)handle; if (!recog_obj) return nullptr; int32_t sampling_rate = -1; Audio audio(1); funasr::Audio audio(1); if(!audio.LoadWav(sz_wavfile, &sampling_rate)) return nullptr; @@ -131,7 +131,7 @@ int flag = 0; int n_step = 0; int n_total = audio.GetQueueSize(); FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT; p_result->snippet_time = audio.GetTimeLen(); while (audio.Fetch(buff, len, flag) > 0) { string msg = recog_obj->Forward(buff, len, flag); @@ -147,16 +147,16 @@ // APIs for VAD Infer _FUNASRAPI FUNASR_RESULT FsmnVadWavFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback) { VadModel* vad_obj = (VadModel*)handle; funasr::VadModel* vad_obj = (funasr::VadModel*)handle; if (!vad_obj) return nullptr; int32_t sampling_rate = -1; Audio audio(1); funasr::Audio audio(1); if(!audio.LoadWav(sz_wavfile, &sampling_rate)) return nullptr; FUNASR_VAD_RESULT* p_result = new FUNASR_VAD_RESULT; funasr::FUNASR_VAD_RESULT* p_result = new funasr::FUNASR_VAD_RESULT; p_result->snippet_time = audio.GetTimeLen(); vector<std::vector<int>> vad_segments; @@ -169,7 +169,7 @@ // APIs for PUNC Infer _FUNASRAPI const std::string FunPuncInfer(FUNASR_HANDLE handle, const char* sz_sentence, FUNASR_MODE mode, QM_CALLBACK fn_callback) { PuncModel* punc_obj = (PuncModel*)handle; funasr::PuncModel* punc_obj = (funasr::PuncModel*)handle; if (!punc_obj) return nullptr; @@ -180,12 +180,12 @@ // APIs for Offline-stream Infer _FUNASRAPI FUNASR_RESULT FunOfflineRecogFile(FUNASR_HANDLE handle, const char* sz_wavfile, FUNASR_MODE mode, QM_CALLBACK fn_callback) { OfflineStream* offline_stream = (OfflineStream*)handle; funasr::OfflineStream* offline_stream = (funasr::OfflineStream*)handle; if (!offline_stream) return nullptr; int32_t sampling_rate = -1; Audio audio(1); funasr::Audio audio(1); if(!audio.LoadWav(sz_wavfile, &sampling_rate)) return nullptr; if(offline_stream->UseVad()){ @@ -197,7 +197,7 @@ int flag = 0; int n_step = 0; int n_total = audio.GetQueueSize(); FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT; p_result->snippet_time = audio.GetTimeLen(); while (audio.Fetch(buff, len, flag) > 0) { string msg = (offline_stream->asr_handle)->Forward(buff, len, flag); @@ -216,11 +216,11 @@ _FUNASRAPI FUNASR_RESULT FunOfflineRecogPCMBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len, int sampling_rate, FUNASR_MODE mode, QM_CALLBACK fn_callback) { OfflineStream* offline_stream = (OfflineStream*)handle; funasr::OfflineStream* offline_stream = (funasr::OfflineStream*)handle; if (!offline_stream) return nullptr; Audio audio(1); funasr::Audio audio(1); if (!audio.LoadPcmwav(sz_buf, n_len, &sampling_rate)) return nullptr; if(offline_stream->UseVad()){ @@ -230,7 +230,7 @@ float* buff; int len; int flag = 0; FUNASR_RECOG_RESULT* p_result = new FUNASR_RECOG_RESULT; funasr::FUNASR_RECOG_RESULT* p_result = new funasr::FUNASR_RECOG_RESULT; p_result->snippet_time = audio.GetTimeLen(); int n_step = 0; int n_total = audio.GetQueueSize(); @@ -263,7 +263,7 @@ if (!result) return 0.0f; return ((FUNASR_RECOG_RESULT*)result)->snippet_time; return ((funasr::FUNASR_RECOG_RESULT*)result)->snippet_time; } _FUNASRAPI const float FsmnVadGetRetSnippetTime(FUNASR_RESULT result) @@ -271,13 +271,13 @@ if (!result) return 0.0f; return ((FUNASR_VAD_RESULT*)result)->snippet_time; return ((funasr::FUNASR_VAD_RESULT*)result)->snippet_time; } // APIs for GetResult _FUNASRAPI const char* FunASRGetResult(FUNASR_RESULT result,int n_index) { FUNASR_RECOG_RESULT * p_result = (FUNASR_RECOG_RESULT*)result; funasr::FUNASR_RECOG_RESULT * p_result = (funasr::FUNASR_RECOG_RESULT*)result; if(!p_result) return nullptr; @@ -286,7 +286,7 @@ _FUNASRAPI vector<std::vector<int>>* FsmnVadGetResult(FUNASR_RESULT result,int n_index) { FUNASR_VAD_RESULT * p_result = (FUNASR_VAD_RESULT*)result; funasr::FUNASR_VAD_RESULT * p_result = (funasr::FUNASR_VAD_RESULT*)result; if(!p_result) return nullptr; @@ -298,13 +298,13 @@ { if (result) { delete (FUNASR_RECOG_RESULT*)result; delete (funasr::FUNASR_RECOG_RESULT*)result; } } _FUNASRAPI void FsmnVadFreeResult(FUNASR_RESULT result) { FUNASR_VAD_RESULT * p_result = (FUNASR_VAD_RESULT*)result; funasr::FUNASR_VAD_RESULT * p_result = (funasr::FUNASR_VAD_RESULT*)result; if (p_result) { if(p_result->segments){ @@ -317,7 +317,7 @@ // APIs for Uninit _FUNASRAPI void FunASRUninit(FUNASR_HANDLE handle) { Model* recog_obj = (Model*)handle; funasr::Model* recog_obj = (funasr::Model*)handle; if (!recog_obj) return; @@ -327,7 +327,7 @@ _FUNASRAPI void FsmnVadUninit(FUNASR_HANDLE handle) { VadModel* recog_obj = (VadModel*)handle; funasr::VadModel* recog_obj = (funasr::VadModel*)handle; if (!recog_obj) return; @@ -337,7 +337,7 @@ _FUNASRAPI void FunPuncUninit(FUNASR_HANDLE handle) { PuncModel* punc_obj = (PuncModel*)handle; funasr::PuncModel* punc_obj = (funasr::PuncModel*)handle; if (!punc_obj) return; @@ -347,7 +347,7 @@ _FUNASRAPI void FunOfflineUninit(FUNASR_HANDLE handle) { OfflineStream* offline_stream = (OfflineStream*)handle; funasr::OfflineStream* offline_stream = (funasr::OfflineStream*)handle; if (!offline_stream) return; funasr/runtime/onnxruntime/src/model.cpp
@@ -1,5 +1,6 @@ #include "precomp.h" namespace funasr { Model *CreateModel(std::map<std::string, std::string>& model_path, int thread_num) { string am_model_path; @@ -14,7 +15,9 @@ am_config_path = PathAppend(model_path.at(MODEL_DIR), AM_CONFIG_NAME); Model *mm; mm = new paraformer::Paraformer(); mm = new Paraformer(); mm->InitAsr(am_model_path, am_cmvn_path, am_config_path, thread_num); return mm; } } // namespace funasr funasr/runtime/onnxruntime/src/offline-stream.cpp
@@ -1,5 +1,6 @@ #include "precomp.h" namespace funasr { OfflineStream::OfflineStream(std::map<std::string, std::string>& model_path, int thread_num) { // VAD model @@ -59,3 +60,5 @@ mm = new OfflineStream(model_path, thread_num); return mm; } } // namespace funasr funasr/runtime/onnxruntime/src/online-feature.cpp
@@ -6,6 +6,7 @@ #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), @@ -131,3 +132,5 @@ } } } // namespace funasr funasr/runtime/onnxruntime/src/online-feature.h
@@ -2,12 +2,12 @@ * Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved. * MIT License (https://opensource.org/licenses/MIT) */ #pragma once #include <vector> #include "precomp.h" using namespace std; namespace funasr { class OnlineFeature { public: @@ -53,3 +53,5 @@ bool input_finished_ = false; }; } // namespace funasr funasr/runtime/onnxruntime/src/paraformer.cpp
@@ -6,7 +6,8 @@ #include "precomp.h" using namespace std; using namespace paraformer; namespace funasr { Paraformer::Paraformer() :env_(ORT_LOGGING_LEVEL_ERROR, "paraformer"),session_options{}{ @@ -238,3 +239,4 @@ LOG(ERROR)<<"Not Imp!!!!!!"; return ""; } } // namespace funasr funasr/runtime/onnxruntime/src/paraformer.h
@@ -4,12 +4,9 @@ */ #pragma once #ifndef PARAFORMER_MODELIMP_H #define PARAFORMER_MODELIMP_H #include "precomp.h" namespace paraformer { namespace funasr { class Paraformer : public Model { /** @@ -52,5 +49,4 @@ string Rescoring(); }; } // namespace paraformer #endif } // namespace funasr funasr/runtime/onnxruntime/src/precomp.h
@@ -46,5 +46,3 @@ #include "paraformer.h" #include "offline-stream.h" #include "funasrruntime.h" using namespace paraformer; funasr/runtime/onnxruntime/src/predefine-coe.h
@@ -3,6 +3,7 @@ #include <stdint.h> namespace funasr { const int32_t melcoe_hex[] = { 0x3f01050c, 0x3e0afb11, 0x3f5d413c, 0x3f547fd0, 0x3e2e00c1, 0x3f132970, @@ -590,3 +591,5 @@ 0x39164323, 0x3910f3c6, 0x390bd472, 0x3906e374, 0x39021f2b, 0x38fb0c03, 0x38f22ce3, 0x38e99e04, 0x38e15c92, 0x38d965ce}; #endif } // namespace funasr funasr/runtime/onnxruntime/src/punc-model.cpp
@@ -1,5 +1,6 @@ #include "precomp.h" namespace funasr { PuncModel *CreatePuncModel(std::map<std::string, std::string>& model_path, int thread_num) { PuncModel *mm; @@ -17,3 +18,5 @@ mm->InitPunc(punc_model_path, punc_config_path, thread_num); return mm; } } // namespace funasr funasr/runtime/onnxruntime/src/resample.cpp
@@ -31,6 +31,7 @@ #include <cstdlib> #include <type_traits> namespace funasr { #ifndef M_2PI #define M_2PI 6.283185307179586476925286766559005 #endif @@ -303,3 +304,4 @@ } } } } // namespace funasr funasr/runtime/onnxruntime/src/resample.h
@@ -21,11 +21,11 @@ */ // this file is copied and modified from // kaldi/src/feat/resample.h #pragma once #include <cstdint> #include <vector> namespace funasr { /* We require that the input and output sampling rate be specified as integers, as this is an easy way to specify that their ratio be rational. @@ -135,3 +135,4 @@ std::vector<float> input_remainder_; ///< A small trailing part of the ///< previously seen input signal. }; } // namespace funasr funasr/runtime/onnxruntime/src/tensor.h
@@ -5,6 +5,8 @@ using namespace std; namespace funasr { template <typename T> class Tensor { private: void alloc_buff(); @@ -152,4 +154,6 @@ fwrite(buff, 1, buff_size * sizeof(T), fp); fclose(fp); } } // namespace funasr #endif funasr/runtime/onnxruntime/src/tokenizer.cpp
@@ -5,6 +5,7 @@ #include "precomp.h" namespace funasr { CTokenizer::CTokenizer(const char* sz_yamlfile):m_ready(false) { OpenYaml(sz_yamlfile); @@ -220,3 +221,5 @@ } id_out= String2Ids(str_out); } } // namespace funasr funasr/runtime/onnxruntime/src/tokenizer.h
@@ -6,6 +6,7 @@ #pragma once #include <yaml-cpp/yaml.h> namespace funasr { class CTokenizer { private: @@ -31,3 +32,5 @@ void Tokenize(const char* str_info, vector<string>& str_out, vector<int>& id_out); }; } // namespace funasr funasr/runtime/onnxruntime/src/util.cpp
@@ -1,6 +1,7 @@ #include "precomp.h" namespace funasr { float *LoadParams(const char *filename) { @@ -178,3 +179,5 @@ } } } } // namespace funasr funasr/runtime/onnxruntime/src/util.h
@@ -1,10 +1,9 @@ #ifndef UTIL_H #define UTIL_H using namespace std; namespace funasr { extern float *LoadParams(const char *filename); extern void SaveDataFile(const char *filename, void *data, uint32_t len); @@ -27,4 +26,5 @@ string PathAppend(const string &p1, const string &p2); } // namespace funasr #endif funasr/runtime/onnxruntime/src/vad-model.cpp
@@ -1,5 +1,6 @@ #include "precomp.h" namespace funasr { VadModel *CreateVadModel(std::map<std::string, std::string>& model_path, int thread_num) { VadModel *mm; @@ -19,3 +20,5 @@ mm->InitVad(vad_model_path, vad_cmvn_path, vad_config_path, thread_num); return mm; } } // namespace funasr funasr/runtime/onnxruntime/src/vocab.cpp
@@ -10,6 +10,7 @@ using namespace std; namespace funasr { Vocab::Vocab(const char *filename) { ifstream in(filename); @@ -151,3 +152,5 @@ { return vocab.size(); } } // namespace funasr funasr/runtime/onnxruntime/src/vocab.h
@@ -7,6 +7,7 @@ #include <vector> using namespace std; namespace funasr { class Vocab { private: vector<string> vocab; @@ -22,4 +23,5 @@ string Vector2StringV2(vector<int> in); }; } // namespace funasr #endif