Add non-streaming ASR support for HarmonyOS. (#1564)

This commit is contained in:
Fangjun Kuang
2024-11-26 16:38:35 +08:00
committed by GitHub
parent a4b79f077c
commit 298b6b6fda
50 changed files with 648 additions and 454 deletions

View File

@@ -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