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

@@ -19,6 +19,10 @@
#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/cat.h"
#include "sherpa-onnx/csrc/macros.h"
@@ -54,9 +58,9 @@ OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
}
}
#if __ANDROID_API__ >= 9
template <typename Manager>
OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
AAssetManager *mgr, const OnlineModelConfig &config)
Manager *mgr, const OnlineModelConfig &config)
: env_(ORT_LOGGING_LEVEL_ERROR),
config_(config),
encoder_sess_opts_(GetSessionOptions(config)),
@@ -78,7 +82,6 @@ OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
InitJoiner(buf.data(), buf.size());
}
}
#endif
void OnlineZipformer2TransducerModel::InitEncoder(void *model_data,
size_t model_data_length) {
@@ -97,7 +100,11 @@ void OnlineZipformer2TransducerModel::InitEncoder(void *model_data,
std::ostringstream os;
os << "---encoder---\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
@@ -474,4 +481,14 @@ Ort::Value OnlineZipformer2TransducerModel::RunJoiner(Ort::Value encoder_out,
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