Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2024-11-26 18:36:56 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-11-26 18:36:56 +0800
Commit
210122726912db22456f1d6cac96cf54971176ce
21012272
1 parent
298b6b6f
Add streaming ASR support for HarmonyOS. (#1565)
隐藏空白字符变更
内嵌
并排对比
正在显示
35 个修改的文件
包含
367 行增加
和
206 行删除
sherpa-onnx/c-api/c-api.cc
sherpa-onnx/c-api/c-api.h
sherpa-onnx/csrc/offline-recognizer-impl.cc
sherpa-onnx/csrc/online-conformer-transducer-model.cc
sherpa-onnx/csrc/online-conformer-transducer-model.h
sherpa-onnx/csrc/online-ctc-model.cc
sherpa-onnx/csrc/online-ctc-model.h
sherpa-onnx/csrc/online-lstm-transducer-model.cc
sherpa-onnx/csrc/online-lstm-transducer-model.h
sherpa-onnx/csrc/online-nemo-ctc-model.cc
sherpa-onnx/csrc/online-nemo-ctc-model.h
sherpa-onnx/csrc/online-paraformer-model.cc
sherpa-onnx/csrc/online-paraformer-model.h
sherpa-onnx/csrc/online-recognizer-ctc-impl.h
sherpa-onnx/csrc/online-recognizer-impl.cc
sherpa-onnx/csrc/online-recognizer-impl.h
sherpa-onnx/csrc/online-recognizer-paraformer-impl.h
sherpa-onnx/csrc/online-recognizer-transducer-impl.h
sherpa-onnx/csrc/online-recognizer-transducer-nemo-impl.h
sherpa-onnx/csrc/online-recognizer.cc
sherpa-onnx/csrc/online-recognizer.h
sherpa-onnx/csrc/online-transducer-model.cc
sherpa-onnx/csrc/online-transducer-model.h
sherpa-onnx/csrc/online-transducer-nemo-model.cc
sherpa-onnx/csrc/online-transducer-nemo-model.h
sherpa-onnx/csrc/online-wenet-ctc-model.cc
sherpa-onnx/csrc/online-wenet-ctc-model.h
sherpa-onnx/csrc/online-zipformer-transducer-model.cc
sherpa-onnx/csrc/online-zipformer-transducer-model.h
sherpa-onnx/csrc/online-zipformer2-ctc-model.cc
sherpa-onnx/csrc/online-zipformer2-ctc-model.h
sherpa-onnx/csrc/online-zipformer2-transducer-model.cc
sherpa-onnx/csrc/online-zipformer2-transducer-model.h
sherpa-onnx/csrc/symbol-table.cc
sherpa-onnx/python/csrc/vad-model.cc
sherpa-onnx/c-api/c-api.cc
查看文件 @
2101227
...
...
@@ -56,7 +56,7 @@ struct SherpaOnnxDisplay {
#define SHERPA_ONNX_OR(x, y) (x ? x : y)
const
SherpaOnnxOnlineRecognizer
*
SherpaOnnxCreateOnlineRecognizer
(
static
sherpa_onnx
::
OnlineRecognizerConfig
GetOnlineRecognizerConfig
(
const
SherpaOnnxOnlineRecognizerConfig
*
config
)
{
sherpa_onnx
::
OnlineRecognizerConfig
recognizer_config
;
...
...
@@ -151,9 +151,21 @@ const SherpaOnnxOnlineRecognizer *SherpaOnnxCreateOnlineRecognizer(
recognizer_config
.
rule_fars
=
SHERPA_ONNX_OR
(
config
->
rule_fars
,
""
);
if
(
config
->
model_config
.
debug
)
{
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
recognizer_config
.
ToString
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
recognizer_config
.
ToString
().
c_str
());
#endif
}
return
recognizer_config
;
}
const
SherpaOnnxOnlineRecognizer
*
SherpaOnnxCreateOnlineRecognizer
(
const
SherpaOnnxOnlineRecognizerConfig
*
config
)
{
sherpa_onnx
::
OnlineRecognizerConfig
recognizer_config
=
GetOnlineRecognizerConfig
(
config
);
if
(
!
recognizer_config
.
Validate
())
{
SHERPA_ONNX_LOGE
(
"Errors in config!"
);
return
nullptr
;
...
...
@@ -1876,6 +1888,20 @@ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
#ifdef __OHOS__
const
SherpaOnnxOnlineRecognizer
*
SherpaOnnxCreateOnlineRecognizerOHOS
(
const
SherpaOnnxOnlineRecognizerConfig
*
config
,
NativeResourceManager
*
mgr
)
{
sherpa_onnx
::
OnlineRecognizerConfig
recognizer_config
=
GetOnlineRecognizerConfig
(
config
);
SherpaOnnxOnlineRecognizer
*
recognizer
=
new
SherpaOnnxOnlineRecognizer
;
recognizer
->
impl
=
std
::
make_unique
<
sherpa_onnx
::
OnlineRecognizer
>
(
mgr
,
recognizer_config
);
return
recognizer
;
}
const
SherpaOnnxOfflineRecognizer
*
SherpaOnnxCreateOfflineRecognizerOHOS
(
const
SherpaOnnxOfflineRecognizerConfig
*
config
,
NativeResourceManager
*
mgr
)
{
...
...
sherpa-onnx/c-api/c-api.h
查看文件 @
2101227
...
...
@@ -1529,6 +1529,13 @@ typedef struct NativeResourceManager NativeResourceManager;
/// @param config Config for the recognizer.
/// @return Return a pointer to the recognizer. The user has to invoke
// SherpaOnnxDestroyOnlineRecognizer() to free it to avoid memory leak.
SHERPA_ONNX_API
const
SherpaOnnxOnlineRecognizer
*
SherpaOnnxCreateOnlineRecognizerOHOS
(
const
SherpaOnnxOnlineRecognizerConfig
*
config
,
NativeResourceManager
*
mgr
);
/// @param config Config for the recognizer.
/// @return Return a pointer to the recognizer. The user has to invoke
// SherpaOnnxDestroyOfflineRecognizer() to free it to avoid memory
// leak.
SHERPA_ONNX_API
const
SherpaOnnxOfflineRecognizer
*
...
...
sherpa-onnx/csrc/offline-recognizer-impl.cc
查看文件 @
2101227
...
...
@@ -5,17 +5,17 @@
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
#include <string>
#include <strstream>
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include <strstream>
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#elif __OHOS__
#include <strstream>
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
...
...
sherpa-onnx/csrc/online-conformer-transducer-model.cc
查看文件 @
2101227
...
...
@@ -17,6 +17,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
...
...
@@ -50,9 +54,9 @@ OnlineConformerTransducerModel::OnlineConformerTransducerModel(
}
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OnlineConformerTransducerModel
::
OnlineConformerTransducerModel
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
env_
(
ORT_LOGGING_LEVEL_ERROR
),
config_
(
config
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -72,7 +76,6 @@ OnlineConformerTransducerModel::OnlineConformerTransducerModel(
InitJoiner
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
void
OnlineConformerTransducerModel
::
InitEncoder
(
void
*
model_data
,
size_t
model_data_length
)
{
...
...
@@ -91,7 +94,11 @@ void OnlineConformerTransducerModel::InitEncoder(void *model_data,
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -121,7 +128,11 @@ void OnlineConformerTransducerModel::InitDecoder(void *model_data,
std
::
ostringstream
os
;
os
<<
"---decoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -273,4 +284,14 @@ Ort::Value OnlineConformerTransducerModel::RunJoiner(Ort::Value encoder_out,
return
std
::
move
(
logit
[
0
]);
}
#if __ANDROID_API__ >= 9
template
OnlineConformerTransducerModel
::
OnlineConformerTransducerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineConformerTransducerModel
::
OnlineConformerTransducerModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-conformer-transducer-model.h
查看文件 @
2101227
...
...
@@ -10,11 +10,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-model-config.h"
#include "sherpa-onnx/csrc/online-transducer-model.h"
...
...
@@ -25,10 +20,8 @@ class OnlineConformerTransducerModel : public OnlineTransducerModel {
public
:
explicit
OnlineConformerTransducerModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineConformerTransducerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineConformerTransducerModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
std
::
vector
<
Ort
::
Value
>
StackStates
(
const
std
::
vector
<
std
::
vector
<
Ort
::
Value
>>
&
states
)
const
override
;
...
...
sherpa-onnx/csrc/online-ctc-model.cc
查看文件 @
2101227
...
...
@@ -9,6 +9,15 @@
#include <sstream>
#include <string>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/online-nemo-ctc-model.h"
#include "sherpa-onnx/csrc/online-wenet-ctc-model.h"
...
...
@@ -31,10 +40,9 @@ std::unique_ptr<OnlineCtcModel> OnlineCtcModel::Create(
}
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
std
::
unique_ptr
<
OnlineCtcModel
>
OnlineCtcModel
::
Create
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
{
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
{
if
(
!
config
.
wenet_ctc
.
model
.
empty
())
{
return
std
::
make_unique
<
OnlineWenetCtcModel
>
(
mgr
,
config
);
}
else
if
(
!
config
.
zipformer2_ctc
.
model
.
empty
())
{
...
...
@@ -46,6 +54,15 @@ std::unique_ptr<OnlineCtcModel> OnlineCtcModel::Create(
exit
(
-
1
);
}
}
#if __ANDROID_API__ >= 9
template
std
::
unique_ptr
<
OnlineCtcModel
>
OnlineCtcModel
::
Create
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
std
::
unique_ptr
<
OnlineCtcModel
>
OnlineCtcModel
::
Create
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-ctc-model.h
查看文件 @
2101227
...
...
@@ -8,11 +8,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-model-config.h"
...
...
@@ -25,10 +20,9 @@ class OnlineCtcModel {
static
std
::
unique_ptr
<
OnlineCtcModel
>
Create
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
static
std
::
unique_ptr
<
OnlineCtcModel
>
Create
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
// Return a list of tensors containing the initial states
virtual
std
::
vector
<
Ort
::
Value
>
GetInitStates
()
const
=
0
;
...
...
sherpa-onnx/csrc/online-lstm-transducer-model.cc
查看文件 @
2101227
...
...
@@ -16,6 +16,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
...
...
@@ -48,9 +52,9 @@ OnlineLstmTransducerModel::OnlineLstmTransducerModel(
}
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OnlineLstmTransducerModel
::
OnlineLstmTransducerModel
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
env_
(
ORT_LOGGING_LEVEL_ERROR
),
config_
(
config
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -70,7 +74,6 @@ OnlineLstmTransducerModel::OnlineLstmTransducerModel(
InitJoiner
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
void
OnlineLstmTransducerModel
::
InitEncoder
(
void
*
model_data
,
size_t
model_data_length
)
{
...
...
@@ -89,7 +92,11 @@ void OnlineLstmTransducerModel::InitEncoder(void *model_data,
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -261,4 +268,14 @@ Ort::Value OnlineLstmTransducerModel::RunJoiner(Ort::Value encoder_out,
return
std
::
move
(
logit
[
0
]);
}
#if __ANDROID_API__ >= 9
template
OnlineLstmTransducerModel
::
OnlineLstmTransducerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineLstmTransducerModel
::
OnlineLstmTransducerModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-lstm-transducer-model.h
查看文件 @
2101227
...
...
@@ -9,11 +9,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-model-config.h"
#include "sherpa-onnx/csrc/online-transducer-model.h"
...
...
@@ -24,10 +19,8 @@ class OnlineLstmTransducerModel : public OnlineTransducerModel {
public
:
explicit
OnlineLstmTransducerModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineLstmTransducerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineLstmTransducerModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
std
::
vector
<
Ort
::
Value
>
StackStates
(
const
std
::
vector
<
std
::
vector
<
Ort
::
Value
>>
&
states
)
const
override
;
...
...
sherpa-onnx/csrc/online-nemo-ctc-model.cc
查看文件 @
2101227
...
...
@@ -13,6 +13,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
...
...
@@ -36,8 +40,8 @@ class OnlineNeMoCtcModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -47,7 +51,6 @@ class OnlineNeMoCtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
x
,
std
::
vector
<
Ort
::
Value
>
states
)
{
...
...
@@ -202,7 +205,11 @@ class OnlineNeMoCtcModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -286,11 +293,10 @@ class OnlineNeMoCtcModel::Impl {
OnlineNeMoCtcModel
::
OnlineNeMoCtcModel
(
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OnlineNeMoCtcModel
::
OnlineNeMoCtcModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OnlineNeMoCtcModel
::
OnlineNeMoCtcModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OnlineNeMoCtcModel
::~
OnlineNeMoCtcModel
()
=
default
;
...
...
@@ -323,4 +329,14 @@ std::vector<std::vector<Ort::Value>> OnlineNeMoCtcModel::UnStackStates(
return
impl_
->
UnStackStates
(
std
::
move
(
states
));
}
#if __ANDROID_API__ >= 9
template
OnlineNeMoCtcModel
::
OnlineNeMoCtcModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineNeMoCtcModel
::
OnlineNeMoCtcModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-nemo-ctc-model.h
查看文件 @
2101227
...
...
@@ -8,11 +8,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-ctc-model.h"
#include "sherpa-onnx/csrc/online-model-config.h"
...
...
@@ -23,9 +18,8 @@ class OnlineNeMoCtcModel : public OnlineCtcModel {
public
:
explicit
OnlineNeMoCtcModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineNeMoCtcModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineNeMoCtcModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
~
OnlineNeMoCtcModel
()
override
;
...
...
sherpa-onnx/csrc/online-paraformer-model.cc
查看文件 @
2101227
...
...
@@ -13,6 +13,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -38,8 +42,8 @@ class OnlineParaformerModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -54,7 +58,6 @@ class OnlineParaformerModel::Impl {
InitDecoder
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
vector
<
Ort
::
Value
>
ForwardEncoder
(
Ort
::
Value
features
,
Ort
::
Value
features_length
)
{
...
...
@@ -123,7 +126,11 @@ class OnlineParaformerModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -191,11 +198,10 @@ class OnlineParaformerModel::Impl {
OnlineParaformerModel
::
OnlineParaformerModel
(
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OnlineParaformerModel
::
OnlineParaformerModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OnlineParaformerModel
::
OnlineParaformerModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OnlineParaformerModel
::~
OnlineParaformerModel
()
=
default
;
...
...
@@ -246,4 +252,14 @@ OrtAllocator *OnlineParaformerModel::Allocator() const {
return
impl_
->
Allocator
();
}
#if __ANDROID_API__ >= 9
template
OnlineParaformerModel
::
OnlineParaformerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineParaformerModel
::
OnlineParaformerModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-paraformer-model.h
查看文件 @
2101227
...
...
@@ -8,11 +8,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-model-config.h"
...
...
@@ -22,9 +17,8 @@ class OnlineParaformerModel {
public
:
explicit
OnlineParaformerModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineParaformerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineParaformerModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
~
OnlineParaformerModel
();
...
...
sherpa-onnx/csrc/online-recognizer-ctc-impl.h
查看文件 @
2101227
...
...
@@ -88,8 +88,8 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
InitDecoder
();
}
#if __ANDROID_API__ >= 9
explicit
OnlineRecognizerCtcImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
explicit
OnlineRecognizerCtcImpl
(
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
:
OnlineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
...
...
@@ -104,7 +104,6 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
InitDecoder
();
}
#endif
std
::
unique_ptr
<
OnlineStream
>
CreateStream
()
const
override
{
auto
stream
=
std
::
make_unique
<
OnlineStream
>
(
config_
.
feat_config
);
...
...
sherpa-onnx/csrc/online-recognizer-impl.cc
查看文件 @
2101227
...
...
@@ -4,15 +4,18 @@
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
#include <strstream>
#include <utility>
#if __ANDROID_API__ >= 9
#include <strstream>
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "fst/extensions/far/far.h"
#include "kaldifst/csrc/kaldi-fst-io.h"
#include "sherpa-onnx/csrc/macros.h"
...
...
@@ -61,9 +64,9 @@ std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
exit
(
-
1
);
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
std
::
unique_ptr
<
OnlineRecognizerImpl
>
OnlineRecognizerImpl
::
Create
(
AAsset
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
{
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
{
if
(
!
config
.
model_config
.
transducer
.
encoder
.
empty
())
{
Ort
::
Env
env
(
ORT_LOGGING_LEVEL_ERROR
);
...
...
@@ -97,7 +100,6 @@ std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
SHERPA_ONNX_LOGE
(
"Please specify a model"
);
exit
(
-
1
);
}
#endif
OnlineRecognizerImpl
::
OnlineRecognizerImpl
(
const
OnlineRecognizerConfig
&
config
)
:
config_
(
config
)
{
...
...
@@ -143,8 +145,8 @@ OnlineRecognizerImpl::OnlineRecognizerImpl(const OnlineRecognizerConfig &config)
}
}
#if __ANDROID_API__ >= 9
OnlineRecognizerImpl
::
OnlineRecognizerImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OnlineRecognizerImpl
::
OnlineRecognizerImpl
(
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
:
config_
(
config
)
{
if
(
!
config
.
rule_fsts
.
empty
())
{
...
...
@@ -189,7 +191,6 @@ OnlineRecognizerImpl::OnlineRecognizerImpl(AAssetManager *mgr,
}
// for (const auto &f : files)
}
// if (!config.rule_fars.empty())
}
#endif
std
::
string
OnlineRecognizerImpl
::
ApplyInverseTextNormalization
(
std
::
string
text
)
const
{
...
...
@@ -202,4 +203,20 @@ std::string OnlineRecognizerImpl::ApplyInverseTextNormalization(
return
text
;
}
#if __ANDROID_API__ >= 9
template
OnlineRecognizerImpl
::
OnlineRecognizerImpl
(
AAssetManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
template
std
::
unique_ptr
<
OnlineRecognizerImpl
>
OnlineRecognizerImpl
::
Create
(
AAssetManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
#endif
#if __OHOS__
template
OnlineRecognizerImpl
::
OnlineRecognizerImpl
(
NativeResourceManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
template
std
::
unique_ptr
<
OnlineRecognizerImpl
>
OnlineRecognizerImpl
::
Create
(
NativeResourceManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-recognizer-impl.h
查看文件 @
2101227
...
...
@@ -9,11 +9,6 @@
#include <string>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "kaldifst/csrc/text-normalizer.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/online-recognizer.h"
...
...
@@ -28,13 +23,12 @@ class OnlineRecognizerImpl {
static
std
::
unique_ptr
<
OnlineRecognizerImpl
>
Create
(
const
OnlineRecognizerConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineRecognizerImpl
(
AAssetManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
template
<
typename
Manager
>
OnlineRecognizerImpl
(
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
template
<
typename
Manager
>
static
std
::
unique_ptr
<
OnlineRecognizerImpl
>
Create
(
AAssetManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
#endif
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
virtual
~
OnlineRecognizerImpl
()
=
default
;
...
...
sherpa-onnx/csrc/online-recognizer-paraformer-impl.h
查看文件 @
2101227
...
...
@@ -120,8 +120,8 @@ class OnlineRecognizerParaformerImpl : public OnlineRecognizerImpl {
config_
.
feat_config
.
normalize_samples
=
false
;
}
#if __ANDROID_API__ >= 9
explicit
OnlineRecognizerParaformerImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
explicit
OnlineRecognizerParaformerImpl
(
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
:
OnlineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
...
...
@@ -138,7 +138,7 @@ class OnlineRecognizerParaformerImpl : public OnlineRecognizerImpl {
// [-32768, 32767], so we set normalize_samples to false
config_
.
feat_config
.
normalize_samples
=
false
;
}
#endif
OnlineRecognizerParaformerImpl
(
const
OnlineRecognizerParaformerImpl
&
)
=
delete
;
...
...
sherpa-onnx/csrc/online-recognizer-transducer-impl.h
查看文件 @
2101227
...
...
@@ -14,11 +14,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/online-lm.h"
...
...
@@ -130,8 +125,8 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
}
}
#if __ANDROID_API__ >= 9
explicit
OnlineRecognizerTransducerImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
explicit
OnlineRecognizerTransducerImpl
(
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
:
OnlineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
...
...
@@ -178,7 +173,6 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
exit
(
-
1
);
}
}
#endif
std
::
unique_ptr
<
OnlineStream
>
CreateStream
()
const
override
{
auto
stream
=
...
...
@@ -429,8 +423,8 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
hotwords_
,
config_
.
hotwords_score
,
boost_scores_
);
}
#if __ANDROID_API__ >= 9
void
InitHotwords
(
AAssetManager
*
mgr
)
{
template
<
typename
Manager
>
void
InitHotwords
(
Manager
*
mgr
)
{
// each line in hotwords_file contains space-separated words
auto
buf
=
ReadFile
(
mgr
,
config_
.
hotwords_file
);
...
...
@@ -452,7 +446,6 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
hotwords_graph_
=
std
::
make_shared
<
ContextGraph
>
(
hotwords_
,
config_
.
hotwords_score
,
boost_scores_
);
}
#endif
void
InitHotwordsFromBufStr
()
{
// each line in hotwords_file contains space-separated words
...
...
sherpa-onnx/csrc/online-recognizer-transducer-nemo-impl.h
查看文件 @
2101227
...
...
@@ -16,11 +16,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
#include "sherpa-onnx/csrc/online-recognizer.h"
...
...
@@ -65,9 +60,9 @@ class OnlineRecognizerTransducerNeMoImpl : public OnlineRecognizerImpl {
PostInit
();
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
explicit
OnlineRecognizerTransducerNeMoImpl
(
AAsset
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
:
OnlineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
symbol_table_
(
mgr
,
config
.
model_config
.
tokens
),
...
...
@@ -85,7 +80,6 @@ class OnlineRecognizerTransducerNeMoImpl : public OnlineRecognizerImpl {
PostInit
();
}
#endif
std
::
unique_ptr
<
OnlineStream
>
CreateStream
()
const
override
{
auto
stream
=
std
::
make_unique
<
OnlineStream
>
(
config_
.
feat_config
);
...
...
sherpa-onnx/csrc/online-recognizer.cc
查看文件 @
2101227
...
...
@@ -13,6 +13,15 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
#include "sherpa-onnx/csrc/text-utils.h"
...
...
@@ -197,11 +206,10 @@ std::string OnlineRecognizerConfig::ToString() const {
OnlineRecognizer
::
OnlineRecognizer
(
const
OnlineRecognizerConfig
&
config
)
:
impl_
(
OnlineRecognizerImpl
::
Create
(
config
))
{}
#if __ANDROID_API__ >= 9
OnlineRecognizer
::
OnlineRecognizer
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OnlineRecognizer
::
OnlineRecognizer
(
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
)
:
impl_
(
OnlineRecognizerImpl
::
Create
(
mgr
,
config
))
{}
#endif
OnlineRecognizer
::~
OnlineRecognizer
()
=
default
;
...
...
@@ -238,4 +246,14 @@ bool OnlineRecognizer::IsEndpoint(OnlineStream *s) const {
void
OnlineRecognizer
::
Reset
(
OnlineStream
*
s
)
const
{
impl_
->
Reset
(
s
);
}
#if __ANDROID_API__ >= 9
template
OnlineRecognizer
::
OnlineRecognizer
(
AAssetManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
#endif
#if __OHOS__
template
OnlineRecognizer
::
OnlineRecognizer
(
NativeResourceManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-recognizer.h
查看文件 @
2101227
...
...
@@ -9,11 +9,6 @@
#include <string>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "sherpa-onnx/csrc/endpoint.h"
#include "sherpa-onnx/csrc/features.h"
#include "sherpa-onnx/csrc/online-ctc-fst-decoder-config.h"
...
...
@@ -149,9 +144,8 @@ class OnlineRecognizer {
public
:
explicit
OnlineRecognizer
(
const
OnlineRecognizerConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineRecognizer
(
AAssetManager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineRecognizer
(
Manager
*
mgr
,
const
OnlineRecognizerConfig
&
config
);
~
OnlineRecognizer
();
...
...
sherpa-onnx/csrc/online-transducer-model.cc
查看文件 @
2101227
...
...
@@ -9,6 +9,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include <algorithm>
#include <memory>
#include <sstream>
...
...
@@ -49,7 +53,11 @@ static ModelType GetModelType(char *model_data, size_t model_data_length,
if
(
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
...
...
@@ -155,9 +163,9 @@ Ort::Value OnlineTransducerModel::BuildDecoderInput(
return
decoder_input
;
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
std
::
unique_ptr
<
OnlineTransducerModel
>
OnlineTransducerModel
::
Create
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
{
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
{
if
(
!
config
.
model_type
.
empty
())
{
const
auto
&
model_type
=
config
.
model_type
;
if
(
model_type
==
"conformer"
)
{
...
...
@@ -195,6 +203,15 @@ std::unique_ptr<OnlineTransducerModel> OnlineTransducerModel::Create(
// unreachable code
return
nullptr
;
}
#if __ANDROID_API__ >= 9
template
std
::
unique_ptr
<
OnlineTransducerModel
>
OnlineTransducerModel
::
Create
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
std
::
unique_ptr
<
OnlineTransducerModel
>
OnlineTransducerModel
::
Create
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-transducer-model.h
查看文件 @
2101227
...
...
@@ -8,11 +8,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/hypothesis.h"
#include "sherpa-onnx/csrc/online-model-config.h"
...
...
@@ -30,10 +25,9 @@ class OnlineTransducerModel {
static
std
::
unique_ptr
<
OnlineTransducerModel
>
Create
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
static
std
::
unique_ptr
<
OnlineTransducerModel
>
Create
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
/** Stack a list of individual states into a batch.
*
...
...
sherpa-onnx/csrc/online-transducer-nemo-model.cc
查看文件 @
2101227
...
...
@@ -20,6 +20,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/online-transducer-decoder.h"
...
...
@@ -54,8 +58,8 @@ class OnlineTransducerNeMoModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -75,7 +79,6 @@ class OnlineTransducerNeMoModel::Impl {
InitJoiner
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
vector
<
Ort
::
Value
>
RunEncoder
(
Ort
::
Value
features
,
std
::
vector
<
Ort
::
Value
>
states
)
{
...
...
@@ -302,7 +305,11 @@ class OnlineTransducerNeMoModel::Impl {
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -460,11 +467,10 @@ OnlineTransducerNeMoModel::OnlineTransducerNeMoModel(
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OnlineTransducerNeMoModel
::
OnlineTransducerNeMoModel
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OnlineTransducerNeMoModel
::~
OnlineTransducerNeMoModel
()
=
default
;
...
...
@@ -528,4 +534,14 @@ std::vector<std::vector<Ort::Value>> OnlineTransducerNeMoModel::UnStackStates(
return
impl_
->
UnStackStates
(
std
::
move
(
states
));
}
#if __ANDROID_API__ >= 9
template
OnlineTransducerNeMoModel
::
OnlineTransducerNeMoModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineTransducerNeMoModel
::
OnlineTransducerNeMoModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-transducer-nemo-model.h
查看文件 @
2101227
...
...
@@ -11,11 +11,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-model-config.h"
...
...
@@ -28,10 +23,8 @@ class OnlineTransducerNeMoModel {
public
:
explicit
OnlineTransducerNeMoModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineTransducerNeMoModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineTransducerNeMoModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
~
OnlineTransducerNeMoModel
();
// A list of 3 tensors:
...
...
sherpa-onnx/csrc/online-wenet-ctc-model.cc
查看文件 @
2101227
...
...
@@ -13,6 +13,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -33,8 +37,8 @@ class OnlineWenetCtcModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -44,7 +48,6 @@ class OnlineWenetCtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
x
,
std
::
vector
<
Ort
::
Value
>
states
)
{
...
...
@@ -139,7 +142,11 @@ class OnlineWenetCtcModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -212,11 +219,10 @@ class OnlineWenetCtcModel::Impl {
OnlineWenetCtcModel
::
OnlineWenetCtcModel
(
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OnlineWenetCtcModel
::
OnlineWenetCtcModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OnlineWenetCtcModel
::
OnlineWenetCtcModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OnlineWenetCtcModel
::~
OnlineWenetCtcModel
()
=
default
;
...
...
@@ -258,4 +264,14 @@ std::vector<std::vector<Ort::Value>> OnlineWenetCtcModel::UnStackStates(
return
ans
;
}
#if __ANDROID_API__ >= 9
template
OnlineWenetCtcModel
::
OnlineWenetCtcModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineWenetCtcModel
::
OnlineWenetCtcModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-wenet-ctc-model.h
查看文件 @
2101227
...
...
@@ -8,11 +8,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-ctc-model.h"
#include "sherpa-onnx/csrc/online-model-config.h"
...
...
@@ -23,9 +18,8 @@ class OnlineWenetCtcModel : public OnlineCtcModel {
public
:
explicit
OnlineWenetCtcModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineWenetCtcModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineWenetCtcModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
~
OnlineWenetCtcModel
()
override
;
...
...
sherpa-onnx/csrc/online-zipformer-transducer-model.cc
查看文件 @
2101227
...
...
@@ -17,6 +17,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
...
...
@@ -50,9 +54,9 @@ OnlineZipformerTransducerModel::OnlineZipformerTransducerModel(
}
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OnlineZipformerTransducerModel
::
OnlineZipformerTransducerModel
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
env_
(
ORT_LOGGING_LEVEL_ERROR
),
config_
(
config
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -72,7 +76,6 @@ OnlineZipformerTransducerModel::OnlineZipformerTransducerModel(
InitJoiner
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
void
OnlineZipformerTransducerModel
::
InitEncoder
(
void
*
model_data
,
size_t
model_data_length
)
{
...
...
@@ -91,7 +94,11 @@ void OnlineZipformerTransducerModel::InitEncoder(void *model_data,
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -480,4 +487,14 @@ Ort::Value OnlineZipformerTransducerModel::RunJoiner(Ort::Value encoder_out,
return
std
::
move
(
logit
[
0
]);
}
#if __ANDROID_API__ >= 9
template
OnlineZipformerTransducerModel
::
OnlineZipformerTransducerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineZipformerTransducerModel
::
OnlineZipformerTransducerModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-zipformer-transducer-model.h
查看文件 @
2101227
...
...
@@ -9,11 +9,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-model-config.h"
#include "sherpa-onnx/csrc/online-transducer-model.h"
...
...
@@ -24,10 +19,8 @@ class OnlineZipformerTransducerModel : public OnlineTransducerModel {
public
:
explicit
OnlineZipformerTransducerModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineZipformerTransducerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineZipformerTransducerModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
std
::
vector
<
Ort
::
Value
>
StackStates
(
const
std
::
vector
<
std
::
vector
<
Ort
::
Value
>>
&
states
)
const
override
;
...
...
sherpa-onnx/csrc/online-zipformer2-ctc-model.cc
查看文件 @
2101227
...
...
@@ -15,6 +15,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
...
...
@@ -37,8 +41,8 @@ class OnlineZipformer2CtcModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -48,7 +52,6 @@ class OnlineZipformer2CtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
features
,
std
::
vector
<
Ort
::
Value
>
states
)
{
...
...
@@ -255,7 +258,11 @@ class OnlineZipformer2CtcModel::Impl {
std
::
ostringstream
os
;
os
<<
"---zipformer2_ctc---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -415,11 +422,10 @@ OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OnlineZipformer2CtcModel
::
OnlineZipformer2CtcModel
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OnlineZipformer2CtcModel
::~
OnlineZipformer2CtcModel
()
=
default
;
...
...
@@ -458,4 +464,14 @@ std::vector<std::vector<Ort::Value>> OnlineZipformer2CtcModel::UnStackStates(
return
impl_
->
UnStackStates
(
std
::
move
(
states
));
}
#if __ANDROID_API__ >= 9
template
OnlineZipformer2CtcModel
::
OnlineZipformer2CtcModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineZipformer2CtcModel
::
OnlineZipformer2CtcModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-zipformer2-ctc-model.h
查看文件 @
2101227
...
...
@@ -8,11 +8,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-ctc-model.h"
#include "sherpa-onnx/csrc/online-model-config.h"
...
...
@@ -23,9 +18,8 @@ class OnlineZipformer2CtcModel : public OnlineCtcModel {
public
:
explicit
OnlineZipformer2CtcModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineZipformer2CtcModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OnlineZipformer2CtcModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
~
OnlineZipformer2CtcModel
()
override
;
...
...
sherpa-onnx/csrc/online-zipformer2-transducer-model.cc
查看文件 @
2101227
...
...
@@ -19,6 +19,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
...
...
@@ -54,9 +58,9 @@ OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
}
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OnlineZipformer2TransducerModel
::
OnlineZipformer2TransducerModel
(
AAsset
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
Manager
*
mgr
,
const
OnlineModelConfig
&
config
)
:
env_
(
ORT_LOGGING_LEVEL_ERROR
),
config_
(
config
),
encoder_sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -78,7 +82,6 @@ OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
InitJoiner
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
void
OnlineZipformer2TransducerModel
::
InitEncoder
(
void
*
model_data
,
size_t
model_data_length
)
{
...
...
@@ -97,7 +100,11 @@ void OnlineZipformer2TransducerModel::InitEncoder(void *model_data,
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -474,4 +481,14 @@ Ort::Value OnlineZipformer2TransducerModel::RunJoiner(Ort::Value encoder_out,
return
std
::
move
(
logit
[
0
]);
}
#if __ANDROID_API__ >= 9
template
OnlineZipformer2TransducerModel
::
OnlineZipformer2TransducerModel
(
AAssetManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
#if __OHOS__
template
OnlineZipformer2TransducerModel
::
OnlineZipformer2TransducerModel
(
NativeResourceManager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/online-zipformer2-transducer-model.h
查看文件 @
2101227
...
...
@@ -9,11 +9,6 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/online-model-config.h"
#include "sherpa-onnx/csrc/online-transducer-model.h"
...
...
@@ -24,10 +19,9 @@ class OnlineZipformer2TransducerModel : public OnlineTransducerModel {
public
:
explicit
OnlineZipformer2TransducerModel
(
const
OnlineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OnlineZipformer2TransducerModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OnlineZipformer2TransducerModel
(
Manager
*
mgr
,
const
OnlineModelConfig
&
config
);
#endif
std
::
vector
<
Ort
::
Value
>
StackStates
(
const
std
::
vector
<
std
::
vector
<
Ort
::
Value
>>
&
states
)
const
override
;
...
...
sherpa-onnx/csrc/symbol-table.cc
查看文件 @
2101227
...
...
@@ -8,16 +8,16 @@
#include <fstream>
#include <sstream>
#include <string>
#include <strstream>
#include <utility>
#if __ANDROID_API__ >= 9
#include <strstream>
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#elif __OHOS__
#include <strstream>
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
...
...
sherpa-onnx/python/csrc/vad-model.cc
查看文件 @
2101227
...
...
@@ -4,6 +4,7 @@
#include "sherpa-onnx/python/csrc/vad-model.h"
#include <memory>
#include <vector>
#include "sherpa-onnx/csrc/vad-model.h"
...
...
@@ -13,8 +14,10 @@ namespace sherpa_onnx {
void
PybindVadModel
(
py
::
module
*
m
)
{
using
PyClass
=
VadModel
;
py
::
class_
<
PyClass
>
(
*
m
,
"VadModel"
)
.
def_static
(
"create"
,
&
PyClass
::
Create
,
py
::
arg
(
"config"
),
py
::
call_guard
<
py
::
gil_scoped_release
>
())
.
def_static
(
"create"
,
(
std
::
unique_ptr
<
VadModel
>
(
*
)(
const
VadModelConfig
&
))(
&
PyClass
::
Create
),
py
::
arg
(
"config"
),
py
::
call_guard
<
py
::
gil_scoped_release
>
())
.
def
(
"reset"
,
&
PyClass
::
Reset
,
py
::
call_guard
<
py
::
gil_scoped_release
>
())
.
def
(
"is_speech"
,
...
...
请
注册
或
登录
后发表评论