Add two-pass speech recognition Android/iOS demo (#304)
This commit is contained in:
@@ -11,8 +11,8 @@
|
||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||
#include "sherpa-onnx/csrc/macros.h"
|
||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||
#include "sherpa-onnx/csrc/text-utils.h"
|
||||
#include "sherpa-onnx/csrc/session.h"
|
||||
#include "sherpa-onnx/csrc/text-utils.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
@@ -23,9 +23,21 @@ class OfflineRnnLM::Impl {
|
||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||
sess_opts_{GetSessionOptions(config)},
|
||||
allocator_{} {
|
||||
Init(config);
|
||||
auto buf = ReadFile(config_.model);
|
||||
Init(buf.data(), buf.size());
|
||||
}
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
Impl(AAssetManager *mgr, const OfflineLMConfig &config)
|
||||
: config_(config),
|
||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||
sess_opts_{GetSessionOptions(config)},
|
||||
allocator_{} {
|
||||
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)};
|
||||
|
||||
@@ -37,10 +49,8 @@ class OfflineRnnLM::Impl {
|
||||
}
|
||||
|
||||
private:
|
||||
void Init(const OfflineLMConfig &config) {
|
||||
auto buf = ReadFile(config_.model);
|
||||
|
||||
sess_ = std::make_unique<Ort::Session>(env_, buf.data(), buf.size(),
|
||||
void Init(void *model_data, size_t model_data_length) {
|
||||
sess_ = std::make_unique<Ort::Session>(env_, model_data, model_data_length,
|
||||
sess_opts_);
|
||||
|
||||
GetInputNames(sess_.get(), &input_names_, &input_names_ptr_);
|
||||
@@ -66,6 +76,11 @@ 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)
|
||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||
#endif
|
||||
|
||||
OfflineRnnLM::~OfflineRnnLM() = default;
|
||||
|
||||
Ort::Value OfflineRnnLM::Rescore(Ort::Value x, Ort::Value x_lens) {
|
||||
|
||||
Reference in New Issue
Block a user