cdevelop
2023-10-11 3bb14b5029becec85034f88dd66ca2d027134072
解决vc编译错误 (#987)

12个文件已修改
109 ■■■■■ 已修改文件
funasr/runtime/onnxruntime/include/funasrruntime.h 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/audio.cpp 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/commonfunc.h 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/ct-transformer-online.cpp 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/ct-transformer.cpp 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/fsmn-vad.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/funasrruntime.cpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/offline-stream.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/paraformer.cpp 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/precomp.h 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/tpass-online-stream.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/src/tpass-stream.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/onnxruntime/include/funasrruntime.h
@@ -18,10 +18,6 @@
#define FUNASR_CALLBCK_PREFIX __stdcall
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef void* FUNASR_HANDLE;
typedef void* FUNASR_RESULT;
@@ -122,7 +118,4 @@
_FUNASRAPI void                FunTpassUninit(FUNASR_HANDLE handle);
_FUNASRAPI void                FunTpassOnlineUninit(FUNASR_HANDLE handle);
#ifdef __cplusplus
}
#endif
funasr/runtime/onnxruntime/src/audio.cpp
@@ -9,6 +9,9 @@
#include "audio.h"
#include "precomp.h"
#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif
#if defined(__APPLE__)
#include <string.h>
funasr/runtime/onnxruntime/src/commonfunc.h
@@ -1,29 +1,34 @@
#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)
{
@@ -39,8 +44,15 @@
}
#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) {
funasr/runtime/onnxruntime/src/ct-transformer-online.cpp
@@ -17,7 +17,7 @@
    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) {
@@ -74,8 +74,8 @@
    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;
@@ -102,10 +102,10 @@
                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)  
@@ -149,7 +149,7 @@
            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]))
    {
funasr/runtime/onnxruntime/src/ct-transformer.cpp
@@ -17,7 +17,7 @@
    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) {
@@ -66,8 +66,8 @@
    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;
@@ -94,10 +94,10 @@
                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());
funasr/runtime/onnxruntime/src/fsmn-vad.cpp
@@ -54,7 +54,7 @@
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();
funasr/runtime/onnxruntime/src/funasrruntime.cpp
@@ -1,9 +1,6 @@
#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)
@@ -694,8 +691,4 @@
        delete tpass_online_stream;
    }
#ifdef __cplusplus
}
#endif
funasr/runtime/onnxruntime/src/offline-stream.cpp
@@ -1,5 +1,4 @@
#include "precomp.h"
#include <unistd.h>
namespace funasr {
OfflineStream::OfflineStream(std::map<std::string, std::string>& model_path, int thread_num)
funasr/runtime/onnxruntime/src/paraformer.cpp
@@ -37,7 +37,7 @@
    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();
@@ -90,7 +90,7 @@
    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();
@@ -98,7 +98,7 @@
    }
    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();
@@ -153,7 +153,7 @@
    // 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();
@@ -250,7 +250,7 @@
    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();
funasr/runtime/onnxruntime/src/precomp.h
@@ -17,6 +17,25 @@
#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__)
@@ -33,6 +52,8 @@
// mine
#include <glog/logging.h>
#include "common-struct.h"
#include "com-define.h"
#include "commonfunc.h"
funasr/runtime/onnxruntime/src/tpass-online-stream.cpp
@@ -1,5 +1,4 @@
#include "precomp.h"
#include <unistd.h>
namespace funasr {
TpassOnlineStream::TpassOnlineStream(TpassStream* tpass_stream, std::vector<int> chunk_size){
funasr/runtime/onnxruntime/src/tpass-stream.cpp
@@ -1,5 +1,4 @@
#include "precomp.h"
#include <unistd.h>
namespace funasr {
TpassStream::TpassStream(std::map<std::string, std::string>& model_path, int thread_num)