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 16:38:35 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-11-26 16:38:35 +0800
Commit
298b6b6fda9b1616b6405a4fc0d7725c1a45fd65
298b6b6f
1 parent
a4b79f07
Add non-streaming ASR support for HarmonyOS. (#1564)
显示空白字符变更
内嵌
并排对比
正在显示
50 个修改的文件
包含
645 行增加
和
451 行删除
sherpa-onnx/c-api/c-api.cc
sherpa-onnx/c-api/c-api.h
sherpa-onnx/c-api/cxx-api.h
sherpa-onnx/csrc/offline-ctc-model.cc
sherpa-onnx/csrc/offline-ctc-model.h
sherpa-onnx/csrc/offline-lm.cc
sherpa-onnx/csrc/offline-lm.h
sherpa-onnx/csrc/offline-moonshine-model.cc
sherpa-onnx/csrc/offline-moonshine-model.h
sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.cc
sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.h
sherpa-onnx/csrc/offline-paraformer-model.cc
sherpa-onnx/csrc/offline-paraformer-model.h
sherpa-onnx/csrc/offline-recognizer-ctc-impl.h
sherpa-onnx/csrc/offline-recognizer-impl.cc
sherpa-onnx/csrc/offline-recognizer-impl.h
sherpa-onnx/csrc/offline-recognizer-moonshine-impl.h
sherpa-onnx/csrc/offline-recognizer-paraformer-impl.h
sherpa-onnx/csrc/offline-recognizer-sense-voice-impl.h
sherpa-onnx/csrc/offline-recognizer-transducer-impl.h
sherpa-onnx/csrc/offline-recognizer-transducer-nemo-impl.h
sherpa-onnx/csrc/offline-recognizer-whisper-impl.h
sherpa-onnx/csrc/offline-recognizer.cc
sherpa-onnx/csrc/offline-recognizer.h
sherpa-onnx/csrc/offline-rnn-lm.cc
sherpa-onnx/csrc/offline-rnn-lm.h
sherpa-onnx/csrc/offline-sense-voice-model.cc
sherpa-onnx/csrc/offline-sense-voice-model.h
sherpa-onnx/csrc/offline-tdnn-ctc-model.cc
sherpa-onnx/csrc/offline-tdnn-ctc-model.h
sherpa-onnx/csrc/offline-telespeech-ctc-model.cc
sherpa-onnx/csrc/offline-telespeech-ctc-model.h
sherpa-onnx/csrc/offline-transducer-model.cc
sherpa-onnx/csrc/offline-transducer-model.h
sherpa-onnx/csrc/offline-transducer-nemo-model.cc
sherpa-onnx/csrc/offline-transducer-nemo-model.h
sherpa-onnx/csrc/offline-wenet-ctc-model.cc
sherpa-onnx/csrc/offline-wenet-ctc-model.h
sherpa-onnx/csrc/offline-whisper-model.cc
sherpa-onnx/csrc/offline-whisper-model.h
sherpa-onnx/csrc/offline-zipformer-ctc-model.cc
sherpa-onnx/csrc/offline-zipformer-ctc-model.h
sherpa-onnx/csrc/silero-vad-model.cc
sherpa-onnx/csrc/silero-vad-model.h
sherpa-onnx/csrc/symbol-table.cc
sherpa-onnx/csrc/symbol-table.h
sherpa-onnx/csrc/vad-model.cc
sherpa-onnx/csrc/vad-model.h
sherpa-onnx/csrc/voice-activity-detector.cc
sherpa-onnx/csrc/voice-activity-detector.h
sherpa-onnx/c-api/c-api.cc
查看文件 @
298b6b6
...
...
@@ -352,27 +352,7 @@ struct SherpaOnnxOfflineStream {
:
impl
(
std
::
move
(
p
))
{}
};
static
sherpa_onnx
::
OfflineRecognizerConfig
convertConfig
(
const
SherpaOnnxOfflineRecognizerConfig
*
config
);
const
SherpaOnnxOfflineRecognizer
*
SherpaOnnxCreateOfflineRecognizer
(
const
SherpaOnnxOfflineRecognizerConfig
*
config
)
{
sherpa_onnx
::
OfflineRecognizerConfig
recognizer_config
=
convertConfig
(
config
);
if
(
!
recognizer_config
.
Validate
())
{
SHERPA_ONNX_LOGE
(
"Errors in config"
);
return
nullptr
;
}
SherpaOnnxOfflineRecognizer
*
recognizer
=
new
SherpaOnnxOfflineRecognizer
;
recognizer
->
impl
=
std
::
make_unique
<
sherpa_onnx
::
OfflineRecognizer
>
(
recognizer_config
);
return
recognizer
;
}
sherpa_onnx
::
OfflineRecognizerConfig
convertConfig
(
static
sherpa_onnx
::
OfflineRecognizerConfig
GetOfflineRecognizerConfig
(
const
SherpaOnnxOfflineRecognizerConfig
*
config
)
{
sherpa_onnx
::
OfflineRecognizerConfig
recognizer_config
;
...
...
@@ -491,17 +471,39 @@ sherpa_onnx::OfflineRecognizerConfig convertConfig(
recognizer_config
.
rule_fars
=
SHERPA_ONNX_OR
(
config
->
rule_fars
,
""
);
if
(
config
->
model_config
.
debug
)
{
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s"
,
recognizer_config
.
ToString
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s"
,
recognizer_config
.
ToString
().
c_str
());
#endif
}
return
recognizer_config
;
}
const
SherpaOnnxOfflineRecognizer
*
SherpaOnnxCreateOfflineRecognizer
(
const
SherpaOnnxOfflineRecognizerConfig
*
config
)
{
sherpa_onnx
::
OfflineRecognizerConfig
recognizer_config
=
GetOfflineRecognizerConfig
(
config
);
if
(
!
recognizer_config
.
Validate
())
{
SHERPA_ONNX_LOGE
(
"Errors in config"
);
return
nullptr
;
}
SherpaOnnxOfflineRecognizer
*
recognizer
=
new
SherpaOnnxOfflineRecognizer
;
recognizer
->
impl
=
std
::
make_unique
<
sherpa_onnx
::
OfflineRecognizer
>
(
recognizer_config
);
return
recognizer
;
}
void
SherpaOnnxOfflineRecognizerSetConfig
(
const
SherpaOnnxOfflineRecognizer
*
recognizer
,
const
SherpaOnnxOfflineRecognizerConfig
*
config
)
{
sherpa_onnx
::
OfflineRecognizerConfig
recognizer_config
=
convert
Config
(
config
);
GetOfflineRecognizer
Config
(
config
);
recognizer
->
impl
->
SetConfig
(
recognizer_config
);
}
...
...
@@ -977,25 +979,6 @@ SherpaOnnxVoiceActivityDetector *SherpaOnnxCreateVoiceActivityDetector(
return
p
;
}
#ifdef __OHOS__
SherpaOnnxVoiceActivityDetector
*
SherpaOnnxCreateVoiceActivityDetectorOHOS
(
const
SherpaOnnxVadModelConfig
*
config
,
float
buffer_size_in_seconds
,
NativeResourceManager
*
mgr
)
{
if
(
mgr
==
nullptr
)
{
return
SherpaOnnxCreateVoiceActivityDetector
(
config
,
buffer_size_in_seconds
);
}
auto
vad_config
=
GetVadModelConfig
(
config
);
SherpaOnnxVoiceActivityDetector
*
p
=
new
SherpaOnnxVoiceActivityDetector
;
p
->
impl
=
std
::
make_unique
<
sherpa_onnx
::
VoiceActivityDetector
>
(
mgr
,
vad_config
,
buffer_size_in_seconds
);
return
p
;
}
#endif
void
SherpaOnnxDestroyVoiceActivityDetector
(
SherpaOnnxVoiceActivityDetector
*
p
)
{
delete
p
;
...
...
@@ -1891,4 +1874,42 @@ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
return
ans
;
}
#ifdef __OHOS__
const
SherpaOnnxOfflineRecognizer
*
SherpaOnnxCreateOfflineRecognizerOHOS
(
const
SherpaOnnxOfflineRecognizerConfig
*
config
,
NativeResourceManager
*
mgr
)
{
if
(
mgr
==
nullptr
)
{
return
SherpaOnnxCreateOfflineRecognizer
(
config
);
}
sherpa_onnx
::
OfflineRecognizerConfig
recognizer_config
=
GetOfflineRecognizerConfig
(
config
);
SherpaOnnxOfflineRecognizer
*
recognizer
=
new
SherpaOnnxOfflineRecognizer
;
recognizer
->
impl
=
std
::
make_unique
<
sherpa_onnx
::
OfflineRecognizer
>
(
mgr
,
recognizer_config
);
return
recognizer
;
}
SherpaOnnxVoiceActivityDetector
*
SherpaOnnxCreateVoiceActivityDetectorOHOS
(
const
SherpaOnnxVadModelConfig
*
config
,
float
buffer_size_in_seconds
,
NativeResourceManager
*
mgr
)
{
if
(
mgr
==
nullptr
)
{
return
SherpaOnnxCreateVoiceActivityDetector
(
config
,
buffer_size_in_seconds
);
}
auto
vad_config
=
GetVadModelConfig
(
config
);
SherpaOnnxVoiceActivityDetector
*
p
=
new
SherpaOnnxVoiceActivityDetector
;
p
->
impl
=
std
::
make_unique
<
sherpa_onnx
::
VoiceActivityDetector
>
(
mgr
,
vad_config
,
buffer_size_in_seconds
);
return
p
;
}
#endif
#endif
...
...
sherpa-onnx/c-api/c-api.h
查看文件 @
298b6b6
...
...
@@ -841,21 +841,6 @@ SHERPA_ONNX_API SherpaOnnxVoiceActivityDetector *
SherpaOnnxCreateVoiceActivityDetector
(
const
SherpaOnnxVadModelConfig
*
config
,
float
buffer_size_in_seconds
);
#ifdef __OHOS__
// Return an instance of VoiceActivityDetector.
// The user has to use SherpaOnnxDestroyVoiceActivityDetector() to free
// the returned pointer to avoid memory leak.
//
// It is for HarmonyOS
typedef
struct
NativeResourceManager
NativeResourceManager
;
SHERPA_ONNX_API
SherpaOnnxVoiceActivityDetector
*
SherpaOnnxCreateVoiceActivityDetectorOHOS
(
const
SherpaOnnxVadModelConfig
*
config
,
float
buffer_size_in_seconds
,
NativeResourceManager
*
mgr
);
#endif
SHERPA_ONNX_API
void
SherpaOnnxDestroyVoiceActivityDetector
(
SherpaOnnxVoiceActivityDetector
*
p
);
...
...
@@ -1537,6 +1522,29 @@ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
SHERPA_ONNX_API
void
SherpaOnnxOfflineSpeakerDiarizationDestroyResult
(
const
SherpaOnnxOfflineSpeakerDiarizationResult
*
r
);
#ifdef __OHOS__
// It is for HarmonyOS
typedef
struct
NativeResourceManager
NativeResourceManager
;
/// @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
*
SherpaOnnxCreateOfflineRecognizerOHOS
(
const
SherpaOnnxOfflineRecognizerConfig
*
config
,
NativeResourceManager
*
mgr
);
// Return an instance of VoiceActivityDetector.
// The user has to use SherpaOnnxDestroyVoiceActivityDetector() to free
// the returned pointer to avoid memory leak.
SHERPA_ONNX_API
SherpaOnnxVoiceActivityDetector
*
SherpaOnnxCreateVoiceActivityDetectorOHOS
(
const
SherpaOnnxVadModelConfig
*
config
,
float
buffer_size_in_seconds
,
NativeResourceManager
*
mgr
);
#endif
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
...
...
sherpa-onnx/c-api/cxx-api.h
查看文件 @
298b6b6
...
...
@@ -214,11 +214,6 @@ struct SHERPA_ONNX_API OfflineTdnnModelConfig {
std
::
string
model
;
};
struct
SHERPA_ONNX_API
SherpaOnnxOfflineLMConfig
{
std
::
string
model
;
float
scale
=
1
.
0
;
};
struct
SHERPA_ONNX_API
OfflineSenseVoiceModelConfig
{
std
::
string
model
;
std
::
string
language
;
...
...
sherpa-onnx/csrc/offline-ctc-model.cc
查看文件 @
298b6b6
...
...
@@ -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/offline-nemo-enc-dec-ctc-model.h"
#include "sherpa-onnx/csrc/offline-tdnn-ctc-model.h"
...
...
@@ -48,7 +57,11 @@ static ModelType GetModelType(char *model_data, size_t model_data_length,
if
(
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
SHERPA_ONNX_LOGE
(
"%s"
,
os
.
str
().
c_str
());
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
...
...
@@ -144,10 +157,9 @@ std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
return
nullptr
;
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
std
::
unique_ptr
<
OfflineCtcModel
>
OfflineCtcModel
::
Create
(
AAsset
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
{
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
{
// TODO(fangjun): Refactor it. We don't need to use model_type here
ModelType
model_type
=
ModelType
::
kUnknown
;
...
...
@@ -196,6 +208,15 @@ std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
return
nullptr
;
}
#if __ANDROID_API__ >= 9
template
std
::
unique_ptr
<
OfflineCtcModel
>
OfflineCtcModel
::
Create
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
std
::
unique_ptr
<
OfflineCtcModel
>
OfflineCtcModel
::
Create
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-ctc-model.h
查看文件 @
298b6b6
...
...
@@ -8,11 +8,6 @@
#include <string>
#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/offline-model-config.h"
...
...
@@ -25,10 +20,9 @@ class OfflineCtcModel {
static
std
::
unique_ptr
<
OfflineCtcModel
>
Create
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
static
std
::
unique_ptr
<
OfflineCtcModel
>
Create
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
/** Run the forward method of the model.
*
...
...
sherpa-onnx/csrc/offline-lm.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,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/offline-rnn-lm.h"
namespace
sherpa_onnx
{
...
...
@@ -16,12 +25,11 @@ std::unique_ptr<OfflineLM> OfflineLM::Create(const OfflineLMConfig &config) {
return
std
::
make_unique
<
OfflineRnnLM
>
(
config
);
}
#if __ANDROID_API__ >= 9
std
::
unique_ptr
<
OfflineLM
>
OfflineLM
::
Create
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
std
::
unique_ptr
<
OfflineLM
>
OfflineLM
::
Create
(
Manager
*
mgr
,
const
OfflineLMConfig
&
config
)
{
return
std
::
make_unique
<
OfflineRnnLM
>
(
mgr
,
config
);
}
#endif
void
OfflineLM
::
ComputeLMScore
(
float
scale
,
int32_t
context_size
,
std
::
vector
<
Hypotheses
>
*
hyps
)
{
...
...
@@ -75,4 +83,14 @@ void OfflineLM::ComputeLMScore(float scale, int32_t context_size,
}
}
#if __ANDROID_API__ >= 9
template
std
::
unique_ptr
<
OfflineLM
>
OfflineLM
::
Create
(
AAssetManager
*
mgr
,
const
OfflineLMConfig
&
config
);
#endif
#if __OHOS__
template
std
::
unique_ptr
<
OfflineLM
>
OfflineLM
::
Create
(
NativeResourceManager
*
mgr
,
const
OfflineLMConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-lm.h
查看文件 @
298b6b6
...
...
@@ -8,11 +8,6 @@
#include <memory>
#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/offline-lm-config.h"
...
...
@@ -25,10 +20,9 @@ class OfflineLM {
static
std
::
unique_ptr
<
OfflineLM
>
Create
(
const
OfflineLMConfig
&
config
);
#if __ANDROID_API__ >= 9
static
std
::
unique_ptr
<
OfflineLM
>
Create
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
static
std
::
unique_ptr
<
OfflineLM
>
Create
(
Manager
*
mgr
,
const
OfflineLMConfig
&
config
);
#endif
/** Rescore a batch of sentences.
*
...
...
sherpa-onnx/csrc/offline-moonshine-model.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,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/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -43,8 +52,8 @@ class OfflineMoonshineModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -69,7 +78,6 @@ class OfflineMoonshineModel::Impl {
InitCachedDecoder
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
Ort
::
Value
ForwardPreprocessor
(
Ort
::
Value
audio
)
{
auto
features
=
preprocessor_sess_
->
Run
(
...
...
@@ -242,11 +250,10 @@ class OfflineMoonshineModel::Impl {
OfflineMoonshineModel
::
OfflineMoonshineModel
(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineMoonshineModel
::
OfflineMoonshineModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineMoonshineModel
::
OfflineMoonshineModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineMoonshineModel
::~
OfflineMoonshineModel
()
=
default
;
...
...
@@ -279,4 +286,14 @@ OrtAllocator *OfflineMoonshineModel::Allocator() const {
return
impl_
->
Allocator
();
}
#if __ANDROID_API__ >= 9
template
OfflineMoonshineModel
::
OfflineMoonshineModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineMoonshineModel
::
OfflineMoonshineModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-moonshine-model.h
查看文件 @
298b6b6
...
...
@@ -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/offline-model-config.h"
...
...
@@ -25,9 +20,8 @@ class OfflineMoonshineModel {
public
:
explicit
OfflineMoonshineModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineMoonshineModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineMoonshineModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineMoonshineModel
();
...
...
sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.cc
查看文件 @
298b6b6
...
...
@@ -4,6 +4,15 @@
#include "sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.h"
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -23,8 +32,8 @@ class OfflineNemoEncDecCtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -32,7 +41,6 @@ class OfflineNemoEncDecCtcModel::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
nemo_ctc
.
model
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
features
,
Ort
::
Value
features_length
)
{
...
...
@@ -88,7 +96,11 @@ class OfflineNemoEncDecCtcModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -126,11 +138,10 @@ OfflineNemoEncDecCtcModel::OfflineNemoEncDecCtcModel(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OfflineNemoEncDecCtcModel
::
OfflineNemoEncDecCtcModel
(
AAsset
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineNemoEncDecCtcModel
::~
OfflineNemoEncDecCtcModel
()
=
default
;
...
...
@@ -156,4 +167,14 @@ std::string OfflineNemoEncDecCtcModel::FeatureNormalizationMethod() const {
bool
OfflineNemoEncDecCtcModel
::
IsGigaAM
()
const
{
return
impl_
->
IsGigaAM
();
}
#if __ANDROID_API__ >= 9
template
OfflineNemoEncDecCtcModel
::
OfflineNemoEncDecCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineNemoEncDecCtcModel
::
OfflineNemoEncDecCtcModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.h
查看文件 @
298b6b6
...
...
@@ -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/offline-ctc-model.h"
#include "sherpa-onnx/csrc/offline-model-config.h"
...
...
@@ -29,10 +24,8 @@ class OfflineNemoEncDecCtcModel : public OfflineCtcModel {
public
:
explicit
OfflineNemoEncDecCtcModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineNemoEncDecCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineNemoEncDecCtcModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineNemoEncDecCtcModel
()
override
;
...
...
sherpa-onnx/csrc/offline-paraformer-model.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,15 @@
#include <string>
#include <utility>
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -26,8 +35,8 @@ class OfflineParaformerModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -35,7 +44,6 @@ class OfflineParaformerModel::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
paraformer
.
model
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
features
,
Ort
::
Value
features_length
)
{
...
...
@@ -72,7 +80,11 @@ class OfflineParaformerModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -109,11 +121,10 @@ class OfflineParaformerModel::Impl {
OfflineParaformerModel
::
OfflineParaformerModel
(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineParaformerModel
::
OfflineParaformerModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineParaformerModel
::
OfflineParaformerModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineParaformerModel
::~
OfflineParaformerModel
()
=
default
;
...
...
@@ -141,4 +152,14 @@ OrtAllocator *OfflineParaformerModel::Allocator() const {
return
impl_
->
Allocator
();
}
#if __ANDROID_API__ >= 9
template
OfflineParaformerModel
::
OfflineParaformerModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineParaformerModel
::
OfflineParaformerModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-paraformer-model.h
查看文件 @
298b6b6
...
...
@@ -7,11 +7,6 @@
#include <memory>
#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/offline-model-config.h"
...
...
@@ -21,9 +16,8 @@ class OfflineParaformerModel {
public
:
explicit
OfflineParaformerModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineParaformerModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineParaformerModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineParaformerModel
();
...
...
sherpa-onnx/csrc/offline-recognizer-ctc-impl.h
查看文件 @
298b6b6
...
...
@@ -12,11 +12,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/offline-ctc-decoder.h"
#include "sherpa-onnx/csrc/offline-ctc-fst-decoder.h"
#include "sherpa-onnx/csrc/offline-ctc-greedy-search-decoder.h"
...
...
@@ -80,16 +75,14 @@ class OfflineRecognizerCtcImpl : public OfflineRecognizerImpl {
Init
();
}
#if __ANDROID_API__ >= 9
OfflineRecognizerCtcImpl
(
AAssetManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
template
<
typename
Manager
>
OfflineRecognizerCtcImpl
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
OfflineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
symbol_table_
(
mgr
,
config_
.
model_config
.
tokens
),
model_
(
OfflineCtcModel
::
Create
(
mgr
,
config_
.
model_config
))
{
Init
();
}
#endif
void
Init
()
{
if
(
!
config_
.
model_config
.
telespeech_ctc
.
empty
())
{
...
...
sherpa-onnx/csrc/offline-recognizer-impl.cc
查看文件 @
298b6b6
...
...
@@ -13,6 +13,10 @@
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#elif __OHOS__
#include <strstream>
#include "rawfile/raw_file_manager.h"
#endif
#include "fst/extensions/far/far.h"
...
...
@@ -211,9 +215,9 @@ std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
exit
(
-
1
);
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
std
::
unique_ptr
<
OfflineRecognizerImpl
>
OfflineRecognizerImpl
::
Create
(
AAsset
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
{
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
{
if
(
!
config
.
model_config
.
sense_voice
.
model
.
empty
())
{
return
std
::
make_unique
<
OfflineRecognizerSenseVoiceImpl
>
(
mgr
,
config
);
}
...
...
@@ -389,7 +393,6 @@ std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
exit
(
-
1
);
}
#endif
OfflineRecognizerImpl
::
OfflineRecognizerImpl
(
const
OfflineRecognizerConfig
&
config
)
...
...
@@ -436,9 +439,9 @@ OfflineRecognizerImpl::OfflineRecognizerImpl(
}
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OfflineRecognizerImpl
::
OfflineRecognizerImpl
(
AAsset
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
config_
(
config
)
{
if
(
!
config
.
rule_fsts
.
empty
())
{
std
::
vector
<
std
::
string
>
files
;
...
...
@@ -482,7 +485,6 @@ OfflineRecognizerImpl::OfflineRecognizerImpl(
}
// for (const auto &f : files)
}
// if (!config.rule_fars.empty())
}
#endif
std
::
string
OfflineRecognizerImpl
::
ApplyInverseTextNormalization
(
std
::
string
text
)
const
{
...
...
@@ -499,4 +501,19 @@ void OfflineRecognizerImpl::SetConfig(const OfflineRecognizerConfig &config) {
config_
=
config
;
}
#if __ANDROID_API__ >= 9
template
OfflineRecognizerImpl
::
OfflineRecognizerImpl
(
AAssetManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
template
std
::
unique_ptr
<
OfflineRecognizerImpl
>
OfflineRecognizerImpl
::
Create
(
AAssetManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
#endif
#if __OHOS__
template
OfflineRecognizerImpl
::
OfflineRecognizerImpl
(
NativeResourceManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
template
std
::
unique_ptr
<
OfflineRecognizerImpl
>
OfflineRecognizerImpl
::
Create
(
NativeResourceManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-recognizer-impl.h
查看文件 @
298b6b6
...
...
@@ -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/offline-recognizer.h"
...
...
@@ -28,13 +23,12 @@ class OfflineRecognizerImpl {
static
std
::
unique_ptr
<
OfflineRecognizerImpl
>
Create
(
const
OfflineRecognizerConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineRecognizerImpl
(
AAssetManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
template
<
typename
Manager
>
OfflineRecognizerImpl
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
template
<
typename
Manager
>
static
std
::
unique_ptr
<
OfflineRecognizerImpl
>
Create
(
AAssetManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
#endif
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
virtual
~
OfflineRecognizerImpl
()
=
default
;
...
...
sherpa-onnx/csrc/offline-recognizer-moonshine-impl.h
查看文件 @
298b6b6
...
...
@@ -12,11 +12,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/offline-model-config.h"
#include "sherpa-onnx/csrc/offline-moonshine-decoder.h"
#include "sherpa-onnx/csrc/offline-moonshine-greedy-search-decoder.h"
...
...
@@ -59,8 +54,8 @@ class OfflineRecognizerMoonshineImpl : public OfflineRecognizerImpl {
Init
();
}
#if __ANDROID_API__ >= 9
OfflineRecognizerMoonshineImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineRecognizerMoonshineImpl
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
OfflineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
...
...
@@ -70,8 +65,6 @@ class OfflineRecognizerMoonshineImpl : public OfflineRecognizerImpl {
Init
();
}
#endif
void
Init
()
{
if
(
config_
.
decoding_method
==
"greedy_search"
)
{
decoder_
=
...
...
sherpa-onnx/csrc/offline-recognizer-paraformer-impl.h
查看文件 @
298b6b6
...
...
@@ -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 "sherpa-onnx/csrc/offline-model-config.h"
#include "sherpa-onnx/csrc/offline-paraformer-decoder.h"
#include "sherpa-onnx/csrc/offline-paraformer-greedy-search-decoder.h"
...
...
@@ -105,8 +100,8 @@ class OfflineRecognizerParaformerImpl : public OfflineRecognizerImpl {
InitFeatConfig
();
}
#if __ANDROID_API__ >= 9
OfflineRecognizerParaformerImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineRecognizerParaformerImpl
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
OfflineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
...
...
@@ -124,7 +119,6 @@ class OfflineRecognizerParaformerImpl : public OfflineRecognizerImpl {
InitFeatConfig
();
}
#endif
std
::
unique_ptr
<
OfflineStream
>
CreateStream
()
const
override
{
return
std
::
make_unique
<
OfflineStream
>
(
config_
.
feat_config
);
...
...
sherpa-onnx/csrc/offline-recognizer-sense-voice-impl.h
查看文件 @
298b6b6
...
...
@@ -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 "sherpa-onnx/csrc/offline-ctc-greedy-search-decoder.h"
#include "sherpa-onnx/csrc/offline-model-config.h"
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
...
...
@@ -83,8 +78,8 @@ class OfflineRecognizerSenseVoiceImpl : public OfflineRecognizerImpl {
InitFeatConfig
();
}
#if __ANDROID_API__ >= 9
OfflineRecognizerSenseVoiceImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineRecognizerSenseVoiceImpl
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
OfflineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
...
...
@@ -103,7 +98,6 @@ class OfflineRecognizerSenseVoiceImpl : public OfflineRecognizerImpl {
InitFeatConfig
();
}
#endif
std
::
unique_ptr
<
OfflineStream
>
CreateStream
()
const
override
{
return
std
::
make_unique
<
OfflineStream
>
(
config_
.
feat_config
);
...
...
sherpa-onnx/csrc/offline-recognizer-transducer-impl.h
查看文件 @
298b6b6
...
...
@@ -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/context-graph.h"
#include "sherpa-onnx/csrc/log.h"
#include "sherpa-onnx/csrc/macros.h"
...
...
@@ -109,9 +104,9 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
}
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
explicit
OfflineRecognizerTransducerImpl
(
AAsset
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
OfflineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
symbol_table_
(
mgr
,
config_
.
model_config
.
tokens
),
...
...
@@ -148,7 +143,6 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
exit
(
-
1
);
}
}
#endif
std
::
unique_ptr
<
OfflineStream
>
CreateStream
(
const
std
::
string
&
hotwords
)
const
override
{
...
...
@@ -246,10 +240,7 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
}
}
OfflineRecognizerConfig
GetConfig
()
const
override
{
return
config_
;
}
OfflineRecognizerConfig
GetConfig
()
const
override
{
return
config_
;
}
void
InitHotwords
()
{
// each line in hotwords_file contains space-separated words
...
...
@@ -271,8 +262,8 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
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
);
...
...
@@ -294,7 +285,6 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
hotwords_graph_
=
std
::
make_shared
<
ContextGraph
>
(
hotwords_
,
config_
.
hotwords_score
,
boost_scores_
);
}
#endif
private
:
OfflineRecognizerConfig
config_
;
...
...
sherpa-onnx/csrc/offline-recognizer-transducer-nemo-impl.h
查看文件 @
298b6b6
...
...
@@ -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/macros.h"
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
#include "sherpa-onnx/csrc/offline-recognizer.h"
...
...
@@ -57,9 +52,9 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
PostInit
();
}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
explicit
OfflineRecognizerTransducerNeMoImpl
(
AAsset
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
OfflineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
symbol_table_
(
mgr
,
config_
.
model_config
.
tokens
),
...
...
@@ -76,7 +71,6 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
PostInit
();
}
#endif
std
::
unique_ptr
<
OfflineStream
>
CreateStream
()
const
override
{
return
std
::
make_unique
<
OfflineStream
>
(
config_
.
feat_config
);
...
...
sherpa-onnx/csrc/offline-recognizer-whisper-impl.h
查看文件 @
298b6b6
...
...
@@ -12,11 +12,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/offline-model-config.h"
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
#include "sherpa-onnx/csrc/offline-recognizer.h"
...
...
@@ -60,8 +55,8 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
Init
();
}
#if __ANDROID_API__ >= 9
OfflineRecognizerWhisperImpl
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineRecognizerWhisperImpl
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
OfflineRecognizerImpl
(
mgr
,
config
),
config_
(
config
),
...
...
@@ -71,8 +66,6 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
Init
();
}
#endif
void
Init
()
{
// tokens.txt from whisper is base64 encoded, so we need to decode it
symbol_table_
.
ApplyBase64Decode
();
...
...
@@ -105,9 +98,7 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
config_
.
model_config
.
whisper
=
config
.
model_config
.
whisper
;
}
OfflineRecognizerConfig
GetConfig
()
const
override
{
return
config_
;
}
OfflineRecognizerConfig
GetConfig
()
const
override
{
return
config_
;
}
private
:
void
DecodeStream
(
OfflineStream
*
s
)
const
{
...
...
sherpa-onnx/csrc/offline-recognizer.cc
查看文件 @
298b6b6
...
...
@@ -6,11 +6,21 @@
#include <memory>
#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/macros.h"
#include "sherpa-onnx/csrc/offline-lm-config.h"
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
#include "sherpa-onnx/csrc/text-utils.h"
namespace
sherpa_onnx
{
void
OfflineRecognizerConfig
::
Register
(
ParseOptions
*
po
)
{
...
...
@@ -132,11 +142,10 @@ std::string OfflineRecognizerConfig::ToString() const {
return
os
.
str
();
}
#if __ANDROID_API__ >= 9
OfflineRecognizer
::
OfflineRecognizer
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineRecognizer
::
OfflineRecognizer
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
)
:
impl_
(
OfflineRecognizerImpl
::
Create
(
mgr
,
config
))
{}
#endif
OfflineRecognizer
::
OfflineRecognizer
(
const
OfflineRecognizerConfig
&
config
)
:
impl_
(
OfflineRecognizerImpl
::
Create
(
config
))
{}
...
...
@@ -164,4 +173,14 @@ OfflineRecognizerConfig OfflineRecognizer::GetConfig() const {
return
impl_
->
GetConfig
();
}
#if __ANDROID_API__ >= 9
template
OfflineRecognizer
::
OfflineRecognizer
(
AAssetManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
#endif
#if __OHOS__
template
OfflineRecognizer
::
OfflineRecognizer
(
NativeResourceManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-recognizer.h
查看文件 @
298b6b6
...
...
@@ -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/features.h"
#include "sherpa-onnx/csrc/offline-ctc-fst-decoder-config.h"
#include "sherpa-onnx/csrc/offline-lm-config.h"
...
...
@@ -82,9 +77,8 @@ class OfflineRecognizer {
public
:
~
OfflineRecognizer
();
#if __ANDROID_API__ >= 9
OfflineRecognizer
(
AAssetManager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineRecognizer
(
Manager
*
mgr
,
const
OfflineRecognizerConfig
&
config
);
explicit
OfflineRecognizer
(
const
OfflineRecognizerConfig
&
config
);
...
...
@@ -121,8 +115,8 @@ class OfflineRecognizer {
/** Onnxruntime Session objects are not affected by this method.
* The exact behavior can be defined by a specific recognizer impl.
* For instance, for the whisper recognizer, you can retrieve the language and task from
* the config and ignore any remaining fields in `config`.
* For instance, for the whisper recognizer, you can retrieve the language and
* task from the config and ignore any remaining fields in `config`.
*/
void
SetConfig
(
const
OfflineRecognizerConfig
&
config
);
...
...
sherpa-onnx/csrc/offline-rnn-lm.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,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 "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
...
...
@@ -27,8 +36,8 @@ class OfflineRnnLM::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineLMConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineLMConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
{
GetSessionOptions
(
config
)},
...
...
@@ -36,7 +45,6 @@ class OfflineRnnLM::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
model
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
Ort
::
Value
Rescore
(
Ort
::
Value
x
,
Ort
::
Value
x_lens
)
{
std
::
array
<
Ort
::
Value
,
2
>
inputs
=
{
std
::
move
(
x
),
std
::
move
(
x_lens
)};
...
...
@@ -76,10 +84,9 @@ class OfflineRnnLM::Impl {
OfflineRnnLM
::
OfflineRnnLM
(
const
OfflineLMConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineRnnLM
::
OfflineRnnLM
(
AAssetManager
*
mgr
,
const
OfflineLMConfig
&
config
)
template
<
typename
Manager
>
OfflineRnnLM
::
OfflineRnnLM
(
Manager
*
mgr
,
const
OfflineLMConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineRnnLM
::~
OfflineRnnLM
()
=
default
;
...
...
@@ -87,4 +94,14 @@ Ort::Value OfflineRnnLM::Rescore(Ort::Value x, Ort::Value x_lens) {
return
impl_
->
Rescore
(
std
::
move
(
x
),
std
::
move
(
x_lens
));
}
#if __ANDROID_API__ >= 9
template
OfflineRnnLM
::
OfflineRnnLM
(
AAssetManager
*
mgr
,
const
OfflineLMConfig
&
config
);
#endif
#if __OHOS__
template
OfflineRnnLM
::
OfflineRnnLM
(
NativeResourceManager
*
mgr
,
const
OfflineLMConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-rnn-lm.h
查看文件 @
298b6b6
...
...
@@ -7,11 +7,6 @@
#include <memory>
#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/offline-lm-config.h"
#include "sherpa-onnx/csrc/offline-lm.h"
...
...
@@ -24,9 +19,8 @@ class OfflineRnnLM : public OfflineLM {
explicit
OfflineRnnLM
(
const
OfflineLMConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineRnnLM
(
AAssetManager
*
mgr
,
const
OfflineLMConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineRnnLM
(
Manager
*
mgr
,
const
OfflineLMConfig
&
config
);
/** Rescore a batch of sentences.
*
...
...
sherpa-onnx/csrc/offline-sense-voice-model.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,15 @@
#include <string>
#include <utility>
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -26,8 +35,8 @@ class OfflineSenseVoiceModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -35,7 +44,6 @@ class OfflineSenseVoiceModel::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
sense_voice
.
model
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
Ort
::
Value
Forward
(
Ort
::
Value
features
,
Ort
::
Value
features_length
,
Ort
::
Value
language
,
Ort
::
Value
text_norm
)
{
...
...
@@ -72,7 +80,11 @@ class OfflineSenseVoiceModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -129,11 +141,10 @@ class OfflineSenseVoiceModel::Impl {
OfflineSenseVoiceModel
::
OfflineSenseVoiceModel
(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineSenseVoiceModel
::
OfflineSenseVoiceModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineSenseVoiceModel
::
OfflineSenseVoiceModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineSenseVoiceModel
::~
OfflineSenseVoiceModel
()
=
default
;
...
...
@@ -154,4 +165,14 @@ OrtAllocator *OfflineSenseVoiceModel::Allocator() const {
return
impl_
->
Allocator
();
}
#if __ANDROID_API__ >= 9
template
OfflineSenseVoiceModel
::
OfflineSenseVoiceModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineSenseVoiceModel
::
OfflineSenseVoiceModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-sense-voice-model.h
查看文件 @
298b6b6
...
...
@@ -7,11 +7,6 @@
#include <memory>
#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/offline-model-config.h"
#include "sherpa-onnx/csrc/offline-sense-voice-model-meta-data.h"
...
...
@@ -22,9 +17,8 @@ class OfflineSenseVoiceModel {
public
:
explicit
OfflineSenseVoiceModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineSenseVoiceModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineSenseVoiceModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineSenseVoiceModel
();
...
...
sherpa-onnx/csrc/offline-tdnn-ctc-model.cc
查看文件 @
298b6b6
...
...
@@ -6,6 +6,15 @@
#include <utility>
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -25,8 +34,8 @@ class OfflineTdnnCtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -34,7 +43,6 @@ class OfflineTdnnCtcModel::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
tdnn
.
model
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
features
)
{
auto
nnet_out
=
...
...
@@ -79,7 +87,11 @@ class OfflineTdnnCtcModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -106,11 +118,10 @@ class OfflineTdnnCtcModel::Impl {
OfflineTdnnCtcModel
::
OfflineTdnnCtcModel
(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineTdnnCtcModel
::
OfflineTdnnCtcModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineTdnnCtcModel
::
OfflineTdnnCtcModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineTdnnCtcModel
::~
OfflineTdnnCtcModel
()
=
default
;
...
...
@@ -125,4 +136,14 @@ OrtAllocator *OfflineTdnnCtcModel::Allocator() const {
return
impl_
->
Allocator
();
}
#if __ANDROID_API__ >= 9
template
OfflineTdnnCtcModel
::
OfflineTdnnCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineTdnnCtcModel
::
OfflineTdnnCtcModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-tdnn-ctc-model.h
查看文件 @
298b6b6
...
...
@@ -7,11 +7,6 @@
#include <string>
#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/offline-ctc-model.h"
#include "sherpa-onnx/csrc/offline-model-config.h"
...
...
@@ -27,9 +22,8 @@ class OfflineTdnnCtcModel : public OfflineCtcModel {
public
:
explicit
OfflineTdnnCtcModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineTdnnCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineTdnnCtcModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineTdnnCtcModel
()
override
;
...
...
sherpa-onnx/csrc/offline-telespeech-ctc-model.cc
查看文件 @
298b6b6
...
...
@@ -4,6 +4,15 @@
#include "sherpa-onnx/csrc/offline-telespeech-ctc-model.h"
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -23,8 +32,8 @@ class OfflineTeleSpeechCtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -32,7 +41,6 @@ class OfflineTeleSpeechCtcModel::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
telespeech_ctc
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
features
,
Ort
::
Value
/*features_length*/
)
{
...
...
@@ -85,7 +93,11 @@ class OfflineTeleSpeechCtcModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
{
...
...
@@ -117,11 +129,10 @@ OfflineTeleSpeechCtcModel::OfflineTeleSpeechCtcModel(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OfflineTeleSpeechCtcModel
::
OfflineTeleSpeechCtcModel
(
AAsset
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineTeleSpeechCtcModel
::~
OfflineTeleSpeechCtcModel
()
=
default
;
...
...
@@ -141,4 +152,14 @@ OrtAllocator *OfflineTeleSpeechCtcModel::Allocator() const {
return
impl_
->
Allocator
();
}
#if __ANDROID_API__ >= 9
template
OfflineTeleSpeechCtcModel
::
OfflineTeleSpeechCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineTeleSpeechCtcModel
::
OfflineTeleSpeechCtcModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-telespeech-ctc-model.h
查看文件 @
298b6b6
...
...
@@ -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/offline-ctc-model.h"
#include "sherpa-onnx/csrc/offline-model-config.h"
...
...
@@ -31,10 +26,8 @@ class OfflineTeleSpeechCtcModel : public OfflineCtcModel {
public
:
explicit
OfflineTeleSpeechCtcModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineTeleSpeechCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineTeleSpeechCtcModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineTeleSpeechCtcModel
()
override
;
...
...
sherpa-onnx/csrc/offline-transducer-model.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,15 @@
#include <string>
#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/macros.h"
#include "sherpa-onnx/csrc/offline-transducer-decoder.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
...
...
@@ -38,8 +47,8 @@ class OfflineTransducerModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -59,7 +68,6 @@ class OfflineTransducerModel::Impl {
InitJoiner
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
pair
<
Ort
::
Value
,
Ort
::
Value
>
RunEncoder
(
Ort
::
Value
features
,
Ort
::
Value
features_length
)
{
...
...
@@ -161,7 +169,11 @@ class OfflineTransducerModel::Impl {
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
}
...
...
@@ -244,11 +256,10 @@ class OfflineTransducerModel::Impl {
OfflineTransducerModel
::
OfflineTransducerModel
(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineTransducerModel
::
OfflineTransducerModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineTransducerModel
::
OfflineTransducerModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineTransducerModel
::~
OfflineTransducerModel
()
=
default
;
...
...
@@ -291,4 +302,14 @@ Ort::Value OfflineTransducerModel::BuildDecoderInput(
return
impl_
->
BuildDecoderInput
(
results
,
end_index
);
}
#if __ANDROID_API__ >= 9
template
OfflineTransducerModel
::
OfflineTransducerModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineTransducerModel
::
OfflineTransducerModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-transducer-model.h
查看文件 @
298b6b6
...
...
@@ -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/offline-model-config.h"
...
...
@@ -25,9 +20,8 @@ class OfflineTransducerModel {
public
:
explicit
OfflineTransducerModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineTransducerModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineTransducerModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineTransducerModel
();
...
...
sherpa-onnx/csrc/offline-transducer-nemo-model.cc
查看文件 @
298b6b6
...
...
@@ -9,6 +9,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/macros.h"
#include "sherpa-onnx/csrc/offline-transducer-decoder.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
...
...
@@ -40,8 +49,8 @@ class OfflineTransducerNeMoModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -61,7 +70,6 @@ class OfflineTransducerNeMoModel::Impl {
InitJoiner
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
vector
<
Ort
::
Value
>
RunEncoder
(
Ort
::
Value
features
,
Ort
::
Value
features_length
)
{
...
...
@@ -172,7 +180,11 @@ class OfflineTransducerNeMoModel::Impl {
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -256,11 +268,10 @@ OfflineTransducerNeMoModel::OfflineTransducerNeMoModel(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OfflineTransducerNeMoModel
::
OfflineTransducerNeMoModel
(
AAsset
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineTransducerNeMoModel
::~
OfflineTransducerNeMoModel
()
=
default
;
...
...
@@ -305,4 +316,14 @@ std::string OfflineTransducerNeMoModel::FeatureNormalizationMethod() const {
bool
OfflineTransducerNeMoModel
::
IsGigaAM
()
const
{
return
impl_
->
IsGigaAM
();
}
#if __ANDROID_API__ >= 9
template
OfflineTransducerNeMoModel
::
OfflineTransducerNeMoModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineTransducerNeMoModel
::
OfflineTransducerNeMoModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-transducer-nemo-model.h
查看文件 @
298b6b6
...
...
@@ -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/offline-model-config.h"
...
...
@@ -26,10 +21,8 @@ class OfflineTransducerNeMoModel {
public
:
explicit
OfflineTransducerNeMoModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineTransducerNeMoModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineTransducerNeMoModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineTransducerNeMoModel
();
...
...
sherpa-onnx/csrc/offline-wenet-ctc-model.cc
查看文件 @
298b6b6
...
...
@@ -4,6 +4,15 @@
#include "sherpa-onnx/csrc/offline-wenet-ctc-model.h"
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -23,8 +32,8 @@ class OfflineWenetCtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -32,7 +41,6 @@ class OfflineWenetCtcModel::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
wenet_ctc
.
model
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
features
,
Ort
::
Value
features_length
)
{
...
...
@@ -63,7 +71,11 @@ class OfflineWenetCtcModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -92,11 +104,10 @@ class OfflineWenetCtcModel::Impl {
OfflineWenetCtcModel
::
OfflineWenetCtcModel
(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineWenetCtcModel
::
OfflineWenetCtcModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineWenetCtcModel
::
OfflineWenetCtcModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineWenetCtcModel
::~
OfflineWenetCtcModel
()
=
default
;
...
...
@@ -115,4 +126,14 @@ OrtAllocator *OfflineWenetCtcModel::Allocator() const {
return
impl_
->
Allocator
();
}
#if __ANDROID_API__ >= 9
template
OfflineWenetCtcModel
::
OfflineWenetCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineWenetCtcModel
::
OfflineWenetCtcModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-wenet-ctc-model.h
查看文件 @
298b6b6
...
...
@@ -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/offline-ctc-model.h"
#include "sherpa-onnx/csrc/offline-model-config.h"
...
...
@@ -31,9 +26,8 @@ class OfflineWenetCtcModel : public OfflineCtcModel {
public
:
explicit
OfflineWenetCtcModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineWenetCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineWenetCtcModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineWenetCtcModel
()
override
;
...
...
sherpa-onnx/csrc/offline-whisper-model.cc
查看文件 @
298b6b6
...
...
@@ -11,6 +11,15 @@
#include <unordered_map>
#include <utility>
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -52,8 +61,8 @@ class OfflineWhisperModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -69,7 +78,8 @@ class OfflineWhisperModel::Impl {
}
}
Impl
(
AAssetManager
*
mgr
,
const
SpokenLanguageIdentificationConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
SpokenLanguageIdentificationConfig
&
config
)
:
lid_config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -84,7 +94,6 @@ class OfflineWhisperModel::Impl {
InitDecoder
(
buf
.
data
(),
buf
.
size
());
}
}
#endif
std
::
pair
<
Ort
::
Value
,
Ort
::
Value
>
ForwardEncoder
(
Ort
::
Value
features
)
{
auto
encoder_out
=
encoder_sess_
->
Run
(
...
...
@@ -237,7 +246,11 @@ class OfflineWhisperModel::Impl {
std
::
ostringstream
os
;
os
<<
"---encoder---
\n
"
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
Ort
::
AllocatorWithDefaultOptions
allocator
;
// used in the macro below
...
...
@@ -338,17 +351,16 @@ OfflineWhisperModel::OfflineWhisperModel(
const
SpokenLanguageIdentificationConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
OfflineWhisperModel
::
OfflineWhisperModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineWhisperModel
::
OfflineWhisperModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
template
<
typename
Manager
>
OfflineWhisperModel
::
OfflineWhisperModel
(
AAsset
Manager
*
mgr
,
const
SpokenLanguageIdentificationConfig
&
config
)
Manager
*
mgr
,
const
SpokenLanguageIdentificationConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineWhisperModel
::~
OfflineWhisperModel
()
=
default
;
std
::
pair
<
Ort
::
Value
,
Ort
::
Value
>
OfflineWhisperModel
::
ForwardEncoder
(
...
...
@@ -453,4 +465,21 @@ void OfflineWhisperModel::NormalizeFeatures(float *features, int32_t num_frames,
}
}
#if __ANDROID_API__ >= 9
template
OfflineWhisperModel
::
OfflineWhisperModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
template
OfflineWhisperModel
::
OfflineWhisperModel
(
AAssetManager
*
mgr
,
const
SpokenLanguageIdentificationConfig
&
config
);
#endif
#if __OHOS__
template
OfflineWhisperModel
::
OfflineWhisperModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
template
OfflineWhisperModel
::
OfflineWhisperModel
(
NativeResourceManager
*
mgr
,
const
SpokenLanguageIdentificationConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-whisper-model.h
查看文件 @
298b6b6
...
...
@@ -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/offline-model-config.h"
#include "sherpa-onnx/csrc/spoken-language-identification.h"
...
...
@@ -29,11 +24,12 @@ class OfflineWhisperModel {
explicit
OfflineWhisperModel
(
const
SpokenLanguageIdentificationConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineWhisperModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
OfflineWhisperModel
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
OfflineWhisperModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
template
<
typename
Manager
>
OfflineWhisperModel
(
Manager
*
mgr
,
const
SpokenLanguageIdentificationConfig
&
config
);
#endif
~
OfflineWhisperModel
();
...
...
sherpa-onnx/csrc/offline-zipformer-ctc-model.cc
查看文件 @
298b6b6
...
...
@@ -6,6 +6,15 @@
#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/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -25,8 +34,8 @@ class OfflineZipformerCtcModel::Impl {
Init
(
buf
.
data
(),
buf
.
size
());
}
#if __ANDROID_API__ >= 9
Impl
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
config_
(
config
),
env_
(
ORT_LOGGING_LEVEL_ERROR
),
sess_opts_
(
GetSessionOptions
(
config
)),
...
...
@@ -34,7 +43,6 @@ class OfflineZipformerCtcModel::Impl {
auto
buf
=
ReadFile
(
mgr
,
config_
.
zipformer_ctc
.
model
);
Init
(
buf
.
data
(),
buf
.
size
());
}
#endif
std
::
vector
<
Ort
::
Value
>
Forward
(
Ort
::
Value
features
,
Ort
::
Value
features_length
)
{
...
...
@@ -64,7 +72,11 @@ class OfflineZipformerCtcModel::Impl {
if
(
config_
.
debug
)
{
std
::
ostringstream
os
;
PrintModelMetadata
(
os
,
meta_data
);
#if __OHOS__
SHERPA_ONNX_LOGE
(
"%{public}s
\n
"
,
os
.
str
().
c_str
());
#else
SHERPA_ONNX_LOGE
(
"%s
\n
"
,
os
.
str
().
c_str
());
#endif
}
// get vocab size from the output[0].shape, which is (N, T, vocab_size)
...
...
@@ -93,11 +105,10 @@ OfflineZipformerCtcModel::OfflineZipformerCtcModel(
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
OfflineZipformerCtcModel
::
OfflineZipformerCtcModel
(
AAsset
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
Manager
*
mgr
,
const
OfflineModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
OfflineZipformerCtcModel
::~
OfflineZipformerCtcModel
()
=
default
;
...
...
@@ -118,4 +129,14 @@ int32_t OfflineZipformerCtcModel::SubsamplingFactor() const {
return
impl_
->
SubsamplingFactor
();
}
#if __ANDROID_API__ >= 9
template
OfflineZipformerCtcModel
::
OfflineZipformerCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
#if __OHOS__
template
OfflineZipformerCtcModel
::
OfflineZipformerCtcModel
(
NativeResourceManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/offline-zipformer-ctc-model.h
查看文件 @
298b6b6
...
...
@@ -7,11 +7,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/offline-ctc-model.h"
#include "sherpa-onnx/csrc/offline-model-config.h"
...
...
@@ -28,10 +23,8 @@ class OfflineZipformerCtcModel : public OfflineCtcModel {
public
:
explicit
OfflineZipformerCtcModel
(
const
OfflineModelConfig
&
config
);
#if __ANDROID_API__ >= 9
OfflineZipformerCtcModel
(
AAssetManager
*
mgr
,
const
OfflineModelConfig
&
config
);
#endif
template
<
typename
Manager
>
OfflineZipformerCtcModel
(
Manager
*
mgr
,
const
OfflineModelConfig
&
config
);
~
OfflineZipformerCtcModel
()
override
;
...
...
sherpa-onnx/csrc/silero-vad-model.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,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/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
...
...
@@ -37,7 +46,6 @@ class SileroVadModel::Impl {
min_speech_samples_
=
sample_rate_
*
config_
.
silero_vad
.
min_speech_duration
;
}
#if __ANDROID_API__ >= 9 || defined(__OHOS__)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
VadModelConfig
&
config
)
:
config_
(
config
),
...
...
@@ -59,7 +67,6 @@ class SileroVadModel::Impl {
min_speech_samples_
=
sample_rate_
*
config_
.
silero_vad
.
min_speech_duration
;
}
#endif
void
Reset
()
{
if
(
is_v5_
)
{
...
...
@@ -433,16 +440,9 @@ class SileroVadModel::Impl {
SileroVadModel
::
SileroVadModel
(
const
VadModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
))
{}
#if __ANDROID_API__ >= 9
SileroVadModel
::
SileroVadModel
(
AAssetManager
*
mgr
,
const
VadModelConfig
&
config
)
template
<
typename
Manager
>
SileroVadModel
::
SileroVadModel
(
Manager
*
mgr
,
const
VadModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
#if __OHOS__
SileroVadModel
::
SileroVadModel
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
))
{}
#endif
SileroVadModel
::~
SileroVadModel
()
=
default
;
...
...
@@ -472,4 +472,14 @@ void SileroVadModel::SetThreshold(float threshold) {
impl_
->
SetThreshold
(
threshold
);
}
#if __ANDROID_API__ >= 9
template
SileroVadModel
::
SileroVadModel
(
AAssetManager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
#if __OHOS__
template
SileroVadModel
::
SileroVadModel
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/silero-vad-model.h
查看文件 @
298b6b6
...
...
@@ -6,15 +6,6 @@
#include <memory>
#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/vad-model.h"
namespace
sherpa_onnx
{
...
...
@@ -23,13 +14,8 @@ class SileroVadModel : public VadModel {
public
:
explicit
SileroVadModel
(
const
VadModelConfig
&
config
);
#if __ANDROID_API__ >= 9
SileroVadModel
(
AAssetManager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
#if __OHOS__
SileroVadModel
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
template
<
typename
Manager
>
SileroVadModel
(
Manager
*
mgr
,
const
VadModelConfig
&
config
);
~
SileroVadModel
()
override
;
...
...
sherpa-onnx/csrc/symbol-table.cc
查看文件 @
298b6b6
...
...
@@ -15,6 +15,10 @@
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#elif __OHOS__
#include <strstream>
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/base64-decode.h"
...
...
@@ -99,14 +103,13 @@ SymbolTable::SymbolTable(const std::string &filename, bool is_file) {
}
}
#if __ANDROID_API__ >= 9
SymbolTable
::
SymbolTable
(
AAssetManager
*
mgr
,
const
std
::
string
&
filename
)
{
template
<
typename
Manager
>
SymbolTable
::
SymbolTable
(
Manager
*
mgr
,
const
std
::
string
&
filename
)
{
auto
buf
=
ReadFile
(
mgr
,
filename
);
std
::
istrstream
is
(
buf
.
data
(),
buf
.
size
());
Init
(
is
);
}
#endif
void
SymbolTable
::
Init
(
std
::
istream
&
is
)
{
sym2id_
=
ReadTokens
(
is
,
&
id2sym_
);
}
...
...
@@ -169,4 +172,14 @@ void SymbolTable::ApplyBase64Decode() {
}
}
#if __ANDROID_API__ >= 9
template
SymbolTable
::
SymbolTable
(
AAssetManager
*
mgr
,
const
std
::
string
&
filename
);
#endif
#if __OHOS__
template
SymbolTable
::
SymbolTable
(
NativeResourceManager
*
mgr
,
const
std
::
string
&
filename
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/symbol-table.h
查看文件 @
298b6b6
...
...
@@ -10,11 +10,6 @@
#include <unordered_map>
#include <vector>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
namespace
sherpa_onnx
{
// The same token can be mapped to different integer IDs, so
...
...
@@ -39,9 +34,8 @@ class SymbolTable {
/// Fields are separated by space(s).
explicit
SymbolTable
(
const
std
::
string
&
filename
,
bool
is_file
=
true
);
#if __ANDROID_API__ >= 9
SymbolTable
(
AAssetManager
*
mgr
,
const
std
::
string
&
filename
);
#endif
template
<
typename
Manager
>
SymbolTable
(
Manager
*
mgr
,
const
std
::
string
&
filename
);
/// Return a string representation of this symbol table
std
::
string
ToString
()
const
;
...
...
sherpa-onnx/csrc/vad-model.cc
查看文件 @
298b6b6
...
...
@@ -4,6 +4,15 @@
#include "sherpa-onnx/csrc/vad-model.h"
#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/silero-vad-model.h"
namespace
sherpa_onnx
{
...
...
@@ -13,20 +22,20 @@ std::unique_ptr<VadModel> VadModel::Create(const VadModelConfig &config) {
return
std
::
make_unique
<
SileroVadModel
>
(
config
);
}
#if __ANDROID_API__ >= 9
std
::
unique_ptr
<
VadModel
>
VadModel
::
Create
(
AAssetManager
*
mgr
,
template
<
typename
Manager
>
std
::
unique_ptr
<
VadModel
>
VadModel
::
Create
(
Manager
*
mgr
,
const
VadModelConfig
&
config
)
{
// TODO(fangjun): Support other VAD models.
return
std
::
make_unique
<
SileroVadModel
>
(
mgr
,
config
);
}
#if __ANDROID_API__ >= 9
template
std
::
unique_ptr
<
VadModel
>
VadModel
::
Create
(
AAssetManager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
#if __OHOS__
std
::
unique_ptr
<
VadModel
>
VadModel
::
Create
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
)
{
// TODO(fangjun): Support other VAD models.
return
std
::
make_unique
<
SileroVadModel
>
(
mgr
,
config
);
}
template
std
::
unique_ptr
<
VadModel
>
VadModel
::
Create
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/vad-model.h
查看文件 @
298b6b6
...
...
@@ -6,15 +6,6 @@
#include <memory>
#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/vad-model-config.h"
namespace
sherpa_onnx
{
...
...
@@ -25,15 +16,9 @@ class VadModel {
static
std
::
unique_ptr
<
VadModel
>
Create
(
const
VadModelConfig
&
config
);
#if __ANDROID_API__ >= 9
static
std
::
unique_ptr
<
VadModel
>
Create
(
AAssetManager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
#if __OHOS__
static
std
::
unique_ptr
<
VadModel
>
Create
(
NativeResourceManager
*
mgr
,
template
<
typename
Manager
>
static
std
::
unique_ptr
<
VadModel
>
Create
(
Manager
*
mgr
,
const
VadModelConfig
&
config
);
#endif
// reset the internal model states
virtual
void
Reset
()
=
0
;
...
...
sherpa-onnx/csrc/voice-activity-detector.cc
查看文件 @
298b6b6
...
...
@@ -8,6 +8,15 @@
#include <queue>
#include <utility>
#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/circular-buffer.h"
#include "sherpa-onnx/csrc/vad-model.h"
...
...
@@ -22,7 +31,6 @@ class VoiceActivityDetector::Impl {
Init
();
}
#if __ANDROID_API__ >= 9 || defined(__OHOS__)
template
<
typename
Manager
>
Impl
(
Manager
*
mgr
,
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
=
60
)
...
...
@@ -31,7 +39,6 @@ class VoiceActivityDetector::Impl {
buffer_
(
buffer_size_in_seconds
*
config
.
sample_rate
)
{
Init
();
}
#endif
void
AcceptWaveform
(
const
float
*
samples
,
int32_t
n
)
{
if
(
buffer_
.
Size
()
>
max_utterance_length_
)
{
...
...
@@ -178,19 +185,11 @@ VoiceActivityDetector::VoiceActivityDetector(
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
/*= 60*/
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
config
,
buffer_size_in_seconds
))
{}
#if __ANDROID_API__ >= 9
template
<
typename
Manager
>
VoiceActivityDetector
::
VoiceActivityDetector
(
AAsset
Manager
*
mgr
,
const
VadModelConfig
&
config
,
Manager
*
mgr
,
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
/*= 60*/
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
,
buffer_size_in_seconds
))
{}
#endif
#if __OHOS__
VoiceActivityDetector
::
VoiceActivityDetector
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
/*= 60*/
)
:
impl_
(
std
::
make_unique
<
Impl
>
(
mgr
,
config
,
buffer_size_in_seconds
))
{}
#endif
VoiceActivityDetector
::~
VoiceActivityDetector
()
=
default
;
...
...
@@ -220,4 +219,16 @@ const VadModelConfig &VoiceActivityDetector::GetConfig() const {
return
impl_
->
GetConfig
();
}
#if __ANDROID_API__ >= 9
template
VoiceActivityDetector
::
VoiceActivityDetector
(
AAssetManager
*
mgr
,
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
=
60
);
#endif
#if __OHOS__
template
VoiceActivityDetector
::
VoiceActivityDetector
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
=
60
);
#endif
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/voice-activity-detector.h
查看文件 @
298b6b6
...
...
@@ -7,15 +7,6 @@
#include <memory>
#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/vad-model-config.h"
namespace
sherpa_onnx
{
...
...
@@ -30,16 +21,9 @@ class VoiceActivityDetector {
explicit
VoiceActivityDetector
(
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
=
60
);
#if __ANDROID_API__ >= 9
VoiceActivityDetector
(
AAssetManager
*
mgr
,
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
=
60
);
#endif
#if __OHOS__
VoiceActivityDetector
(
NativeResourceManager
*
mgr
,
const
VadModelConfig
&
config
,
template
<
typename
Manager
>
VoiceActivityDetector
(
Manager
*
mgr
,
const
VadModelConfig
&
config
,
float
buffer_size_in_seconds
=
60
);
#endif
~
VoiceActivityDetector
();
...
...
请
注册
或
登录
后发表评论