Skip to content

Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.

add funasr namespace

lyblsgo1799f356dff6
diff --git a/funasr/runtime/onnxruntime/src/alignedmem.cpp b/funasr/runtime/onnxruntime/src/alignedmem.cpp
index d3e4b8202..9c7d323df 100644
--- a/funasr/runtime/onnxruntime/src/alignedmem.cpp
+++ b/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 @@ void AlignedFree(void *p)
{
free(((void **)p)[-1]);
}
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/alignedmem.h b/funasr/runtime/onnxruntime/src/alignedmem.h
index e2b640a97..e4b9a7892 100644
--- a/funasr/runtime/onnxruntime/src/alignedmem.h
+++ b/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
diff --git a/funasr/runtime/onnxruntime/src/audio.cpp b/funasr/runtime/onnxruntime/src/audio.cpp
index 2ecd3e63c..6d63d6757 100644
--- a/funasr/runtime/onnxruntime/src/audio.cpp
+++ b/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 {
@@ -552,4 +553,6 @@ void Audio::Split(VadModel* vad_obj, vector<std::vector<int>>& vad_segments)
std::vector<float> pcm_data(speech_data, speech_data+sp_len);
vad_segments = vad_obj->Infer(pcm_data);
-}
\ No newline at end of file
+}
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/commonfunc.h b/funasr/runtime/onnxruntime/src/commonfunc.h
index d5298c31c..d0882c6a9 100644
--- a/funasr/runtime/onnxruntime/src/commonfunc.h
+++ b/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 @@ template <class ForwardIterator>
inline static size_t Argmax(ForwardIterator first, ForwardIterator last) {
return std::distance(first, std::max_element(first, last));
}
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/ct-transformer.cpp b/funasr/runtime/onnxruntime/src/ct-transformer.cpp
index 91e795c45..38a5a70a9 100644
--- a/funasr/runtime/onnxruntime/src/ct-transformer.cpp
+++ b/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 @@ vector<int> CTTransformer::Infer(vector<int32_t> input_data)
return punction;
}
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/ct-transformer.h b/funasr/runtime/onnxruntime/src/ct-transformer.h
index cff4f4747..49ed1b7bf 100644
--- a/funasr/runtime/onnxruntime/src/ct-transformer.h
+++ b/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 @@ public:
vector<int> Infer(vector<int32_t> input_data);
string AddPunc(const char* sz_input);
};
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/e2e-vad.h b/funasr/runtime/onnxruntime/src/e2e-vad.h
index d881a322e..e9a8293ef 100644
--- a/funasr/runtime/onnxruntime/src/e2e-vad.h
+++ b/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 @@ private:
};
-
-
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/fsmn-vad.cpp b/funasr/runtime/onnxruntime/src/fsmn-vad.cpp
index b1b0e639c..0a646f0ca 100644
--- a/funasr/runtime/onnxruntime/src/fsmn-vad.cpp
+++ b/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() {
FsmnVad::FsmnVad():env_(ORT_LOGGING_LEVEL_ERROR, ""),session_options_{} {
}
+
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/fsmn-vad.h b/funasr/runtime/onnxruntime/src/fsmn-vad.h
index cf03ce91a..7a6707c4d 100644
--- a/funasr/runtime/onnxruntime/src/fsmn-vad.h
+++ b/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 @@ private:
int lfr_n = VAD_LFR_N;
};
-
+} // namespace funasr
#endif //VAD_SERVER_FSMNVAD_H
diff --git a/funasr/runtime/onnxruntime/src/funasrruntime.cpp b/funasr/runtime/onnxruntime/src/funasrruntime.cpp
index ee6143edf..b8508fd3d 100644
--- a/funasr/runtime/onnxruntime/src/funasrruntime.cpp
+++ b/funasr/runtime/onnxruntime/src/funasrruntime.cpp
@@ -7,44 +7,44 @@ extern "C" {
// 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 @@ extern "C" {
_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 @@ extern "C" {
_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 @@ extern "C" {
_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 @@ extern "C" {
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 @@ extern "C" {
// 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 @@ extern "C" {
// 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 @@ extern "C" {
// 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 @@ extern "C" {
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 @@ extern "C" {
_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 @@ extern "C" {
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 @@ extern "C" {
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 @@ extern "C" {
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 @@ extern "C" {
_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 @@ extern "C" {
{
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 @@ extern "C" {
// 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 @@ extern "C" {
_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 @@ extern "C" {
_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 @@ extern "C" {
_FUNASRAPI void FunOfflineUninit(FUNASR_HANDLE handle)
{
- OfflineStream* offline_stream = (OfflineStream*)handle;
+ funasr::OfflineStream* offline_stream = (funasr::OfflineStream*)handle;
if (!offline_stream)
return;
diff --git a/funasr/runtime/onnxruntime/src/model.cpp b/funasr/runtime/onnxruntime/src/model.cpp
index 65ea172f0..6badde667 100644
--- a/funasr/runtime/onnxruntime/src/model.cpp
+++ b/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 @@ Model *CreateModel(std::map<std::string, std::string>& model_path, int thread_nu
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
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/offline-stream.cpp b/funasr/runtime/onnxruntime/src/offline-stream.cpp
index 00c131844..817012981 100644
--- a/funasr/runtime/onnxruntime/src/offline-stream.cpp
+++ b/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 @@ OfflineStream *CreateOfflineStream(std::map<std::string, std::string>& model_pat
mm = new OfflineStream(model_path, thread_num);
return mm;
}
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/online-feature.cpp b/funasr/runtime/onnxruntime/src/online-feature.cpp
index 3f57e0b9d..c5caf0ae6 100644
--- a/funasr/runtime/onnxruntime/src/online-feature.cpp
+++ b/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 @@ void OnlineFeature::OnlineFbank(vector<std::vector<float>> &vad_feats,
}
}
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/online-feature.h b/funasr/runtime/onnxruntime/src/online-feature.h
index decaaf4e7..7347056de 100644
--- a/funasr/runtime/onnxruntime/src/online-feature.h
+++ b/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 @@ private:
bool input_finished_ = false;
};
+
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/paraformer.cpp b/funasr/runtime/onnxruntime/src/paraformer.cpp
index 244a706db..74366a0fa 100644
--- a/funasr/runtime/onnxruntime/src/paraformer.cpp
+++ b/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 @@ string Paraformer::Rescoring()
LOG(ERROR)<<"Not Imp!!!!!!";
return "";
}
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/paraformer.h b/funasr/runtime/onnxruntime/src/paraformer.h
index 3aa7057e5..533c16fdc 100644
--- a/funasr/runtime/onnxruntime/src/paraformer.h
+++ b/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 @@ namespace paraformer {
string Rescoring();
};
-} // namespace paraformer
-#endif
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/precomp.h b/funasr/runtime/onnxruntime/src/precomp.h
index 9a8b17d69..e607dbff1 100644
--- a/funasr/runtime/onnxruntime/src/precomp.h
+++ b/funasr/runtime/onnxruntime/src/precomp.h
@@ -46,5 +46,3 @@ using namespace std;
#include "paraformer.h"
#include "offline-stream.h"
#include "funasrruntime.h"
-
-using namespace paraformer;
diff --git a/funasr/runtime/onnxruntime/src/predefine-coe.h b/funasr/runtime/onnxruntime/src/predefine-coe.h
index 93012d857..17c263f7b 100644
--- a/funasr/runtime/onnxruntime/src/predefine-coe.h
+++ b/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 @@ const int pos_enc_div_term_hex[] = {
0x39164323, 0x3910f3c6, 0x390bd472, 0x3906e374, 0x39021f2b, 0x38fb0c03,
0x38f22ce3, 0x38e99e04, 0x38e15c92, 0x38d965ce};
#endif
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/punc-model.cpp b/funasr/runtime/onnxruntime/src/punc-model.cpp
index 1e619ab9d..52ba0df90 100644
--- a/funasr/runtime/onnxruntime/src/punc-model.cpp
+++ b/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 @@ PuncModel *CreatePuncModel(std::map<std::string, std::string>& model_path, int t
mm->InitPunc(punc_model_path, punc_config_path, thread_num);
return mm;
}
+
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/resample.cpp b/funasr/runtime/onnxruntime/src/resample.cpp
index 0238752c3..9c74dc886 100644
--- a/funasr/runtime/onnxruntime/src/resample.cpp
+++ b/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 @@ void LinearResample::SetRemainder(const float *input, int32_t input_dim) {
}
}
}
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/resample.h b/funasr/runtime/onnxruntime/src/resample.h
index b9a283ab8..5cfc97196 100644
--- a/funasr/runtime/onnxruntime/src/resample.h
+++ b/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 @@ class LinearResample {
std::vector<float> input_remainder_; ///< A small trailing part of the
///< previously seen input signal.
};
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/tensor.h b/funasr/runtime/onnxruntime/src/tensor.h
index 3b7a63352..a2a7bc366 100644
--- a/funasr/runtime/onnxruntime/src/tensor.h
+++ b/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 @@ template <typename T> void Tensor<T>::dump(const char *mode)
fwrite(buff, 1, buff_size * sizeof(T), fp);
fclose(fp);
}
+
+} // namespace funasr
#endif
diff --git a/funasr/runtime/onnxruntime/src/tokenizer.cpp b/funasr/runtime/onnxruntime/src/tokenizer.cpp
index 5aff058b3..a8f630108 100644
--- a/funasr/runtime/onnxruntime/src/tokenizer.cpp
+++ b/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 @@ void CTokenizer::StrSplit(const string& str, const char split, vector<string>& r
}
id_out= String2Ids(str_out);
}
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/tokenizer.h b/funasr/runtime/onnxruntime/src/tokenizer.h
index 4ddd359e5..419791bf5 100644
--- a/funasr/runtime/onnxruntime/src/tokenizer.h
+++ b/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 @@ public:
void Tokenize(const char* str_info, vector<string>& str_out, vector<int>& id_out);
};
+
+} // namespace funasr
diff --git a/funasr/runtime/onnxruntime/src/util.cpp b/funasr/runtime/onnxruntime/src/util.cpp
index c5c27af7d..d29c5c0f9 100644
--- a/funasr/runtime/onnxruntime/src/util.cpp
+++ b/funasr/runtime/onnxruntime/src/util.cpp
@@ -1,6 +1,7 @@
#include "precomp.h"
+namespace funasr {
float *LoadParams(const char *filename)
{
@@ -178,3 +179,5 @@ void Glu(Tensor<float> *din, Tensor<float> *dout)
}
}
}
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/util.h b/funasr/runtime/onnxruntime/src/util.h
index 6327f7b4b..95ef4586a 100644
--- a/funasr/runtime/onnxruntime/src/util.h
+++ b/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 @@ extern void Glu(Tensor<float> *din, Tensor<float> *dout);
string PathAppend(const string &p1, const string &p2);
+} // namespace funasr
#endif
diff --git a/funasr/runtime/onnxruntime/src/vad-model.cpp b/funasr/runtime/onnxruntime/src/vad-model.cpp
index 0a0ec84eb..764db00c9 100644
--- a/funasr/runtime/onnxruntime/src/vad-model.cpp
+++ b/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 @@ VadModel *CreateVadModel(std::map<std::string, std::string>& model_path, int thr
mm->InitVad(vad_model_path, vad_cmvn_path, vad_config_path, thread_num);
return mm;
}
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/vocab.cpp b/funasr/runtime/onnxruntime/src/vocab.cpp
index 53233b341..65af8b6f5 100644
--- a/funasr/runtime/onnxruntime/src/vocab.cpp
+++ b/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 @@ int Vocab::Size()
{
return vocab.size();
}
+
+} // namespace funasr
\ No newline at end of file
diff --git a/funasr/runtime/onnxruntime/src/vocab.h b/funasr/runtime/onnxruntime/src/vocab.h
index a3fdf654a..6c4e52354 100644
--- a/funasr/runtime/onnxruntime/src/vocab.h
+++ b/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 @@ class Vocab {
string Vector2StringV2(vector<int> in);
};
+} // namespace funasr
#endif