mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
解决vc编译错误 (#987)
This commit is contained in:
parent
7529416cea
commit
3bb14b5029
@ -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 FUNASR_RESULT FunTpassInferBuffer(FUNASR_HANDLE handle, FUNASR_HANDLE
|
||||
_FUNASRAPI void FunTpassUninit(FUNASR_HANDLE handle);
|
||||
_FUNASRAPI void FunTpassOnlineUninit(FUNASR_HANDLE handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -9,6 +9,9 @@
|
||||
#include "audio.h"
|
||||
#include "precomp.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <string.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 @@ inline std::wstring StrToWstr(std::string str) {
|
||||
|
||||
}
|
||||
|
||||
#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) {
|
||||
|
||||
@ -17,7 +17,7 @@ void CTTransformerOnline::InitPunc(const std::string &punc_model, const std::str
|
||||
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 @@ string CTTransformerOnline::AddPunc(const char* sz_input, vector<string> &arr_ca
|
||||
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 @@ string CTTransformerOnline::AddPunc(const char* sz_input, vector<string> &arr_ca
|
||||
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 @@ string CTTransformerOnline::AddPunc(const char* sz_input, vector<string> &arr_ca
|
||||
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]))
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@ void CTTransformer::InitPunc(const std::string &punc_model, const std::string &p
|
||||
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 @@ string CTTransformer::AddPunc(const char* sz_input, std::string language)
|
||||
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 @@ string CTTransformer::AddPunc(const char* sz_input, std::string language)
|
||||
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());
|
||||
|
||||
@ -54,7 +54,7 @@ void FsmnVad::LoadConfigFromYaml(const char* filename){
|
||||
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();
|
||||
|
||||
@ -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 @@ extern "C" {
|
||||
delete tpass_online_stream;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -37,7 +37,7 @@ void Paraformer::InitAsr(const std::string &am_model, const std::string &am_cmvn
|
||||
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 @@ void Paraformer::InitAsr(const std::string &en_model, const std::string &de_mode
|
||||
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 @@ void Paraformer::InitAsr(const std::string &en_model, const std::string &de_mode
|
||||
}
|
||||
|
||||
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 @@ void Paraformer::InitAsr(const std::string &am_model, const std::string &en_mode
|
||||
|
||||
// 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 @@ void Paraformer::InitHwCompiler(const std::string &hw_model, int thread_num) {
|
||||
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();
|
||||
|
||||
@ -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 @@ using namespace std;
|
||||
|
||||
// mine
|
||||
#include <glog/logging.h>
|
||||
|
||||
|
||||
#include "common-struct.h"
|
||||
#include "com-define.h"
|
||||
#include "commonfunc.h"
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include "precomp.h"
|
||||
#include <unistd.h>
|
||||
|
||||
namespace funasr {
|
||||
TpassOnlineStream::TpassOnlineStream(TpassStream* tpass_stream, std::vector<int> chunk_size){
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user