| | |
| | | #define FUNASR_CALLBCK_PREFIX __stdcall |
| | | #endif |
| | | |
| | | #ifdef __cplusplus |
| | | |
| | | extern "C" { |
| | | #endif |
| | | |
| | | typedef void* FUNASR_HANDLE; |
| | | typedef void* FUNASR_RESULT; |
| | |
| | | _FUNASRAPI void FunTpassUninit(FUNASR_HANDLE handle); |
| | | _FUNASRAPI void FunTpassOnlineUninit(FUNASR_HANDLE handle); |
| | | |
| | | #ifdef __cplusplus |
| | | |
| | | } |
| | | #endif |
| | |
| | | #include "audio.h" |
| | | #include "precomp.h" |
| | | |
| | | #ifdef _MSC_VER |
| | | #pragma warning(disable:4996) |
| | | #endif |
| | | |
| | | #if defined(__APPLE__) |
| | | #include <string.h> |
| | |
| | | #pragma once |
| | | #include <algorithm> |
| | | #ifdef _WIN32 |
| | | #include <codecvt> |
| | | #endif |
| | | |
| | | namespace funasr { |
| | | typedef struct |
| | | { |
| | | std::string msg=""; |
| | | std::string stamp=""; |
| | | std::string tpass_msg=""; |
| | | float snippet_time=0; |
| | | std::string msg; |
| | | std::string stamp; |
| | | std::string tpass_msg; |
| | | float snippet_time; |
| | | }FUNASR_RECOG_RESULT; |
| | | |
| | | typedef struct |
| | | { |
| | | std::vector<std::vector<int>>* segments; |
| | | float snippet_time=0; |
| | | float snippet_time; |
| | | }FUNASR_VAD_RESULT; |
| | | |
| | | typedef struct |
| | | { |
| | | string msg=""; |
| | | string msg; |
| | | vector<string> arr_cache; |
| | | }FUNASR_PUNC_RESULT; |
| | | |
| | | #ifdef _WIN32 |
| | | #include <codecvt> |
| | | |
| | | #define ORTSTRING(str) StrToWstr(str) |
| | | #define ORTCHAR(str) StrToWstr(str).c_str() |
| | | |
| | | inline std::wstring String2wstring(const std::string& str, const std::string& locale) |
| | | { |
| | |
| | | |
| | | } |
| | | |
| | | #else |
| | | |
| | | #define ORTSTRING(str) str |
| | | #define ORTCHAR(str) str |
| | | |
| | | #endif |
| | | |
| | | |
| | | |
| | | inline void GetInputName(Ort::Session* session, string& inputName,int nIndex=0) { |
| | | size_t numInputNodes = session->GetInputCount(); |
| | | if (numInputNodes > 0) { |
| | |
| | | session_options.DisableCpuMemArena(); |
| | | |
| | | try{ |
| | | m_session = std::make_unique<Ort::Session>(env_, punc_model.c_str(), session_options); |
| | | m_session = std::make_unique<Ort::Session>(env_, ORTSTRING(punc_model).c_str(), session_options); |
| | | LOG(INFO) << "Successfully load model from " << punc_model; |
| | | } |
| | | catch (std::exception const &e) { |
| | |
| | | for (size_t i = 0; i < InputData.size(); i += TOKEN_LEN) |
| | | { |
| | | nDiff = (i + TOKEN_LEN) < InputData.size() ? (0) : (i + TOKEN_LEN - InputData.size()); |
| | | vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + TOKEN_LEN - nDiff); |
| | | vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + TOKEN_LEN - nDiff); |
| | | vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + (TOKEN_LEN - nDiff)); |
| | | vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + (TOKEN_LEN - nDiff)); |
| | | InputIDs.insert(InputIDs.begin(), RemainIDs.begin(), RemainIDs.end()); // RemainIDs+InputIDs; |
| | | InputStr.insert(InputStr.begin(), RemainStr.begin(), RemainStr.end()); // RemainStr+InputStr; |
| | | |
| | |
| | | nSentEnd = nLastCommaIndex; |
| | | Punction[nSentEnd] = PERIOD_INDEX; |
| | | } |
| | | RemainStr.assign(InputStr.begin() + nSentEnd + 1, InputStr.end()); |
| | | RemainIDs.assign(InputIDs.begin() + nSentEnd + 1, InputIDs.end()); |
| | | InputStr.assign(InputStr.begin(), InputStr.begin() + nSentEnd + 1); // minit_sentence |
| | | Punction.assign(Punction.begin(), Punction.begin() + nSentEnd + 1); |
| | | RemainStr.assign(InputStr.begin() + (nSentEnd + 1), InputStr.end()); |
| | | RemainIDs.assign(InputIDs.begin() + (nSentEnd + 1), InputIDs.end()); |
| | | InputStr.assign(InputStr.begin(), InputStr.begin() + (nSentEnd + 1)); // minit_sentence |
| | | Punction.assign(Punction.begin(), Punction.begin() + (nSentEnd + 1)); |
| | | } |
| | | |
| | | for (auto& item : Punction) |
| | |
| | | break; |
| | | } |
| | | } |
| | | arr_cache.assign(sentence_words_list.begin() + nSentEnd + 1, sentence_words_list.end()); |
| | | arr_cache.assign(sentence_words_list.begin() + (nSentEnd + 1), sentence_words_list.end()); |
| | | |
| | | if (sentenceOut.size() > 0 && m_tokenizer.IsPunc(sentenceOut[sentenceOut.size() - 1])) |
| | | { |
| | |
| | | session_options.DisableCpuMemArena(); |
| | | |
| | | try{ |
| | | m_session = std::make_unique<Ort::Session>(env_, punc_model.c_str(), session_options); |
| | | m_session = std::make_unique<Ort::Session>(env_, ORTSTRING(punc_model).c_str(), session_options); |
| | | LOG(INFO) << "Successfully load model from " << punc_model; |
| | | } |
| | | catch (std::exception const &e) { |
| | |
| | | for (size_t i = 0; i < InputData.size(); i += TOKEN_LEN) |
| | | { |
| | | nDiff = (i + TOKEN_LEN) < InputData.size() ? (0) : (i + TOKEN_LEN - InputData.size()); |
| | | vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + TOKEN_LEN - nDiff); |
| | | vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + TOKEN_LEN - nDiff); |
| | | vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + (TOKEN_LEN - nDiff)); |
| | | vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + (TOKEN_LEN - nDiff)); |
| | | InputIDs.insert(InputIDs.begin(), RemainIDs.begin(), RemainIDs.end()); // RemainIDs+InputIDs; |
| | | InputStr.insert(InputStr.begin(), RemainStr.begin(), RemainStr.end()); // RemainStr+InputStr; |
| | | |
| | |
| | | nSentEnd = nLastCommaIndex; |
| | | Punction[nSentEnd] = PERIOD_INDEX; |
| | | } |
| | | RemainStr.assign(InputStr.begin() + nSentEnd + 1, InputStr.end()); |
| | | RemainIDs.assign(InputIDs.begin() + nSentEnd + 1, InputIDs.end()); |
| | | InputStr.assign(InputStr.begin(), InputStr.begin() + nSentEnd + 1); // minit_sentence |
| | | Punction.assign(Punction.begin(), Punction.begin() + nSentEnd + 1); |
| | | RemainStr.assign(InputStr.begin() + (nSentEnd + 1), InputStr.end()); |
| | | RemainIDs.assign(InputIDs.begin() + (nSentEnd + 1), InputIDs.end()); |
| | | InputStr.assign(InputStr.begin(), InputStr.begin() + (nSentEnd + 1)); // minit_sentence |
| | | Punction.assign(Punction.begin(), Punction.begin() + (nSentEnd + 1)); |
| | | } |
| | | |
| | | NewPunctuation.insert(NewPunctuation.end(), Punction.begin(), Punction.end()); |
| | |
| | | void FsmnVad::ReadModel(const char* vad_model) { |
| | | try { |
| | | vad_session_ = std::make_shared<Ort::Session>( |
| | | env_, vad_model, session_options_); |
| | | env_, ORTCHAR(vad_model), session_options_); |
| | | LOG(INFO) << "Successfully load model from " << vad_model; |
| | | } catch (std::exception const &e) { |
| | | LOG(ERROR) << "Error when load vad onnx model: " << e.what(); |
| | |
| | | #include "precomp.h" |
| | | #include <vector> |
| | | #ifdef __cplusplus |
| | | |
| | | extern "C" { |
| | | #endif |
| | | |
| | | // APIs for Init |
| | | _FUNASRAPI FUNASR_HANDLE FunASRInit(std::map<std::string, std::string>& model_path, int thread_num, ASR_TYPE type) |
| | |
| | | delete tpass_online_stream; |
| | | } |
| | | |
| | | #ifdef __cplusplus |
| | | |
| | | } |
| | | #endif |
| | | |
| | |
| | | #include "precomp.h" |
| | | #include <unistd.h> |
| | | |
| | | namespace funasr { |
| | | OfflineStream::OfflineStream(std::map<std::string, std::string>& model_path, int thread_num) |
| | |
| | | session_options_.DisableCpuMemArena(); |
| | | |
| | | try { |
| | | m_session_ = std::make_unique<Ort::Session>(env_, am_model.c_str(), session_options_); |
| | | m_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(am_model).c_str(), session_options_); |
| | | LOG(INFO) << "Successfully load model from " << am_model; |
| | | } catch (std::exception const &e) { |
| | | LOG(ERROR) << "Error when load am onnx model: " << e.what(); |
| | |
| | | session_options_.DisableCpuMemArena(); |
| | | |
| | | try { |
| | | encoder_session_ = std::make_unique<Ort::Session>(env_, en_model.c_str(), session_options_); |
| | | encoder_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(en_model).c_str(), session_options_); |
| | | LOG(INFO) << "Successfully load model from " << en_model; |
| | | } catch (std::exception const &e) { |
| | | LOG(ERROR) << "Error when load am encoder model: " << e.what(); |
| | |
| | | } |
| | | |
| | | try { |
| | | decoder_session_ = std::make_unique<Ort::Session>(env_, de_model.c_str(), session_options_); |
| | | decoder_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(de_model).c_str(), session_options_); |
| | | LOG(INFO) << "Successfully load model from " << de_model; |
| | | } catch (std::exception const &e) { |
| | | LOG(ERROR) << "Error when load am decoder model: " << e.what(); |
| | |
| | | |
| | | // offline |
| | | try { |
| | | m_session_ = std::make_unique<Ort::Session>(env_, am_model.c_str(), session_options_); |
| | | m_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(am_model).c_str(), session_options_); |
| | | LOG(INFO) << "Successfully load model from " << am_model; |
| | | } catch (std::exception const &e) { |
| | | LOG(ERROR) << "Error when load am onnx model: " << e.what(); |
| | |
| | | hw_session_options.DisableCpuMemArena(); |
| | | |
| | | try { |
| | | hw_m_session = std::make_unique<Ort::Session>(hw_env_, hw_model.c_str(), hw_session_options); |
| | | hw_m_session = std::make_unique<Ort::Session>(hw_env_, ORTSTRING(hw_model).c_str(), hw_session_options); |
| | | LOG(INFO) << "Successfully load model from " << hw_model; |
| | | } catch (std::exception const &e) { |
| | | LOG(ERROR) << "Error when load hw compiler onnx model: " << e.what(); |
| | |
| | | #include <numeric> |
| | | #include <cstring> |
| | | |
| | | #ifdef _WIN32 |
| | | #include<io.h> |
| | | #ifndef R_OK |
| | | #define R_OK 4 |
| | | #endif |
| | | #ifndef W_OK |
| | | #define W_OK 2 |
| | | #endif |
| | | #ifndef X_OK |
| | | #define X_OK 0 |
| | | #endif |
| | | #ifndef F_OK |
| | | #define F_OK 0 |
| | | #endif |
| | | #define access _access |
| | | #else |
| | | #include <unistd.h> |
| | | #endif |
| | | |
| | | using namespace std; |
| | | // third part |
| | | #if defined(__APPLE__) |
| | |
| | | |
| | | // mine |
| | | #include <glog/logging.h> |
| | | |
| | | |
| | | #include "common-struct.h" |
| | | #include "com-define.h" |
| | | #include "commonfunc.h" |
| | |
| | | #include "precomp.h" |
| | | #include <unistd.h> |
| | | |
| | | namespace funasr { |
| | | TpassOnlineStream::TpassOnlineStream(TpassStream* tpass_stream, std::vector<int> chunk_size){ |
| | |
| | | #include "precomp.h" |
| | | #include <unistd.h> |
| | | |
| | | namespace funasr { |
| | | TpassStream::TpassStream(std::map<std::string, std::string>& model_path, int thread_num) |