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

@@ -15,6 +15,10 @@
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/cat.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
@@ -37,8 +41,8 @@ class OnlineZipformer2CtcModel::Impl {
}
}
#if __ANDROID_API__ >= 9
Impl(AAssetManager *mgr, const OnlineModelConfig &config)
template <typename Manager>
Impl(Manager *mgr, const OnlineModelConfig &config)
: config_(config),
env_(ORT_LOGGING_LEVEL_ERROR),
sess_opts_(GetSessionOptions(config)),
@@ -48,7 +52,6 @@ class OnlineZipformer2CtcModel::Impl {
Init(buf.data(), buf.size());
}
}
#endif
std::vector<Ort::Value> Forward(Ort::Value features,
std::vector<Ort::Value> states) {
@@ -255,7 +258,11 @@ class OnlineZipformer2CtcModel::Impl {
std::ostringstream os;
os << "---zipformer2_ctc---\n";
PrintModelMetadata(os, meta_data);
#if __OHOS__
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
#else
SHERPA_ONNX_LOGE("%s", os.str().c_str());
#endif
}
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
@@ -415,11 +422,10 @@ OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
const OnlineModelConfig &config)
: impl_(std::make_unique<Impl>(config)) {}
#if __ANDROID_API__ >= 9
template <typename Manager>
OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
AAssetManager *mgr, const OnlineModelConfig &config)
Manager *mgr, const OnlineModelConfig &config)
: impl_(std::make_unique<Impl>(mgr, config)) {}
#endif
OnlineZipformer2CtcModel::~OnlineZipformer2CtcModel() = default;
@@ -458,4 +464,14 @@ std::vector<std::vector<Ort::Value>> OnlineZipformer2CtcModel::UnStackStates(
return impl_->UnStackStates(std::move(states));
}
#if __ANDROID_API__ >= 9
template OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
AAssetManager *mgr, const OnlineModelConfig &config);
#endif
#if __OHOS__
template OnlineZipformer2CtcModel::OnlineZipformer2CtcModel(
NativeResourceManager *mgr, const OnlineModelConfig &config);
#endif
} // namespace sherpa_onnx