Add streaming ASR support for HarmonyOS. (#1565)
This commit is contained in:
@@ -56,7 +56,7 @@ struct SherpaOnnxDisplay {
|
|||||||
|
|
||||||
#define SHERPA_ONNX_OR(x, y) (x ? x : y)
|
#define SHERPA_ONNX_OR(x, y) (x ? x : y)
|
||||||
|
|
||||||
const SherpaOnnxOnlineRecognizer *SherpaOnnxCreateOnlineRecognizer(
|
static sherpa_onnx::OnlineRecognizerConfig GetOnlineRecognizerConfig(
|
||||||
const SherpaOnnxOnlineRecognizerConfig *config) {
|
const SherpaOnnxOnlineRecognizerConfig *config) {
|
||||||
sherpa_onnx::OnlineRecognizerConfig recognizer_config;
|
sherpa_onnx::OnlineRecognizerConfig recognizer_config;
|
||||||
|
|
||||||
@@ -151,9 +151,21 @@ const SherpaOnnxOnlineRecognizer *SherpaOnnxCreateOnlineRecognizer(
|
|||||||
recognizer_config.rule_fars = SHERPA_ONNX_OR(config->rule_fars, "");
|
recognizer_config.rule_fars = SHERPA_ONNX_OR(config->rule_fars, "");
|
||||||
|
|
||||||
if (config->model_config.debug) {
|
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());
|
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()) {
|
if (!recognizer_config.Validate()) {
|
||||||
SHERPA_ONNX_LOGE("Errors in config!");
|
SHERPA_ONNX_LOGE("Errors in config!");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -1876,6 +1888,20 @@ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
|
|||||||
|
|
||||||
#ifdef __OHOS__
|
#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 SherpaOnnxOfflineRecognizer *SherpaOnnxCreateOfflineRecognizerOHOS(
|
||||||
const SherpaOnnxOfflineRecognizerConfig *config,
|
const SherpaOnnxOfflineRecognizerConfig *config,
|
||||||
NativeResourceManager *mgr) {
|
NativeResourceManager *mgr) {
|
||||||
|
|||||||
@@ -1527,6 +1527,13 @@ SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationDestroyResult(
|
|||||||
// It is for HarmonyOS
|
// It is for HarmonyOS
|
||||||
typedef struct NativeResourceManager NativeResourceManager;
|
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.
|
/// @param config Config for the recognizer.
|
||||||
/// @return Return a pointer to the recognizer. The user has to invoke
|
/// @return Return a pointer to the recognizer. The user has to invoke
|
||||||
// SherpaOnnxDestroyOfflineRecognizer() to free it to avoid memory
|
// SherpaOnnxDestroyOfflineRecognizer() to free it to avoid memory
|
||||||
|
|||||||
@@ -5,17 +5,17 @@
|
|||||||
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <strstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
#if __ANDROID_API__ >= 9
|
||||||
#include <strstream>
|
|
||||||
|
|
||||||
#include "android/asset_manager.h"
|
#include "android/asset_manager.h"
|
||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#elif __OHOS__
|
#endif
|
||||||
#include <strstream>
|
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
#include "rawfile/raw_file_manager.h"
|
#include "rawfile/raw_file_manager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/cat.h"
|
#include "sherpa-onnx/csrc/cat.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
@@ -50,9 +54,9 @@ OnlineConformerTransducerModel::OnlineConformerTransducerModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineConformerTransducerModel::OnlineConformerTransducerModel(
|
OnlineConformerTransducerModel::OnlineConformerTransducerModel(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config)
|
Manager *mgr, const OnlineModelConfig &config)
|
||||||
: env_(ORT_LOGGING_LEVEL_ERROR),
|
: env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
config_(config),
|
config_(config),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -72,7 +76,6 @@ OnlineConformerTransducerModel::OnlineConformerTransducerModel(
|
|||||||
InitJoiner(buf.data(), buf.size());
|
InitJoiner(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void OnlineConformerTransducerModel::InitEncoder(void *model_data,
|
void OnlineConformerTransducerModel::InitEncoder(void *model_data,
|
||||||
size_t model_data_length) {
|
size_t model_data_length) {
|
||||||
@@ -91,7 +94,11 @@ void OnlineConformerTransducerModel::InitEncoder(void *model_data,
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -121,7 +128,11 @@ void OnlineConformerTransducerModel::InitDecoder(void *model_data,
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---decoder---\n";
|
os << "---decoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
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]);
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -10,11 +10,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
||||||
@@ -25,10 +20,8 @@ class OnlineConformerTransducerModel : public OnlineTransducerModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineConformerTransducerModel(const OnlineModelConfig &config);
|
explicit OnlineConformerTransducerModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineConformerTransducerModel(AAssetManager *mgr,
|
OnlineConformerTransducerModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
const OnlineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> StackStates(
|
std::vector<Ort::Value> StackStates(
|
||||||
const std::vector<std::vector<Ort::Value>> &states) const override;
|
const std::vector<std::vector<Ort::Value>> &states) const override;
|
||||||
|
|||||||
@@ -9,6 +9,15 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#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/macros.h"
|
||||||
#include "sherpa-onnx/csrc/online-nemo-ctc-model.h"
|
#include "sherpa-onnx/csrc/online-nemo-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/online-wenet-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(
|
std::unique_ptr<OnlineCtcModel> OnlineCtcModel::Create(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config) {
|
Manager *mgr, const OnlineModelConfig &config) {
|
||||||
if (!config.wenet_ctc.model.empty()) {
|
if (!config.wenet_ctc.model.empty()) {
|
||||||
return std::make_unique<OnlineWenetCtcModel>(mgr, config);
|
return std::make_unique<OnlineWenetCtcModel>(mgr, config);
|
||||||
} else if (!config.zipformer2_ctc.model.empty()) {
|
} else if (!config.zipformer2_ctc.model.empty()) {
|
||||||
@@ -46,6 +54,15 @@ std::unique_ptr<OnlineCtcModel> OnlineCtcModel::Create(
|
|||||||
exit(-1);
|
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
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
|
|
||||||
@@ -25,10 +20,9 @@ class OnlineCtcModel {
|
|||||||
static std::unique_ptr<OnlineCtcModel> Create(
|
static std::unique_ptr<OnlineCtcModel> Create(
|
||||||
const OnlineModelConfig &config);
|
const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
static std::unique_ptr<OnlineCtcModel> Create(
|
static std::unique_ptr<OnlineCtcModel> Create(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config);
|
Manager *mgr, const OnlineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Return a list of tensors containing the initial states
|
// Return a list of tensors containing the initial states
|
||||||
virtual std::vector<Ort::Value> GetInitStates() const = 0;
|
virtual std::vector<Ort::Value> GetInitStates() const = 0;
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/cat.h"
|
#include "sherpa-onnx/csrc/cat.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
@@ -48,9 +52,9 @@ OnlineLstmTransducerModel::OnlineLstmTransducerModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineLstmTransducerModel::OnlineLstmTransducerModel(
|
OnlineLstmTransducerModel::OnlineLstmTransducerModel(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config)
|
Manager *mgr, const OnlineModelConfig &config)
|
||||||
: env_(ORT_LOGGING_LEVEL_ERROR),
|
: env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
config_(config),
|
config_(config),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -70,7 +74,6 @@ OnlineLstmTransducerModel::OnlineLstmTransducerModel(
|
|||||||
InitJoiner(buf.data(), buf.size());
|
InitJoiner(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void OnlineLstmTransducerModel::InitEncoder(void *model_data,
|
void OnlineLstmTransducerModel::InitEncoder(void *model_data,
|
||||||
size_t model_data_length) {
|
size_t model_data_length) {
|
||||||
@@ -89,7 +92,11 @@ void OnlineLstmTransducerModel::InitEncoder(void *model_data,
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
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]);
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
||||||
@@ -24,10 +19,8 @@ class OnlineLstmTransducerModel : public OnlineTransducerModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineLstmTransducerModel(const OnlineModelConfig &config);
|
explicit OnlineLstmTransducerModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineLstmTransducerModel(AAssetManager *mgr,
|
OnlineLstmTransducerModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
const OnlineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> StackStates(
|
std::vector<Ort::Value> StackStates(
|
||||||
const std::vector<std::vector<Ort::Value>> &states) const override;
|
const std::vector<std::vector<Ort::Value>> &states) const override;
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/cat.h"
|
#include "sherpa-onnx/csrc/cat.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
@@ -36,8 +40,8 @@ class OnlineNeMoCtcModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OnlineModelConfig &config)
|
Impl(Manager *mgr, const OnlineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -47,7 +51,6 @@ class OnlineNeMoCtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value x,
|
std::vector<Ort::Value> Forward(Ort::Value x,
|
||||||
std::vector<Ort::Value> states) {
|
std::vector<Ort::Value> states) {
|
||||||
@@ -202,7 +205,11 @@ class OnlineNeMoCtcModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
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
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -286,11 +293,10 @@ class OnlineNeMoCtcModel::Impl {
|
|||||||
OnlineNeMoCtcModel::OnlineNeMoCtcModel(const OnlineModelConfig &config)
|
OnlineNeMoCtcModel::OnlineNeMoCtcModel(const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineNeMoCtcModel::OnlineNeMoCtcModel(AAssetManager *mgr,
|
OnlineNeMoCtcModel::OnlineNeMoCtcModel(Manager *mgr,
|
||||||
const OnlineModelConfig &config)
|
const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OnlineNeMoCtcModel::~OnlineNeMoCtcModel() = default;
|
OnlineNeMoCtcModel::~OnlineNeMoCtcModel() = default;
|
||||||
|
|
||||||
@@ -323,4 +329,14 @@ std::vector<std::vector<Ort::Value>> OnlineNeMoCtcModel::UnStackStates(
|
|||||||
return impl_->UnStackStates(std::move(states));
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-ctc-model.h"
|
#include "sherpa-onnx/csrc/online-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
@@ -23,9 +18,8 @@ class OnlineNeMoCtcModel : public OnlineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineNeMoCtcModel(const OnlineModelConfig &config);
|
explicit OnlineNeMoCtcModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineNeMoCtcModel(AAssetManager *mgr, const OnlineModelConfig &config);
|
OnlineNeMoCtcModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OnlineNeMoCtcModel() override;
|
~OnlineNeMoCtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -38,8 +42,8 @@ class OnlineParaformerModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OnlineModelConfig &config)
|
Impl(Manager *mgr, const OnlineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -54,7 +58,6 @@ class OnlineParaformerModel::Impl {
|
|||||||
InitDecoder(buf.data(), buf.size());
|
InitDecoder(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> ForwardEncoder(Ort::Value features,
|
std::vector<Ort::Value> ForwardEncoder(Ort::Value features,
|
||||||
Ort::Value features_length) {
|
Ort::Value features_length) {
|
||||||
@@ -123,7 +126,11 @@ class OnlineParaformerModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
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
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -191,11 +198,10 @@ class OnlineParaformerModel::Impl {
|
|||||||
OnlineParaformerModel::OnlineParaformerModel(const OnlineModelConfig &config)
|
OnlineParaformerModel::OnlineParaformerModel(const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineParaformerModel::OnlineParaformerModel(AAssetManager *mgr,
|
OnlineParaformerModel::OnlineParaformerModel(Manager *mgr,
|
||||||
const OnlineModelConfig &config)
|
const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OnlineParaformerModel::~OnlineParaformerModel() = default;
|
OnlineParaformerModel::~OnlineParaformerModel() = default;
|
||||||
|
|
||||||
@@ -246,4 +252,14 @@ OrtAllocator *OnlineParaformerModel::Allocator() const {
|
|||||||
return impl_->Allocator();
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
|
|
||||||
@@ -22,9 +17,8 @@ class OnlineParaformerModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineParaformerModel(const OnlineModelConfig &config);
|
explicit OnlineParaformerModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineParaformerModel(AAssetManager *mgr, const OnlineModelConfig &config);
|
OnlineParaformerModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OnlineParaformerModel();
|
~OnlineParaformerModel();
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
|
|||||||
InitDecoder();
|
InitDecoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
explicit OnlineRecognizerCtcImpl(AAssetManager *mgr,
|
explicit OnlineRecognizerCtcImpl(Manager *mgr,
|
||||||
const OnlineRecognizerConfig &config)
|
const OnlineRecognizerConfig &config)
|
||||||
: OnlineRecognizerImpl(mgr, config),
|
: OnlineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -104,7 +104,6 @@ class OnlineRecognizerCtcImpl : public OnlineRecognizerImpl {
|
|||||||
|
|
||||||
InitDecoder();
|
InitDecoder();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unique_ptr<OnlineStream> CreateStream() const override {
|
std::unique_ptr<OnlineStream> CreateStream() const override {
|
||||||
auto stream = std::make_unique<OnlineStream>(config_.feat_config);
|
auto stream = std::make_unique<OnlineStream>(config_.feat_config);
|
||||||
|
|||||||
@@ -4,15 +4,18 @@
|
|||||||
|
|
||||||
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
|
||||||
|
|
||||||
|
#include <strstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
#if __ANDROID_API__ >= 9
|
||||||
#include <strstream>
|
|
||||||
|
|
||||||
#include "android/asset_manager.h"
|
#include "android/asset_manager.h"
|
||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "fst/extensions/far/far.h"
|
#include "fst/extensions/far/far.h"
|
||||||
#include "kaldifst/csrc/kaldi-fst-io.h"
|
#include "kaldifst/csrc/kaldi-fst-io.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
@@ -61,9 +64,9 @@ std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
|
std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
|
||||||
AAssetManager *mgr, const OnlineRecognizerConfig &config) {
|
Manager *mgr, const OnlineRecognizerConfig &config) {
|
||||||
if (!config.model_config.transducer.encoder.empty()) {
|
if (!config.model_config.transducer.encoder.empty()) {
|
||||||
Ort::Env env(ORT_LOGGING_LEVEL_ERROR);
|
Ort::Env env(ORT_LOGGING_LEVEL_ERROR);
|
||||||
|
|
||||||
@@ -97,7 +100,6 @@ std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
|
|||||||
SHERPA_ONNX_LOGE("Please specify a model");
|
SHERPA_ONNX_LOGE("Please specify a model");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
OnlineRecognizerImpl::OnlineRecognizerImpl(const OnlineRecognizerConfig &config)
|
OnlineRecognizerImpl::OnlineRecognizerImpl(const OnlineRecognizerConfig &config)
|
||||||
: config_(config) {
|
: config_(config) {
|
||||||
@@ -143,8 +145,8 @@ OnlineRecognizerImpl::OnlineRecognizerImpl(const OnlineRecognizerConfig &config)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineRecognizerImpl::OnlineRecognizerImpl(AAssetManager *mgr,
|
OnlineRecognizerImpl::OnlineRecognizerImpl(Manager *mgr,
|
||||||
const OnlineRecognizerConfig &config)
|
const OnlineRecognizerConfig &config)
|
||||||
: config_(config) {
|
: config_(config) {
|
||||||
if (!config.rule_fsts.empty()) {
|
if (!config.rule_fsts.empty()) {
|
||||||
@@ -189,7 +191,6 @@ OnlineRecognizerImpl::OnlineRecognizerImpl(AAssetManager *mgr,
|
|||||||
} // for (const auto &f : files)
|
} // for (const auto &f : files)
|
||||||
} // if (!config.rule_fars.empty())
|
} // if (!config.rule_fars.empty())
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string OnlineRecognizerImpl::ApplyInverseTextNormalization(
|
std::string OnlineRecognizerImpl::ApplyInverseTextNormalization(
|
||||||
std::string text) const {
|
std::string text) const {
|
||||||
@@ -202,4 +203,20 @@ std::string OnlineRecognizerImpl::ApplyInverseTextNormalization(
|
|||||||
return text;
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#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 "kaldifst/csrc/text-normalizer.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/online-recognizer.h"
|
#include "sherpa-onnx/csrc/online-recognizer.h"
|
||||||
@@ -28,13 +23,12 @@ class OnlineRecognizerImpl {
|
|||||||
static std::unique_ptr<OnlineRecognizerImpl> Create(
|
static std::unique_ptr<OnlineRecognizerImpl> Create(
|
||||||
const OnlineRecognizerConfig &config);
|
const OnlineRecognizerConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineRecognizerImpl(AAssetManager *mgr,
|
OnlineRecognizerImpl(Manager *mgr, const OnlineRecognizerConfig &config);
|
||||||
const OnlineRecognizerConfig &config);
|
|
||||||
|
|
||||||
|
template <typename Manager>
|
||||||
static std::unique_ptr<OnlineRecognizerImpl> Create(
|
static std::unique_ptr<OnlineRecognizerImpl> Create(
|
||||||
AAssetManager *mgr, const OnlineRecognizerConfig &config);
|
Manager *mgr, const OnlineRecognizerConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual ~OnlineRecognizerImpl() = default;
|
virtual ~OnlineRecognizerImpl() = default;
|
||||||
|
|
||||||
|
|||||||
@@ -120,8 +120,8 @@ class OnlineRecognizerParaformerImpl : public OnlineRecognizerImpl {
|
|||||||
config_.feat_config.normalize_samples = false;
|
config_.feat_config.normalize_samples = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
explicit OnlineRecognizerParaformerImpl(AAssetManager *mgr,
|
explicit OnlineRecognizerParaformerImpl(Manager *mgr,
|
||||||
const OnlineRecognizerConfig &config)
|
const OnlineRecognizerConfig &config)
|
||||||
: OnlineRecognizerImpl(mgr, config),
|
: OnlineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -138,7 +138,7 @@ class OnlineRecognizerParaformerImpl : public OnlineRecognizerImpl {
|
|||||||
// [-32768, 32767], so we set normalize_samples to false
|
// [-32768, 32767], so we set normalize_samples to false
|
||||||
config_.feat_config.normalize_samples = false;
|
config_.feat_config.normalize_samples = false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
OnlineRecognizerParaformerImpl(const OnlineRecognizerParaformerImpl &) =
|
OnlineRecognizerParaformerImpl(const OnlineRecognizerParaformerImpl &) =
|
||||||
delete;
|
delete;
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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/file-utils.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/online-lm.h"
|
#include "sherpa-onnx/csrc/online-lm.h"
|
||||||
@@ -130,8 +125,8 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
explicit OnlineRecognizerTransducerImpl(AAssetManager *mgr,
|
explicit OnlineRecognizerTransducerImpl(Manager *mgr,
|
||||||
const OnlineRecognizerConfig &config)
|
const OnlineRecognizerConfig &config)
|
||||||
: OnlineRecognizerImpl(mgr, config),
|
: OnlineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -178,7 +173,6 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unique_ptr<OnlineStream> CreateStream() const override {
|
std::unique_ptr<OnlineStream> CreateStream() const override {
|
||||||
auto stream =
|
auto stream =
|
||||||
@@ -429,8 +423,8 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
|
|||||||
hotwords_, config_.hotwords_score, boost_scores_);
|
hotwords_, config_.hotwords_score, boost_scores_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
void InitHotwords(AAssetManager *mgr) {
|
void InitHotwords(Manager *mgr) {
|
||||||
// each line in hotwords_file contains space-separated words
|
// each line in hotwords_file contains space-separated words
|
||||||
|
|
||||||
auto buf = ReadFile(mgr, config_.hotwords_file);
|
auto buf = ReadFile(mgr, config_.hotwords_file);
|
||||||
@@ -452,7 +446,6 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
|
|||||||
hotwords_graph_ = std::make_shared<ContextGraph>(
|
hotwords_graph_ = std::make_shared<ContextGraph>(
|
||||||
hotwords_, config_.hotwords_score, boost_scores_);
|
hotwords_, config_.hotwords_score, boost_scores_);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void InitHotwordsFromBufStr() {
|
void InitHotwordsFromBufStr() {
|
||||||
// each line in hotwords_file contains space-separated words
|
// each line in hotwords_file contains space-separated words
|
||||||
|
|||||||
@@ -16,11 +16,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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/macros.h"
|
||||||
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
|
||||||
#include "sherpa-onnx/csrc/online-recognizer.h"
|
#include "sherpa-onnx/csrc/online-recognizer.h"
|
||||||
@@ -65,9 +60,9 @@ class OnlineRecognizerTransducerNeMoImpl : public OnlineRecognizerImpl {
|
|||||||
PostInit();
|
PostInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
explicit OnlineRecognizerTransducerNeMoImpl(
|
explicit OnlineRecognizerTransducerNeMoImpl(
|
||||||
AAssetManager *mgr, const OnlineRecognizerConfig &config)
|
Manager *mgr, const OnlineRecognizerConfig &config)
|
||||||
: OnlineRecognizerImpl(mgr, config),
|
: OnlineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
symbol_table_(mgr, config.model_config.tokens),
|
symbol_table_(mgr, config.model_config.tokens),
|
||||||
@@ -85,7 +80,6 @@ class OnlineRecognizerTransducerNeMoImpl : public OnlineRecognizerImpl {
|
|||||||
|
|
||||||
PostInit();
|
PostInit();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unique_ptr<OnlineStream> CreateStream() const override {
|
std::unique_ptr<OnlineStream> CreateStream() const override {
|
||||||
auto stream = std::make_unique<OnlineStream>(config_.feat_config);
|
auto stream = std::make_unique<OnlineStream>(config_.feat_config);
|
||||||
|
|||||||
@@ -13,6 +13,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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/file-utils.h"
|
||||||
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/online-recognizer-impl.h"
|
||||||
#include "sherpa-onnx/csrc/text-utils.h"
|
#include "sherpa-onnx/csrc/text-utils.h"
|
||||||
@@ -197,11 +206,10 @@ std::string OnlineRecognizerConfig::ToString() const {
|
|||||||
OnlineRecognizer::OnlineRecognizer(const OnlineRecognizerConfig &config)
|
OnlineRecognizer::OnlineRecognizer(const OnlineRecognizerConfig &config)
|
||||||
: impl_(OnlineRecognizerImpl::Create(config)) {}
|
: impl_(OnlineRecognizerImpl::Create(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineRecognizer::OnlineRecognizer(AAssetManager *mgr,
|
OnlineRecognizer::OnlineRecognizer(Manager *mgr,
|
||||||
const OnlineRecognizerConfig &config)
|
const OnlineRecognizerConfig &config)
|
||||||
: impl_(OnlineRecognizerImpl::Create(mgr, config)) {}
|
: impl_(OnlineRecognizerImpl::Create(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OnlineRecognizer::~OnlineRecognizer() = default;
|
OnlineRecognizer::~OnlineRecognizer() = default;
|
||||||
|
|
||||||
@@ -238,4 +246,14 @@ bool OnlineRecognizer::IsEndpoint(OnlineStream *s) const {
|
|||||||
|
|
||||||
void OnlineRecognizer::Reset(OnlineStream *s) const { impl_->Reset(s); }
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#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/endpoint.h"
|
||||||
#include "sherpa-onnx/csrc/features.h"
|
#include "sherpa-onnx/csrc/features.h"
|
||||||
#include "sherpa-onnx/csrc/online-ctc-fst-decoder-config.h"
|
#include "sherpa-onnx/csrc/online-ctc-fst-decoder-config.h"
|
||||||
@@ -149,9 +144,8 @@ class OnlineRecognizer {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineRecognizer(const OnlineRecognizerConfig &config);
|
explicit OnlineRecognizer(const OnlineRecognizerConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineRecognizer(AAssetManager *mgr, const OnlineRecognizerConfig &config);
|
OnlineRecognizer(Manager *mgr, const OnlineRecognizerConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OnlineRecognizer();
|
~OnlineRecognizer();
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -49,7 +53,11 @@ static ModelType GetModelType(char *model_data, size_t model_data_length,
|
|||||||
if (debug) {
|
if (debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator;
|
Ort::AllocatorWithDefaultOptions allocator;
|
||||||
@@ -155,9 +163,9 @@ Ort::Value OnlineTransducerModel::BuildDecoderInput(
|
|||||||
return decoder_input;
|
return decoder_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
std::unique_ptr<OnlineTransducerModel> OnlineTransducerModel::Create(
|
std::unique_ptr<OnlineTransducerModel> OnlineTransducerModel::Create(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config) {
|
Manager *mgr, const OnlineModelConfig &config) {
|
||||||
if (!config.model_type.empty()) {
|
if (!config.model_type.empty()) {
|
||||||
const auto &model_type = config.model_type;
|
const auto &model_type = config.model_type;
|
||||||
if (model_type == "conformer") {
|
if (model_type == "conformer") {
|
||||||
@@ -195,6 +203,15 @@ std::unique_ptr<OnlineTransducerModel> OnlineTransducerModel::Create(
|
|||||||
// unreachable code
|
// unreachable code
|
||||||
return nullptr;
|
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
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/hypothesis.h"
|
#include "sherpa-onnx/csrc/hypothesis.h"
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
@@ -30,10 +25,9 @@ class OnlineTransducerModel {
|
|||||||
static std::unique_ptr<OnlineTransducerModel> Create(
|
static std::unique_ptr<OnlineTransducerModel> Create(
|
||||||
const OnlineModelConfig &config);
|
const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
static std::unique_ptr<OnlineTransducerModel> Create(
|
static std::unique_ptr<OnlineTransducerModel> Create(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config);
|
Manager *mgr, const OnlineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Stack a list of individual states into a batch.
|
/** Stack a list of individual states into a batch.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -20,6 +20,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/cat.h"
|
#include "sherpa-onnx/csrc/cat.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/online-transducer-decoder.h"
|
#include "sherpa-onnx/csrc/online-transducer-decoder.h"
|
||||||
@@ -54,8 +58,8 @@ class OnlineTransducerNeMoModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OnlineModelConfig &config)
|
Impl(Manager *mgr, const OnlineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -75,7 +79,6 @@ class OnlineTransducerNeMoModel::Impl {
|
|||||||
InitJoiner(buf.data(), buf.size());
|
InitJoiner(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> RunEncoder(Ort::Value features,
|
std::vector<Ort::Value> RunEncoder(Ort::Value features,
|
||||||
std::vector<Ort::Value> states) {
|
std::vector<Ort::Value> states) {
|
||||||
@@ -302,7 +305,11 @@ class OnlineTransducerNeMoModel::Impl {
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
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
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -460,11 +467,10 @@ OnlineTransducerNeMoModel::OnlineTransducerNeMoModel(
|
|||||||
const OnlineModelConfig &config)
|
const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineTransducerNeMoModel::OnlineTransducerNeMoModel(
|
OnlineTransducerNeMoModel::OnlineTransducerNeMoModel(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config)
|
Manager *mgr, const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OnlineTransducerNeMoModel::~OnlineTransducerNeMoModel() = default;
|
OnlineTransducerNeMoModel::~OnlineTransducerNeMoModel() = default;
|
||||||
|
|
||||||
@@ -528,4 +534,14 @@ std::vector<std::vector<Ort::Value>> OnlineTransducerNeMoModel::UnStackStates(
|
|||||||
return impl_->UnStackStates(std::move(states));
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -11,11 +11,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
|
|
||||||
@@ -28,10 +23,8 @@ class OnlineTransducerNeMoModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineTransducerNeMoModel(const OnlineModelConfig &config);
|
explicit OnlineTransducerNeMoModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineTransducerNeMoModel(AAssetManager *mgr,
|
OnlineTransducerNeMoModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
const OnlineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~OnlineTransducerNeMoModel();
|
~OnlineTransducerNeMoModel();
|
||||||
// A list of 3 tensors:
|
// A list of 3 tensors:
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -33,8 +37,8 @@ class OnlineWenetCtcModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OnlineModelConfig &config)
|
Impl(Manager *mgr, const OnlineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -44,7 +48,6 @@ class OnlineWenetCtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value x,
|
std::vector<Ort::Value> Forward(Ort::Value x,
|
||||||
std::vector<Ort::Value> states) {
|
std::vector<Ort::Value> states) {
|
||||||
@@ -139,7 +142,11 @@ class OnlineWenetCtcModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
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
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -212,11 +219,10 @@ class OnlineWenetCtcModel::Impl {
|
|||||||
OnlineWenetCtcModel::OnlineWenetCtcModel(const OnlineModelConfig &config)
|
OnlineWenetCtcModel::OnlineWenetCtcModel(const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineWenetCtcModel::OnlineWenetCtcModel(AAssetManager *mgr,
|
OnlineWenetCtcModel::OnlineWenetCtcModel(Manager *mgr,
|
||||||
const OnlineModelConfig &config)
|
const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OnlineWenetCtcModel::~OnlineWenetCtcModel() = default;
|
OnlineWenetCtcModel::~OnlineWenetCtcModel() = default;
|
||||||
|
|
||||||
@@ -258,4 +264,14 @@ std::vector<std::vector<Ort::Value>> OnlineWenetCtcModel::UnStackStates(
|
|||||||
return ans;
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-ctc-model.h"
|
#include "sherpa-onnx/csrc/online-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
@@ -23,9 +18,8 @@ class OnlineWenetCtcModel : public OnlineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineWenetCtcModel(const OnlineModelConfig &config);
|
explicit OnlineWenetCtcModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineWenetCtcModel(AAssetManager *mgr, const OnlineModelConfig &config);
|
OnlineWenetCtcModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OnlineWenetCtcModel() override;
|
~OnlineWenetCtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/cat.h"
|
#include "sherpa-onnx/csrc/cat.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
@@ -50,9 +54,9 @@ OnlineZipformerTransducerModel::OnlineZipformerTransducerModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineZipformerTransducerModel::OnlineZipformerTransducerModel(
|
OnlineZipformerTransducerModel::OnlineZipformerTransducerModel(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config)
|
Manager *mgr, const OnlineModelConfig &config)
|
||||||
: env_(ORT_LOGGING_LEVEL_ERROR),
|
: env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
config_(config),
|
config_(config),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -72,7 +76,6 @@ OnlineZipformerTransducerModel::OnlineZipformerTransducerModel(
|
|||||||
InitJoiner(buf.data(), buf.size());
|
InitJoiner(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void OnlineZipformerTransducerModel::InitEncoder(void *model_data,
|
void OnlineZipformerTransducerModel::InitEncoder(void *model_data,
|
||||||
size_t model_data_length) {
|
size_t model_data_length) {
|
||||||
@@ -91,7 +94,11 @@ void OnlineZipformerTransducerModel::InitEncoder(void *model_data,
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
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]);
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
||||||
@@ -24,10 +19,8 @@ class OnlineZipformerTransducerModel : public OnlineTransducerModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineZipformerTransducerModel(const OnlineModelConfig &config);
|
explicit OnlineZipformerTransducerModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineZipformerTransducerModel(AAssetManager *mgr,
|
OnlineZipformerTransducerModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
const OnlineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> StackStates(
|
std::vector<Ort::Value> StackStates(
|
||||||
const std::vector<std::vector<Ort::Value>> &states) const override;
|
const std::vector<std::vector<Ort::Value>> &states) const override;
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/cat.h"
|
#include "sherpa-onnx/csrc/cat.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
@@ -37,8 +41,8 @@ class OnlineZipformer2CtcModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OnlineModelConfig &config)
|
Impl(Manager *mgr, const OnlineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -48,7 +52,6 @@ class OnlineZipformer2CtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value features,
|
std::vector<Ort::Value> Forward(Ort::Value features,
|
||||||
std::vector<Ort::Value> states) {
|
std::vector<Ort::Value> states) {
|
||||||
@@ -255,7 +258,11 @@ class OnlineZipformer2CtcModel::Impl {
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---zipformer2_ctc---\n";
|
os << "---zipformer2_ctc---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -415,11 +422,10 @@ OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
|
|||||||
const OnlineModelConfig &config)
|
const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
|
OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config)
|
Manager *mgr, const OnlineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OnlineZipformer2CtcModel::~OnlineZipformer2CtcModel() = default;
|
OnlineZipformer2CtcModel::~OnlineZipformer2CtcModel() = default;
|
||||||
|
|
||||||
@@ -458,4 +464,14 @@ std::vector<std::vector<Ort::Value>> OnlineZipformer2CtcModel::UnStackStates(
|
|||||||
return impl_->UnStackStates(std::move(states));
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-ctc-model.h"
|
#include "sherpa-onnx/csrc/online-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
@@ -23,9 +18,8 @@ class OnlineZipformer2CtcModel : public OnlineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineZipformer2CtcModel(const OnlineModelConfig &config);
|
explicit OnlineZipformer2CtcModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineZipformer2CtcModel(AAssetManager *mgr, const OnlineModelConfig &config);
|
OnlineZipformer2CtcModel(Manager *mgr, const OnlineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OnlineZipformer2CtcModel() override;
|
~OnlineZipformer2CtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/cat.h"
|
#include "sherpa-onnx/csrc/cat.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
@@ -54,9 +58,9 @@ OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
|
OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
|
||||||
AAssetManager *mgr, const OnlineModelConfig &config)
|
Manager *mgr, const OnlineModelConfig &config)
|
||||||
: env_(ORT_LOGGING_LEVEL_ERROR),
|
: env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
config_(config),
|
config_(config),
|
||||||
encoder_sess_opts_(GetSessionOptions(config)),
|
encoder_sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -78,7 +82,6 @@ OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
|
|||||||
InitJoiner(buf.data(), buf.size());
|
InitJoiner(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void OnlineZipformer2TransducerModel::InitEncoder(void *model_data,
|
void OnlineZipformer2TransducerModel::InitEncoder(void *model_data,
|
||||||
size_t model_data_length) {
|
size_t model_data_length) {
|
||||||
@@ -97,7 +100,11 @@ void OnlineZipformer2TransducerModel::InitEncoder(void *model_data,
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
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]);
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/online-model-config.h"
|
#include "sherpa-onnx/csrc/online-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
||||||
@@ -24,10 +19,9 @@ class OnlineZipformer2TransducerModel : public OnlineTransducerModel {
|
|||||||
public:
|
public:
|
||||||
explicit OnlineZipformer2TransducerModel(const OnlineModelConfig &config);
|
explicit OnlineZipformer2TransducerModel(const OnlineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OnlineZipformer2TransducerModel(AAssetManager *mgr,
|
OnlineZipformer2TransducerModel(Manager *mgr,
|
||||||
const OnlineModelConfig &config);
|
const OnlineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> StackStates(
|
std::vector<Ort::Value> StackStates(
|
||||||
const std::vector<std::vector<Ort::Value>> &states) const override;
|
const std::vector<std::vector<Ort::Value>> &states) const override;
|
||||||
|
|||||||
@@ -8,16 +8,16 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <strstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
#if __ANDROID_API__ >= 9
|
||||||
#include <strstream>
|
|
||||||
|
|
||||||
#include "android/asset_manager.h"
|
#include "android/asset_manager.h"
|
||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#elif __OHOS__
|
#endif
|
||||||
#include <strstream>
|
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
#include "rawfile/raw_file_manager.h"
|
#include "rawfile/raw_file_manager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "sherpa-onnx/python/csrc/vad-model.h"
|
#include "sherpa-onnx/python/csrc/vad-model.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/vad-model.h"
|
#include "sherpa-onnx/csrc/vad-model.h"
|
||||||
@@ -13,8 +14,10 @@ namespace sherpa_onnx {
|
|||||||
void PybindVadModel(py::module *m) {
|
void PybindVadModel(py::module *m) {
|
||||||
using PyClass = VadModel;
|
using PyClass = VadModel;
|
||||||
py::class_<PyClass>(*m, "VadModel")
|
py::class_<PyClass>(*m, "VadModel")
|
||||||
.def_static("create", &PyClass::Create, py::arg("config"),
|
.def_static("create",
|
||||||
py::call_guard<py::gil_scoped_release>())
|
(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("reset", &PyClass::Reset, py::call_guard<py::gil_scoped_release>())
|
||||||
.def(
|
.def(
|
||||||
"is_speech",
|
"is_speech",
|
||||||
|
|||||||
Reference in New Issue
Block a user