Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
解决vc编译错误 (#987)
cdevelop3bb14b5029be
diff --git a/funasr/runtime/onnxruntime/include/funasrruntime.h b/funasr/runtime/onnxruntime/include/funasrruntime.hindex 14f6122dd..3b5ae8f0d 100644--- a/funasr/runtime/onnxruntime/include/funasrruntime.h+++ b/funasr/runtime/onnxruntime/include/funasrruntime.h@@ -18,10 +18,6 @@#define FUNASR_CALLBCK_PREFIX __stdcall#endif-#ifdef __cplusplus--extern "C" {-#endiftypedef 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-}-#endifdiff --git a/funasr/runtime/onnxruntime/src/audio.cpp b/funasr/runtime/onnxruntime/src/audio.cppindex d62151e91..1eafa3f59 100644--- a/funasr/runtime/onnxruntime/src/audio.cpp+++ b/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>diff --git a/funasr/runtime/onnxruntime/src/commonfunc.h b/funasr/runtime/onnxruntime/src/commonfunc.hindex d7e5f1379..9bd2a0011 100644--- a/funasr/runtime/onnxruntime/src/commonfunc.h+++ b/funasr/runtime/onnxruntime/src/commonfunc.h@@ -1,29 +1,34 @@#pragma once#include <algorithm>+#ifdef _WIN32+#include <codecvt>+#endifnamespace 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) {diff --git a/funasr/runtime/onnxruntime/src/ct-transformer-online.cpp b/funasr/runtime/onnxruntime/src/ct-transformer-online.cppindex 51f2a6a78..21986678d 100644--- a/funasr/runtime/onnxruntime/src/ct-transformer-online.cpp+++ b/funasr/runtime/onnxruntime/src/ct-transformer-online.cpp@@ -17,7 +17,7 @@ void CTTransformerOnline::InitPunc(const std::string &punc_model, const std::strsession_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_cafor (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_canSentEnd = 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_cabreak;}}- 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])){diff --git a/funasr/runtime/onnxruntime/src/ct-transformer.cpp b/funasr/runtime/onnxruntime/src/ct-transformer.cppindex 64a70da94..71a8847c4 100644--- a/funasr/runtime/onnxruntime/src/ct-transformer.cpp+++ b/funasr/runtime/onnxruntime/src/ct-transformer.cpp@@ -17,7 +17,7 @@ void CTTransformer::InitPunc(const std::string &punc_model, const std::string &psession_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());diff --git a/funasr/runtime/onnxruntime/src/fsmn-vad.cpp b/funasr/runtime/onnxruntime/src/fsmn-vad.cppindex fb79ad747..db633b0b2 100644--- a/funasr/runtime/onnxruntime/src/fsmn-vad.cpp+++ b/funasr/runtime/onnxruntime/src/fsmn-vad.cpp@@ -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();diff --git a/funasr/runtime/onnxruntime/src/funasrruntime.cpp b/funasr/runtime/onnxruntime/src/funasrruntime.cppindex 150be704b..91ef18893 100644--- a/funasr/runtime/onnxruntime/src/funasrruntime.cpp+++ b/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 @@ extern "C" {delete tpass_online_stream;}-#ifdef __cplusplus--}-#endifdiff --git a/funasr/runtime/onnxruntime/src/offline-stream.cpp b/funasr/runtime/onnxruntime/src/offline-stream.cppindex 50d01881a..caea72e7f 100644--- a/funasr/runtime/onnxruntime/src/offline-stream.cpp+++ b/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)diff --git a/funasr/runtime/onnxruntime/src/paraformer.cpp b/funasr/runtime/onnxruntime/src/paraformer.cppindex a2dd038d3..5bbaeef4c 100644--- a/funasr/runtime/onnxruntime/src/paraformer.cpp+++ b/funasr/runtime/onnxruntime/src/paraformer.cpp@@ -37,7 +37,7 @@ void Paraformer::InitAsr(const std::string &am_model, const std::string &am_cmvnsession_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_modesession_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// offlinetry {- 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();diff --git a/funasr/runtime/onnxruntime/src/precomp.h b/funasr/runtime/onnxruntime/src/precomp.hindex 59e594e39..5c49fd6a5 100644--- a/funasr/runtime/onnxruntime/src/precomp.h+++ b/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 @@ using namespace std;// mine#include <glog/logging.h>++#include "common-struct.h"#include "com-define.h"#include "commonfunc.h"diff --git a/funasr/runtime/onnxruntime/src/tpass-online-stream.cpp b/funasr/runtime/onnxruntime/src/tpass-online-stream.cppindex 832cfd198..7788e0b12 100644--- a/funasr/runtime/onnxruntime/src/tpass-online-stream.cpp+++ b/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){diff --git a/funasr/runtime/onnxruntime/src/tpass-stream.cpp b/funasr/runtime/onnxruntime/src/tpass-stream.cppindex 47734afc8..a3e1b0eb3 100644--- a/funasr/runtime/onnxruntime/src/tpass-stream.cpp+++ b/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)