Add streaming ASR support for HarmonyOS. (#1565)

This commit is contained in:
Fangjun Kuang
2024-11-26 18:36:56 +08:00
committed by GitHub
parent 298b6b6fda
commit 2101227269
35 changed files with 367 additions and 206 deletions

View File

@@ -13,6 +13,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
#include "sherpa-onnx/csrc/session.h"
@@ -38,8 +42,8 @@ class OnlineParaformerModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl(AAssetManager *mgr, const OnlineModelConfig &config)
template <typename Manager>
Impl(Manager *mgr, const OnlineModelConfig &config)
: config_(config),
env_(ORT_LOGGING_LEVEL_ERROR),
sess_opts_(GetSessionOptions(config)),
@@ -54,7 +58,6 @@ class OnlineParaformerModel::Impl {
InitDecoder(buf.data(), buf.size());
}
}
#endif
std::vector<Ort::Value> ForwardEncoder(Ort::Value features,
Ort::Value features_length) {
@@ -123,7 +126,11 @@ class OnlineParaformerModel::Impl {
if (config_.debug) {
std::ostringstream os;
PrintModelMetadata(os, meta_data);
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
#if __OHOS__
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
#else
SHERPA_ONNX_LOGE("%s", os.str().c_str());
#endif
}
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
@@ -191,11 +198,10 @@ class OnlineParaformerModel::Impl {
OnlineParaformerModel::OnlineParaformerModel(const OnlineModelConfig &config)
: impl_(std::make_unique<Impl>(config)) {}
#if __ANDROID_API__ >= 9
OnlineParaformerModel::OnlineParaformerModel(AAssetManager *mgr,
template <typename Manager>
OnlineParaformerModel::OnlineParaformerModel(Manager *mgr,
const OnlineModelConfig &config)
: impl_(std::make_unique<Impl>(mgr, config)) {}
#endif
OnlineParaformerModel::~OnlineParaformerModel() = default;
@@ -246,4 +252,14 @@ OrtAllocator *OnlineParaformerModel::Allocator() const {
return impl_->Allocator();
}
#if __ANDROID_API__ >= 9
template OnlineParaformerModel::OnlineParaformerModel(
AAssetManager *mgr, const OnlineModelConfig &config);
#endif
#if __OHOS__
template OnlineParaformerModel::OnlineParaformerModel(
NativeResourceManager *mgr, const OnlineModelConfig &config);
#endif
} // namespace sherpa_onnx