Add non-streaming ASR support for HarmonyOS. (#1564)
This commit is contained in:
@@ -352,27 +352,7 @@ struct SherpaOnnxOfflineStream {
|
|||||||
: impl(std::move(p)) {}
|
: impl(std::move(p)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
static sherpa_onnx::OfflineRecognizerConfig convertConfig(
|
static sherpa_onnx::OfflineRecognizerConfig GetOfflineRecognizerConfig(
|
||||||
const SherpaOnnxOfflineRecognizerConfig *config);
|
|
||||||
|
|
||||||
const SherpaOnnxOfflineRecognizer *SherpaOnnxCreateOfflineRecognizer(
|
|
||||||
const SherpaOnnxOfflineRecognizerConfig *config) {
|
|
||||||
sherpa_onnx::OfflineRecognizerConfig recognizer_config =
|
|
||||||
convertConfig(config);
|
|
||||||
|
|
||||||
if (!recognizer_config.Validate()) {
|
|
||||||
SHERPA_ONNX_LOGE("Errors in config");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
SherpaOnnxOfflineRecognizer *recognizer = new SherpaOnnxOfflineRecognizer;
|
|
||||||
|
|
||||||
recognizer->impl =
|
|
||||||
std::make_unique<sherpa_onnx::OfflineRecognizer>(recognizer_config);
|
|
||||||
|
|
||||||
return recognizer;
|
|
||||||
}
|
|
||||||
sherpa_onnx::OfflineRecognizerConfig convertConfig(
|
|
||||||
const SherpaOnnxOfflineRecognizerConfig *config) {
|
const SherpaOnnxOfflineRecognizerConfig *config) {
|
||||||
sherpa_onnx::OfflineRecognizerConfig recognizer_config;
|
sherpa_onnx::OfflineRecognizerConfig recognizer_config;
|
||||||
|
|
||||||
@@ -491,17 +471,39 @@ sherpa_onnx::OfflineRecognizerConfig convertConfig(
|
|||||||
recognizer_config.rule_fars = SHERPA_ONNX_OR(config->rule_fars, "");
|
recognizer_config.rule_fars = SHERPA_ONNX_OR(config->rule_fars, "");
|
||||||
|
|
||||||
if (config->model_config.debug) {
|
if (config->model_config.debug) {
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s", recognizer_config.ToString().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s", recognizer_config.ToString().c_str());
|
SHERPA_ONNX_LOGE("%s", recognizer_config.ToString().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return recognizer_config;
|
return recognizer_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SherpaOnnxOfflineRecognizer *SherpaOnnxCreateOfflineRecognizer(
|
||||||
|
const SherpaOnnxOfflineRecognizerConfig *config) {
|
||||||
|
sherpa_onnx::OfflineRecognizerConfig recognizer_config =
|
||||||
|
GetOfflineRecognizerConfig(config);
|
||||||
|
|
||||||
|
if (!recognizer_config.Validate()) {
|
||||||
|
SHERPA_ONNX_LOGE("Errors in config");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
SherpaOnnxOfflineRecognizer *recognizer = new SherpaOnnxOfflineRecognizer;
|
||||||
|
|
||||||
|
recognizer->impl =
|
||||||
|
std::make_unique<sherpa_onnx::OfflineRecognizer>(recognizer_config);
|
||||||
|
|
||||||
|
return recognizer;
|
||||||
|
}
|
||||||
|
|
||||||
void SherpaOnnxOfflineRecognizerSetConfig(
|
void SherpaOnnxOfflineRecognizerSetConfig(
|
||||||
const SherpaOnnxOfflineRecognizer *recognizer,
|
const SherpaOnnxOfflineRecognizer *recognizer,
|
||||||
const SherpaOnnxOfflineRecognizerConfig *config) {
|
const SherpaOnnxOfflineRecognizerConfig *config) {
|
||||||
sherpa_onnx::OfflineRecognizerConfig recognizer_config =
|
sherpa_onnx::OfflineRecognizerConfig recognizer_config =
|
||||||
convertConfig(config);
|
GetOfflineRecognizerConfig(config);
|
||||||
recognizer->impl->SetConfig(recognizer_config);
|
recognizer->impl->SetConfig(recognizer_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -977,25 +979,6 @@ SherpaOnnxVoiceActivityDetector *SherpaOnnxCreateVoiceActivityDetector(
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __OHOS__
|
|
||||||
SherpaOnnxVoiceActivityDetector *SherpaOnnxCreateVoiceActivityDetectorOHOS(
|
|
||||||
const SherpaOnnxVadModelConfig *config, float buffer_size_in_seconds,
|
|
||||||
NativeResourceManager *mgr) {
|
|
||||||
if (mgr == nullptr) {
|
|
||||||
return SherpaOnnxCreateVoiceActivityDetector(config,
|
|
||||||
buffer_size_in_seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto vad_config = GetVadModelConfig(config);
|
|
||||||
|
|
||||||
SherpaOnnxVoiceActivityDetector *p = new SherpaOnnxVoiceActivityDetector;
|
|
||||||
p->impl = std::make_unique<sherpa_onnx::VoiceActivityDetector>(
|
|
||||||
mgr, vad_config, buffer_size_in_seconds);
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SherpaOnnxDestroyVoiceActivityDetector(
|
void SherpaOnnxDestroyVoiceActivityDetector(
|
||||||
SherpaOnnxVoiceActivityDetector *p) {
|
SherpaOnnxVoiceActivityDetector *p) {
|
||||||
delete p;
|
delete p;
|
||||||
@@ -1891,4 +1874,42 @@ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
|
|||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __OHOS__
|
||||||
|
|
||||||
|
const SherpaOnnxOfflineRecognizer *SherpaOnnxCreateOfflineRecognizerOHOS(
|
||||||
|
const SherpaOnnxOfflineRecognizerConfig *config,
|
||||||
|
NativeResourceManager *mgr) {
|
||||||
|
if (mgr == nullptr) {
|
||||||
|
return SherpaOnnxCreateOfflineRecognizer(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
sherpa_onnx::OfflineRecognizerConfig recognizer_config =
|
||||||
|
GetOfflineRecognizerConfig(config);
|
||||||
|
|
||||||
|
SherpaOnnxOfflineRecognizer *recognizer = new SherpaOnnxOfflineRecognizer;
|
||||||
|
|
||||||
|
recognizer->impl =
|
||||||
|
std::make_unique<sherpa_onnx::OfflineRecognizer>(mgr, recognizer_config);
|
||||||
|
|
||||||
|
return recognizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
SherpaOnnxVoiceActivityDetector *SherpaOnnxCreateVoiceActivityDetectorOHOS(
|
||||||
|
const SherpaOnnxVadModelConfig *config, float buffer_size_in_seconds,
|
||||||
|
NativeResourceManager *mgr) {
|
||||||
|
if (mgr == nullptr) {
|
||||||
|
return SherpaOnnxCreateVoiceActivityDetector(config,
|
||||||
|
buffer_size_in_seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto vad_config = GetVadModelConfig(config);
|
||||||
|
|
||||||
|
SherpaOnnxVoiceActivityDetector *p = new SherpaOnnxVoiceActivityDetector;
|
||||||
|
p->impl = std::make_unique<sherpa_onnx::VoiceActivityDetector>(
|
||||||
|
mgr, vad_config, buffer_size_in_seconds);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -841,21 +841,6 @@ SHERPA_ONNX_API SherpaOnnxVoiceActivityDetector *
|
|||||||
SherpaOnnxCreateVoiceActivityDetector(const SherpaOnnxVadModelConfig *config,
|
SherpaOnnxCreateVoiceActivityDetector(const SherpaOnnxVadModelConfig *config,
|
||||||
float buffer_size_in_seconds);
|
float buffer_size_in_seconds);
|
||||||
|
|
||||||
#ifdef __OHOS__
|
|
||||||
|
|
||||||
// Return an instance of VoiceActivityDetector.
|
|
||||||
// The user has to use SherpaOnnxDestroyVoiceActivityDetector() to free
|
|
||||||
// the returned pointer to avoid memory leak.
|
|
||||||
//
|
|
||||||
// It is for HarmonyOS
|
|
||||||
typedef struct NativeResourceManager NativeResourceManager;
|
|
||||||
|
|
||||||
SHERPA_ONNX_API SherpaOnnxVoiceActivityDetector *
|
|
||||||
SherpaOnnxCreateVoiceActivityDetectorOHOS(
|
|
||||||
const SherpaOnnxVadModelConfig *config, float buffer_size_in_seconds,
|
|
||||||
NativeResourceManager *mgr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SHERPA_ONNX_API void SherpaOnnxDestroyVoiceActivityDetector(
|
SHERPA_ONNX_API void SherpaOnnxDestroyVoiceActivityDetector(
|
||||||
SherpaOnnxVoiceActivityDetector *p);
|
SherpaOnnxVoiceActivityDetector *p);
|
||||||
|
|
||||||
@@ -1537,6 +1522,29 @@ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
|
|||||||
SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationDestroyResult(
|
SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationDestroyResult(
|
||||||
const SherpaOnnxOfflineSpeakerDiarizationResult *r);
|
const SherpaOnnxOfflineSpeakerDiarizationResult *r);
|
||||||
|
|
||||||
|
#ifdef __OHOS__
|
||||||
|
|
||||||
|
// It is for HarmonyOS
|
||||||
|
typedef struct NativeResourceManager NativeResourceManager;
|
||||||
|
|
||||||
|
/// @param config Config for the recognizer.
|
||||||
|
/// @return Return a pointer to the recognizer. The user has to invoke
|
||||||
|
// SherpaOnnxDestroyOfflineRecognizer() to free it to avoid memory
|
||||||
|
// leak.
|
||||||
|
SHERPA_ONNX_API const SherpaOnnxOfflineRecognizer *
|
||||||
|
SherpaOnnxCreateOfflineRecognizerOHOS(
|
||||||
|
const SherpaOnnxOfflineRecognizerConfig *config,
|
||||||
|
NativeResourceManager *mgr);
|
||||||
|
|
||||||
|
// Return an instance of VoiceActivityDetector.
|
||||||
|
// The user has to use SherpaOnnxDestroyVoiceActivityDetector() to free
|
||||||
|
// the returned pointer to avoid memory leak.
|
||||||
|
SHERPA_ONNX_API SherpaOnnxVoiceActivityDetector *
|
||||||
|
SherpaOnnxCreateVoiceActivityDetectorOHOS(
|
||||||
|
const SherpaOnnxVadModelConfig *config, float buffer_size_in_seconds,
|
||||||
|
NativeResourceManager *mgr);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -214,11 +214,6 @@ struct SHERPA_ONNX_API OfflineTdnnModelConfig {
|
|||||||
std::string model;
|
std::string model;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SHERPA_ONNX_API SherpaOnnxOfflineLMConfig {
|
|
||||||
std::string model;
|
|
||||||
float scale = 1.0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SHERPA_ONNX_API OfflineSenseVoiceModelConfig {
|
struct SHERPA_ONNX_API OfflineSenseVoiceModelConfig {
|
||||||
std::string model;
|
std::string model;
|
||||||
std::string language;
|
std::string language;
|
||||||
|
|||||||
@@ -9,6 +9,15 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/offline-tdnn-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-tdnn-ctc-model.h"
|
||||||
@@ -48,7 +57,11 @@ static ModelType GetModelType(char *model_data, size_t model_data_length,
|
|||||||
if (debug) {
|
if (debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
SHERPA_ONNX_LOGE("%s", os.str().c_str());
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator;
|
Ort::AllocatorWithDefaultOptions allocator;
|
||||||
@@ -144,10 +157,9 @@ std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
|
|
||||||
std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
|
std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
|
||||||
AAssetManager *mgr, const OfflineModelConfig &config) {
|
Manager *mgr, const OfflineModelConfig &config) {
|
||||||
// TODO(fangjun): Refactor it. We don't need to use model_type here
|
// TODO(fangjun): Refactor it. We don't need to use model_type here
|
||||||
ModelType model_type = ModelType::kUnknown;
|
ModelType model_type = ModelType::kUnknown;
|
||||||
|
|
||||||
@@ -196,6 +208,15 @@ std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
|
|
||||||
@@ -25,10 +20,9 @@ class OfflineCtcModel {
|
|||||||
static std::unique_ptr<OfflineCtcModel> Create(
|
static std::unique_ptr<OfflineCtcModel> Create(
|
||||||
const OfflineModelConfig &config);
|
const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
static std::unique_ptr<OfflineCtcModel> Create(
|
static std::unique_ptr<OfflineCtcModel> Create(
|
||||||
AAssetManager *mgr, const OfflineModelConfig &config);
|
Manager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Run the forward method of the model.
|
/** Run the forward method of the model.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "sherpa-onnx/csrc/offline-rnn-lm.h"
|
#include "sherpa-onnx/csrc/offline-rnn-lm.h"
|
||||||
|
|
||||||
namespace sherpa_onnx {
|
namespace sherpa_onnx {
|
||||||
@@ -16,12 +25,11 @@ std::unique_ptr<OfflineLM> OfflineLM::Create(const OfflineLMConfig &config) {
|
|||||||
return std::make_unique<OfflineRnnLM>(config);
|
return std::make_unique<OfflineRnnLM>(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
std::unique_ptr<OfflineLM> OfflineLM::Create(AAssetManager *mgr,
|
std::unique_ptr<OfflineLM> OfflineLM::Create(Manager *mgr,
|
||||||
const OfflineLMConfig &config) {
|
const OfflineLMConfig &config) {
|
||||||
return std::make_unique<OfflineRnnLM>(mgr, config);
|
return std::make_unique<OfflineRnnLM>(mgr, config);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void OfflineLM::ComputeLMScore(float scale, int32_t context_size,
|
void OfflineLM::ComputeLMScore(float scale, int32_t context_size,
|
||||||
std::vector<Hypotheses> *hyps) {
|
std::vector<Hypotheses> *hyps) {
|
||||||
@@ -75,4 +83,14 @@ void OfflineLM::ComputeLMScore(float scale, int32_t context_size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template std::unique_ptr<OfflineLM> OfflineLM::Create(
|
||||||
|
AAssetManager *mgr, const OfflineLMConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template std::unique_ptr<OfflineLM> OfflineLM::Create(
|
||||||
|
NativeResourceManager *mgr, const OfflineLMConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/hypothesis.h"
|
#include "sherpa-onnx/csrc/hypothesis.h"
|
||||||
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
||||||
@@ -25,10 +20,9 @@ class OfflineLM {
|
|||||||
|
|
||||||
static std::unique_ptr<OfflineLM> Create(const OfflineLMConfig &config);
|
static std::unique_ptr<OfflineLM> Create(const OfflineLMConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
static std::unique_ptr<OfflineLM> Create(AAssetManager *mgr,
|
static std::unique_ptr<OfflineLM> Create(Manager *mgr,
|
||||||
const OfflineLMConfig &config);
|
const OfflineLMConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Rescore a batch of sentences.
|
/** Rescore a batch of sentences.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -43,8 +52,8 @@ class OfflineMoonshineModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -69,7 +78,6 @@ class OfflineMoonshineModel::Impl {
|
|||||||
InitCachedDecoder(buf.data(), buf.size());
|
InitCachedDecoder(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
Ort::Value ForwardPreprocessor(Ort::Value audio) {
|
Ort::Value ForwardPreprocessor(Ort::Value audio) {
|
||||||
auto features = preprocessor_sess_->Run(
|
auto features = preprocessor_sess_->Run(
|
||||||
@@ -242,11 +250,10 @@ class OfflineMoonshineModel::Impl {
|
|||||||
OfflineMoonshineModel::OfflineMoonshineModel(const OfflineModelConfig &config)
|
OfflineMoonshineModel::OfflineMoonshineModel(const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineMoonshineModel::OfflineMoonshineModel(AAssetManager *mgr,
|
OfflineMoonshineModel::OfflineMoonshineModel(Manager *mgr,
|
||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineMoonshineModel::~OfflineMoonshineModel() = default;
|
OfflineMoonshineModel::~OfflineMoonshineModel() = default;
|
||||||
|
|
||||||
@@ -279,4 +286,14 @@ OrtAllocator *OfflineMoonshineModel::Allocator() const {
|
|||||||
return impl_->Allocator();
|
return impl_->Allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineMoonshineModel::OfflineMoonshineModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineMoonshineModel::OfflineMoonshineModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
|
|
||||||
@@ -25,9 +20,8 @@ class OfflineMoonshineModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineMoonshineModel(const OfflineModelConfig &config);
|
explicit OfflineMoonshineModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineMoonshineModel(AAssetManager *mgr, const OfflineModelConfig &config);
|
OfflineMoonshineModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineMoonshineModel();
|
~OfflineMoonshineModel();
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-nemo-enc-dec-ctc-model.h"
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -23,8 +32,8 @@ class OfflineNemoEncDecCtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -32,7 +41,6 @@ class OfflineNemoEncDecCtcModel::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.nemo_ctc.model);
|
auto buf = ReadFile(mgr, config_.nemo_ctc.model);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value features,
|
std::vector<Ort::Value> Forward(Ort::Value features,
|
||||||
Ort::Value features_length) {
|
Ort::Value features_length) {
|
||||||
@@ -88,7 +96,11 @@ class OfflineNemoEncDecCtcModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -126,11 +138,10 @@ OfflineNemoEncDecCtcModel::OfflineNemoEncDecCtcModel(
|
|||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineNemoEncDecCtcModel::OfflineNemoEncDecCtcModel(
|
OfflineNemoEncDecCtcModel::OfflineNemoEncDecCtcModel(
|
||||||
AAssetManager *mgr, const OfflineModelConfig &config)
|
Manager *mgr, const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineNemoEncDecCtcModel::~OfflineNemoEncDecCtcModel() = default;
|
OfflineNemoEncDecCtcModel::~OfflineNemoEncDecCtcModel() = default;
|
||||||
|
|
||||||
@@ -156,4 +167,14 @@ std::string OfflineNemoEncDecCtcModel::FeatureNormalizationMethod() const {
|
|||||||
|
|
||||||
bool OfflineNemoEncDecCtcModel::IsGigaAM() const { return impl_->IsGigaAM(); }
|
bool OfflineNemoEncDecCtcModel::IsGigaAM() const { return impl_->IsGigaAM(); }
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineNemoEncDecCtcModel::OfflineNemoEncDecCtcModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineNemoEncDecCtcModel::OfflineNemoEncDecCtcModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
@@ -29,10 +24,8 @@ class OfflineNemoEncDecCtcModel : public OfflineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineNemoEncDecCtcModel(const OfflineModelConfig &config);
|
explicit OfflineNemoEncDecCtcModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineNemoEncDecCtcModel(AAssetManager *mgr,
|
OfflineNemoEncDecCtcModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
const OfflineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineNemoEncDecCtcModel() override;
|
~OfflineNemoEncDecCtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -26,8 +35,8 @@ class OfflineParaformerModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -35,7 +44,6 @@ class OfflineParaformerModel::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.paraformer.model);
|
auto buf = ReadFile(mgr, config_.paraformer.model);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value features,
|
std::vector<Ort::Value> Forward(Ort::Value features,
|
||||||
Ort::Value features_length) {
|
Ort::Value features_length) {
|
||||||
@@ -72,7 +80,11 @@ class OfflineParaformerModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -109,11 +121,10 @@ class OfflineParaformerModel::Impl {
|
|||||||
OfflineParaformerModel::OfflineParaformerModel(const OfflineModelConfig &config)
|
OfflineParaformerModel::OfflineParaformerModel(const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineParaformerModel::OfflineParaformerModel(AAssetManager *mgr,
|
OfflineParaformerModel::OfflineParaformerModel(Manager *mgr,
|
||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineParaformerModel::~OfflineParaformerModel() = default;
|
OfflineParaformerModel::~OfflineParaformerModel() = default;
|
||||||
|
|
||||||
@@ -141,4 +152,14 @@ OrtAllocator *OfflineParaformerModel::Allocator() const {
|
|||||||
return impl_->Allocator();
|
return impl_->Allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineParaformerModel::OfflineParaformerModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineParaformerModel::OfflineParaformerModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
|
|
||||||
@@ -21,9 +16,8 @@ class OfflineParaformerModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineParaformerModel(const OfflineModelConfig &config);
|
explicit OfflineParaformerModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineParaformerModel(AAssetManager *mgr, const OfflineModelConfig &config);
|
OfflineParaformerModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineParaformerModel();
|
~OfflineParaformerModel();
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-decoder.h"
|
#include "sherpa-onnx/csrc/offline-ctc-decoder.h"
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-fst-decoder.h"
|
#include "sherpa-onnx/csrc/offline-ctc-fst-decoder.h"
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-greedy-search-decoder.h"
|
#include "sherpa-onnx/csrc/offline-ctc-greedy-search-decoder.h"
|
||||||
@@ -80,16 +75,14 @@ class OfflineRecognizerCtcImpl : public OfflineRecognizerImpl {
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizerCtcImpl(AAssetManager *mgr,
|
OfflineRecognizerCtcImpl(Manager *mgr, const OfflineRecognizerConfig &config)
|
||||||
const OfflineRecognizerConfig &config)
|
|
||||||
: OfflineRecognizerImpl(mgr, config),
|
: OfflineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
symbol_table_(mgr, config_.model_config.tokens),
|
symbol_table_(mgr, config_.model_config.tokens),
|
||||||
model_(OfflineCtcModel::Create(mgr, config_.model_config)) {
|
model_(OfflineCtcModel::Create(mgr, config_.model_config)) {
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
if (!config_.model_config.telespeech_ctc.empty()) {
|
if (!config_.model_config.telespeech_ctc.empty()) {
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
|
|
||||||
#include "android/asset_manager.h"
|
#include "android/asset_manager.h"
|
||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
|
#elif __OHOS__
|
||||||
|
#include <strstream>
|
||||||
|
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "fst/extensions/far/far.h"
|
#include "fst/extensions/far/far.h"
|
||||||
@@ -211,9 +215,9 @@ std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
|
std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
|
||||||
AAssetManager *mgr, const OfflineRecognizerConfig &config) {
|
Manager *mgr, const OfflineRecognizerConfig &config) {
|
||||||
if (!config.model_config.sense_voice.model.empty()) {
|
if (!config.model_config.sense_voice.model.empty()) {
|
||||||
return std::make_unique<OfflineRecognizerSenseVoiceImpl>(mgr, config);
|
return std::make_unique<OfflineRecognizerSenseVoiceImpl>(mgr, config);
|
||||||
}
|
}
|
||||||
@@ -389,7 +393,6 @@ std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
|
|||||||
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineRecognizerImpl::OfflineRecognizerImpl(
|
OfflineRecognizerImpl::OfflineRecognizerImpl(
|
||||||
const OfflineRecognizerConfig &config)
|
const OfflineRecognizerConfig &config)
|
||||||
@@ -436,9 +439,9 @@ OfflineRecognizerImpl::OfflineRecognizerImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizerImpl::OfflineRecognizerImpl(
|
OfflineRecognizerImpl::OfflineRecognizerImpl(
|
||||||
AAssetManager *mgr, const OfflineRecognizerConfig &config)
|
Manager *mgr, const OfflineRecognizerConfig &config)
|
||||||
: config_(config) {
|
: config_(config) {
|
||||||
if (!config.rule_fsts.empty()) {
|
if (!config.rule_fsts.empty()) {
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
@@ -482,7 +485,6 @@ OfflineRecognizerImpl::OfflineRecognizerImpl(
|
|||||||
} // for (const auto &f : files)
|
} // for (const auto &f : files)
|
||||||
} // if (!config.rule_fars.empty())
|
} // if (!config.rule_fars.empty())
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string OfflineRecognizerImpl::ApplyInverseTextNormalization(
|
std::string OfflineRecognizerImpl::ApplyInverseTextNormalization(
|
||||||
std::string text) const {
|
std::string text) const {
|
||||||
@@ -499,4 +501,19 @@ void OfflineRecognizerImpl::SetConfig(const OfflineRecognizerConfig &config) {
|
|||||||
config_ = config;
|
config_ = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineRecognizerImpl::OfflineRecognizerImpl(
|
||||||
|
AAssetManager *mgr, const OfflineRecognizerConfig &config);
|
||||||
|
|
||||||
|
template std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
|
||||||
|
AAssetManager *mgr, const OfflineRecognizerConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineRecognizerImpl::OfflineRecognizerImpl(
|
||||||
|
NativeResourceManager *mgr, const OfflineRecognizerConfig &config);
|
||||||
|
template std::unique_ptr<OfflineRecognizerImpl> OfflineRecognizerImpl::Create(
|
||||||
|
NativeResourceManager *mgr, const OfflineRecognizerConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "kaldifst/csrc/text-normalizer.h"
|
#include "kaldifst/csrc/text-normalizer.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
||||||
@@ -28,13 +23,12 @@ class OfflineRecognizerImpl {
|
|||||||
static std::unique_ptr<OfflineRecognizerImpl> Create(
|
static std::unique_ptr<OfflineRecognizerImpl> Create(
|
||||||
const OfflineRecognizerConfig &config);
|
const OfflineRecognizerConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizerImpl(AAssetManager *mgr,
|
OfflineRecognizerImpl(Manager *mgr, const OfflineRecognizerConfig &config);
|
||||||
const OfflineRecognizerConfig &config);
|
|
||||||
|
|
||||||
|
template <typename Manager>
|
||||||
static std::unique_ptr<OfflineRecognizerImpl> Create(
|
static std::unique_ptr<OfflineRecognizerImpl> Create(
|
||||||
AAssetManager *mgr, const OfflineRecognizerConfig &config);
|
Manager *mgr, const OfflineRecognizerConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual ~OfflineRecognizerImpl() = default;
|
virtual ~OfflineRecognizerImpl() = default;
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-moonshine-decoder.h"
|
#include "sherpa-onnx/csrc/offline-moonshine-decoder.h"
|
||||||
#include "sherpa-onnx/csrc/offline-moonshine-greedy-search-decoder.h"
|
#include "sherpa-onnx/csrc/offline-moonshine-greedy-search-decoder.h"
|
||||||
@@ -59,8 +54,8 @@ class OfflineRecognizerMoonshineImpl : public OfflineRecognizerImpl {
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizerMoonshineImpl(AAssetManager *mgr,
|
OfflineRecognizerMoonshineImpl(Manager *mgr,
|
||||||
const OfflineRecognizerConfig &config)
|
const OfflineRecognizerConfig &config)
|
||||||
: OfflineRecognizerImpl(mgr, config),
|
: OfflineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -70,8 +65,6 @@ class OfflineRecognizerMoonshineImpl : public OfflineRecognizerImpl {
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
if (config_.decoding_method == "greedy_search") {
|
if (config_.decoding_method == "greedy_search") {
|
||||||
decoder_ =
|
decoder_ =
|
||||||
|
|||||||
@@ -11,11 +11,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-paraformer-decoder.h"
|
#include "sherpa-onnx/csrc/offline-paraformer-decoder.h"
|
||||||
#include "sherpa-onnx/csrc/offline-paraformer-greedy-search-decoder.h"
|
#include "sherpa-onnx/csrc/offline-paraformer-greedy-search-decoder.h"
|
||||||
@@ -105,8 +100,8 @@ class OfflineRecognizerParaformerImpl : public OfflineRecognizerImpl {
|
|||||||
InitFeatConfig();
|
InitFeatConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizerParaformerImpl(AAssetManager *mgr,
|
OfflineRecognizerParaformerImpl(Manager *mgr,
|
||||||
const OfflineRecognizerConfig &config)
|
const OfflineRecognizerConfig &config)
|
||||||
: OfflineRecognizerImpl(mgr, config),
|
: OfflineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -124,7 +119,6 @@ class OfflineRecognizerParaformerImpl : public OfflineRecognizerImpl {
|
|||||||
|
|
||||||
InitFeatConfig();
|
InitFeatConfig();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unique_ptr<OfflineStream> CreateStream() const override {
|
std::unique_ptr<OfflineStream> CreateStream() const override {
|
||||||
return std::make_unique<OfflineStream>(config_.feat_config);
|
return std::make_unique<OfflineStream>(config_.feat_config);
|
||||||
|
|||||||
@@ -11,11 +11,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-greedy-search-decoder.h"
|
#include "sherpa-onnx/csrc/offline-ctc-greedy-search-decoder.h"
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
||||||
@@ -83,8 +78,8 @@ class OfflineRecognizerSenseVoiceImpl : public OfflineRecognizerImpl {
|
|||||||
InitFeatConfig();
|
InitFeatConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizerSenseVoiceImpl(AAssetManager *mgr,
|
OfflineRecognizerSenseVoiceImpl(Manager *mgr,
|
||||||
const OfflineRecognizerConfig &config)
|
const OfflineRecognizerConfig &config)
|
||||||
: OfflineRecognizerImpl(mgr, config),
|
: OfflineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -103,7 +98,6 @@ class OfflineRecognizerSenseVoiceImpl : public OfflineRecognizerImpl {
|
|||||||
|
|
||||||
InitFeatConfig();
|
InitFeatConfig();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unique_ptr<OfflineStream> CreateStream() const override {
|
std::unique_ptr<OfflineStream> CreateStream() const override {
|
||||||
return std::make_unique<OfflineStream>(config_.feat_config);
|
return std::make_unique<OfflineStream>(config_.feat_config);
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/context-graph.h"
|
#include "sherpa-onnx/csrc/context-graph.h"
|
||||||
#include "sherpa-onnx/csrc/log.h"
|
#include "sherpa-onnx/csrc/log.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
@@ -109,9 +104,9 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
explicit OfflineRecognizerTransducerImpl(
|
explicit OfflineRecognizerTransducerImpl(
|
||||||
AAssetManager *mgr, const OfflineRecognizerConfig &config)
|
Manager *mgr, const OfflineRecognizerConfig &config)
|
||||||
: OfflineRecognizerImpl(mgr, config),
|
: OfflineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
symbol_table_(mgr, config_.model_config.tokens),
|
symbol_table_(mgr, config_.model_config.tokens),
|
||||||
@@ -148,7 +143,6 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unique_ptr<OfflineStream> CreateStream(
|
std::unique_ptr<OfflineStream> CreateStream(
|
||||||
const std::string &hotwords) const override {
|
const std::string &hotwords) const override {
|
||||||
@@ -246,10 +240,7 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflineRecognizerConfig GetConfig() const override {
|
OfflineRecognizerConfig GetConfig() const override { return config_; }
|
||||||
return config_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void InitHotwords() {
|
void InitHotwords() {
|
||||||
// each line in hotwords_file contains space-separated words
|
// each line in hotwords_file contains space-separated words
|
||||||
@@ -271,8 +262,8 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
|
|||||||
hotwords_, config_.hotwords_score, boost_scores_);
|
hotwords_, config_.hotwords_score, boost_scores_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
void InitHotwords(AAssetManager *mgr) {
|
void InitHotwords(Manager *mgr) {
|
||||||
// each line in hotwords_file contains space-separated words
|
// each line in hotwords_file contains space-separated words
|
||||||
|
|
||||||
auto buf = ReadFile(mgr, config_.hotwords_file);
|
auto buf = ReadFile(mgr, config_.hotwords_file);
|
||||||
@@ -294,7 +285,6 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
|
|||||||
hotwords_graph_ = std::make_shared<ContextGraph>(
|
hotwords_graph_ = std::make_shared<ContextGraph>(
|
||||||
hotwords_, config_.hotwords_score, boost_scores_);
|
hotwords_, config_.hotwords_score, boost_scores_);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OfflineRecognizerConfig config_;
|
OfflineRecognizerConfig config_;
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
||||||
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
||||||
@@ -57,9 +52,9 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
|
|||||||
PostInit();
|
PostInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
explicit OfflineRecognizerTransducerNeMoImpl(
|
explicit OfflineRecognizerTransducerNeMoImpl(
|
||||||
AAssetManager *mgr, const OfflineRecognizerConfig &config)
|
Manager *mgr, const OfflineRecognizerConfig &config)
|
||||||
: OfflineRecognizerImpl(mgr, config),
|
: OfflineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
symbol_table_(mgr, config_.model_config.tokens),
|
symbol_table_(mgr, config_.model_config.tokens),
|
||||||
@@ -76,7 +71,6 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
|
|||||||
|
|
||||||
PostInit();
|
PostInit();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unique_ptr<OfflineStream> CreateStream() const override {
|
std::unique_ptr<OfflineStream> CreateStream() const override {
|
||||||
return std::make_unique<OfflineStream>(config_.feat_config);
|
return std::make_unique<OfflineStream>(config_.feat_config);
|
||||||
|
|||||||
@@ -12,11 +12,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
||||||
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
||||||
@@ -60,8 +55,8 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizerWhisperImpl(AAssetManager *mgr,
|
OfflineRecognizerWhisperImpl(Manager *mgr,
|
||||||
const OfflineRecognizerConfig &config)
|
const OfflineRecognizerConfig &config)
|
||||||
: OfflineRecognizerImpl(mgr, config),
|
: OfflineRecognizerImpl(mgr, config),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -71,8 +66,6 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
// tokens.txt from whisper is base64 encoded, so we need to decode it
|
// tokens.txt from whisper is base64 encoded, so we need to decode it
|
||||||
symbol_table_.ApplyBase64Decode();
|
symbol_table_.ApplyBase64Decode();
|
||||||
@@ -105,9 +98,7 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
|
|||||||
config_.model_config.whisper = config.model_config.whisper;
|
config_.model_config.whisper = config.model_config.whisper;
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflineRecognizerConfig GetConfig() const override {
|
OfflineRecognizerConfig GetConfig() const override { return config_; }
|
||||||
return config_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DecodeStream(OfflineStream *s) const {
|
void DecodeStream(OfflineStream *s) const {
|
||||||
|
|||||||
@@ -6,11 +6,21 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/file-utils.h"
|
#include "sherpa-onnx/csrc/file-utils.h"
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
#include "sherpa-onnx/csrc/offline-recognizer-impl.h"
|
||||||
#include "sherpa-onnx/csrc/text-utils.h"
|
#include "sherpa-onnx/csrc/text-utils.h"
|
||||||
|
|
||||||
namespace sherpa_onnx {
|
namespace sherpa_onnx {
|
||||||
|
|
||||||
void OfflineRecognizerConfig::Register(ParseOptions *po) {
|
void OfflineRecognizerConfig::Register(ParseOptions *po) {
|
||||||
@@ -132,11 +142,10 @@ std::string OfflineRecognizerConfig::ToString() const {
|
|||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizer::OfflineRecognizer(AAssetManager *mgr,
|
OfflineRecognizer::OfflineRecognizer(Manager *mgr,
|
||||||
const OfflineRecognizerConfig &config)
|
const OfflineRecognizerConfig &config)
|
||||||
: impl_(OfflineRecognizerImpl::Create(mgr, config)) {}
|
: impl_(OfflineRecognizerImpl::Create(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineRecognizer::OfflineRecognizer(const OfflineRecognizerConfig &config)
|
OfflineRecognizer::OfflineRecognizer(const OfflineRecognizerConfig &config)
|
||||||
: impl_(OfflineRecognizerImpl::Create(config)) {}
|
: impl_(OfflineRecognizerImpl::Create(config)) {}
|
||||||
@@ -164,4 +173,14 @@ OfflineRecognizerConfig OfflineRecognizer::GetConfig() const {
|
|||||||
return impl_->GetConfig();
|
return impl_->GetConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineRecognizer::OfflineRecognizer(
|
||||||
|
AAssetManager *mgr, const OfflineRecognizerConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineRecognizer::OfflineRecognizer(
|
||||||
|
NativeResourceManager *mgr, const OfflineRecognizerConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/features.h"
|
#include "sherpa-onnx/csrc/features.h"
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-fst-decoder-config.h"
|
#include "sherpa-onnx/csrc/offline-ctc-fst-decoder-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
||||||
@@ -82,9 +77,8 @@ class OfflineRecognizer {
|
|||||||
public:
|
public:
|
||||||
~OfflineRecognizer();
|
~OfflineRecognizer();
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRecognizer(AAssetManager *mgr, const OfflineRecognizerConfig &config);
|
OfflineRecognizer(Manager *mgr, const OfflineRecognizerConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
explicit OfflineRecognizer(const OfflineRecognizerConfig &config);
|
explicit OfflineRecognizer(const OfflineRecognizerConfig &config);
|
||||||
|
|
||||||
@@ -121,8 +115,8 @@ class OfflineRecognizer {
|
|||||||
|
|
||||||
/** Onnxruntime Session objects are not affected by this method.
|
/** Onnxruntime Session objects are not affected by this method.
|
||||||
* The exact behavior can be defined by a specific recognizer impl.
|
* The exact behavior can be defined by a specific recognizer impl.
|
||||||
* For instance, for the whisper recognizer, you can retrieve the language and task from
|
* For instance, for the whisper recognizer, you can retrieve the language and
|
||||||
* the config and ignore any remaining fields in `config`.
|
* task from the config and ignore any remaining fields in `config`.
|
||||||
*/
|
*/
|
||||||
void SetConfig(const OfflineRecognizerConfig &config);
|
void SetConfig(const OfflineRecognizerConfig &config);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
@@ -27,8 +36,8 @@ class OfflineRnnLM::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineLMConfig &config)
|
Impl(Manager *mgr, const OfflineLMConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_{GetSessionOptions(config)},
|
sess_opts_{GetSessionOptions(config)},
|
||||||
@@ -36,7 +45,6 @@ class OfflineRnnLM::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.model);
|
auto buf = ReadFile(mgr, config_.model);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
Ort::Value Rescore(Ort::Value x, Ort::Value x_lens) {
|
Ort::Value Rescore(Ort::Value x, Ort::Value x_lens) {
|
||||||
std::array<Ort::Value, 2> inputs = {std::move(x), std::move(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)
|
OfflineRnnLM::OfflineRnnLM(const OfflineLMConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRnnLM::OfflineRnnLM(AAssetManager *mgr, const OfflineLMConfig &config)
|
OfflineRnnLM::OfflineRnnLM(Manager *mgr, const OfflineLMConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineRnnLM::~OfflineRnnLM() = default;
|
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));
|
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
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
#include "sherpa-onnx/csrc/offline-lm-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-lm.h"
|
#include "sherpa-onnx/csrc/offline-lm.h"
|
||||||
@@ -24,9 +19,8 @@ class OfflineRnnLM : public OfflineLM {
|
|||||||
|
|
||||||
explicit OfflineRnnLM(const OfflineLMConfig &config);
|
explicit OfflineRnnLM(const OfflineLMConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineRnnLM(AAssetManager *mgr, const OfflineLMConfig &config);
|
OfflineRnnLM(Manager *mgr, const OfflineLMConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Rescore a batch of sentences.
|
/** Rescore a batch of sentences.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -26,8 +35,8 @@ class OfflineSenseVoiceModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -35,7 +44,6 @@ class OfflineSenseVoiceModel::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.sense_voice.model);
|
auto buf = ReadFile(mgr, config_.sense_voice.model);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
Ort::Value Forward(Ort::Value features, Ort::Value features_length,
|
Ort::Value Forward(Ort::Value features, Ort::Value features_length,
|
||||||
Ort::Value language, Ort::Value text_norm) {
|
Ort::Value language, Ort::Value text_norm) {
|
||||||
@@ -72,7 +80,11 @@ class OfflineSenseVoiceModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -129,11 +141,10 @@ class OfflineSenseVoiceModel::Impl {
|
|||||||
OfflineSenseVoiceModel::OfflineSenseVoiceModel(const OfflineModelConfig &config)
|
OfflineSenseVoiceModel::OfflineSenseVoiceModel(const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineSenseVoiceModel::OfflineSenseVoiceModel(AAssetManager *mgr,
|
OfflineSenseVoiceModel::OfflineSenseVoiceModel(Manager *mgr,
|
||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineSenseVoiceModel::~OfflineSenseVoiceModel() = default;
|
OfflineSenseVoiceModel::~OfflineSenseVoiceModel() = default;
|
||||||
|
|
||||||
@@ -154,4 +165,14 @@ OrtAllocator *OfflineSenseVoiceModel::Allocator() const {
|
|||||||
return impl_->Allocator();
|
return impl_->Allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineSenseVoiceModel::OfflineSenseVoiceModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineSenseVoiceModel::OfflineSenseVoiceModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/offline-sense-voice-model-meta-data.h"
|
#include "sherpa-onnx/csrc/offline-sense-voice-model-meta-data.h"
|
||||||
@@ -22,9 +17,8 @@ class OfflineSenseVoiceModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineSenseVoiceModel(const OfflineModelConfig &config);
|
explicit OfflineSenseVoiceModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineSenseVoiceModel(AAssetManager *mgr, const OfflineModelConfig &config);
|
OfflineSenseVoiceModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineSenseVoiceModel();
|
~OfflineSenseVoiceModel();
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,15 @@
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -25,8 +34,8 @@ class OfflineTdnnCtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -34,7 +43,6 @@ class OfflineTdnnCtcModel::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.tdnn.model);
|
auto buf = ReadFile(mgr, config_.tdnn.model);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value features) {
|
std::vector<Ort::Value> Forward(Ort::Value features) {
|
||||||
auto nnet_out =
|
auto nnet_out =
|
||||||
@@ -79,7 +87,11 @@ class OfflineTdnnCtcModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -106,11 +118,10 @@ class OfflineTdnnCtcModel::Impl {
|
|||||||
OfflineTdnnCtcModel::OfflineTdnnCtcModel(const OfflineModelConfig &config)
|
OfflineTdnnCtcModel::OfflineTdnnCtcModel(const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTdnnCtcModel::OfflineTdnnCtcModel(AAssetManager *mgr,
|
OfflineTdnnCtcModel::OfflineTdnnCtcModel(Manager *mgr,
|
||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineTdnnCtcModel::~OfflineTdnnCtcModel() = default;
|
OfflineTdnnCtcModel::~OfflineTdnnCtcModel() = default;
|
||||||
|
|
||||||
@@ -125,4 +136,14 @@ OrtAllocator *OfflineTdnnCtcModel::Allocator() const {
|
|||||||
return impl_->Allocator();
|
return impl_->Allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineTdnnCtcModel::OfflineTdnnCtcModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineTdnnCtcModel::OfflineTdnnCtcModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
@@ -27,9 +22,8 @@ class OfflineTdnnCtcModel : public OfflineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineTdnnCtcModel(const OfflineModelConfig &config);
|
explicit OfflineTdnnCtcModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTdnnCtcModel(AAssetManager *mgr, const OfflineModelConfig &config);
|
OfflineTdnnCtcModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineTdnnCtcModel() override;
|
~OfflineTdnnCtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-telespeech-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-telespeech-ctc-model.h"
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -23,8 +32,8 @@ class OfflineTeleSpeechCtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -32,7 +41,6 @@ class OfflineTeleSpeechCtcModel::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.telespeech_ctc);
|
auto buf = ReadFile(mgr, config_.telespeech_ctc);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value features,
|
std::vector<Ort::Value> Forward(Ort::Value features,
|
||||||
Ort::Value /*features_length*/) {
|
Ort::Value /*features_length*/) {
|
||||||
@@ -85,7 +93,11 @@ class OfflineTeleSpeechCtcModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -117,11 +129,10 @@ OfflineTeleSpeechCtcModel::OfflineTeleSpeechCtcModel(
|
|||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTeleSpeechCtcModel::OfflineTeleSpeechCtcModel(
|
OfflineTeleSpeechCtcModel::OfflineTeleSpeechCtcModel(
|
||||||
AAssetManager *mgr, const OfflineModelConfig &config)
|
Manager *mgr, const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineTeleSpeechCtcModel::~OfflineTeleSpeechCtcModel() = default;
|
OfflineTeleSpeechCtcModel::~OfflineTeleSpeechCtcModel() = default;
|
||||||
|
|
||||||
@@ -141,4 +152,14 @@ OrtAllocator *OfflineTeleSpeechCtcModel::Allocator() const {
|
|||||||
return impl_->Allocator();
|
return impl_->Allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineTeleSpeechCtcModel::OfflineTeleSpeechCtcModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineTeleSpeechCtcModel::OfflineTeleSpeechCtcModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
@@ -31,10 +26,8 @@ class OfflineTeleSpeechCtcModel : public OfflineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineTeleSpeechCtcModel(const OfflineModelConfig &config);
|
explicit OfflineTeleSpeechCtcModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTeleSpeechCtcModel(AAssetManager *mgr,
|
OfflineTeleSpeechCtcModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
const OfflineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineTeleSpeechCtcModel() override;
|
~OfflineTeleSpeechCtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/offline-transducer-decoder.h"
|
#include "sherpa-onnx/csrc/offline-transducer-decoder.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
@@ -38,8 +47,8 @@ class OfflineTransducerModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -59,7 +68,6 @@ class OfflineTransducerModel::Impl {
|
|||||||
InitJoiner(buf.data(), buf.size());
|
InitJoiner(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::pair<Ort::Value, Ort::Value> RunEncoder(Ort::Value features,
|
std::pair<Ort::Value, Ort::Value> RunEncoder(Ort::Value features,
|
||||||
Ort::Value features_length) {
|
Ort::Value features_length) {
|
||||||
@@ -161,7 +169,11 @@ class OfflineTransducerModel::Impl {
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,11 +256,10 @@ class OfflineTransducerModel::Impl {
|
|||||||
OfflineTransducerModel::OfflineTransducerModel(const OfflineModelConfig &config)
|
OfflineTransducerModel::OfflineTransducerModel(const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTransducerModel::OfflineTransducerModel(AAssetManager *mgr,
|
OfflineTransducerModel::OfflineTransducerModel(Manager *mgr,
|
||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineTransducerModel::~OfflineTransducerModel() = default;
|
OfflineTransducerModel::~OfflineTransducerModel() = default;
|
||||||
|
|
||||||
@@ -291,4 +302,14 @@ Ort::Value OfflineTransducerModel::BuildDecoderInput(
|
|||||||
return impl_->BuildDecoderInput(results, end_index);
|
return impl_->BuildDecoderInput(results, end_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineTransducerModel::OfflineTransducerModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineTransducerModel::OfflineTransducerModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/hypothesis.h"
|
#include "sherpa-onnx/csrc/hypothesis.h"
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
@@ -25,9 +20,8 @@ class OfflineTransducerModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineTransducerModel(const OfflineModelConfig &config);
|
explicit OfflineTransducerModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTransducerModel(AAssetManager *mgr, const OfflineModelConfig &config);
|
OfflineTransducerModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineTransducerModel();
|
~OfflineTransducerModel();
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/offline-transducer-decoder.h"
|
#include "sherpa-onnx/csrc/offline-transducer-decoder.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
@@ -40,8 +49,8 @@ class OfflineTransducerNeMoModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -61,7 +70,6 @@ class OfflineTransducerNeMoModel::Impl {
|
|||||||
InitJoiner(buf.data(), buf.size());
|
InitJoiner(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> RunEncoder(Ort::Value features,
|
std::vector<Ort::Value> RunEncoder(Ort::Value features,
|
||||||
Ort::Value features_length) {
|
Ort::Value features_length) {
|
||||||
@@ -172,7 +180,11 @@ class OfflineTransducerNeMoModel::Impl {
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -256,11 +268,10 @@ OfflineTransducerNeMoModel::OfflineTransducerNeMoModel(
|
|||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTransducerNeMoModel::OfflineTransducerNeMoModel(
|
OfflineTransducerNeMoModel::OfflineTransducerNeMoModel(
|
||||||
AAssetManager *mgr, const OfflineModelConfig &config)
|
Manager *mgr, const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineTransducerNeMoModel::~OfflineTransducerNeMoModel() = default;
|
OfflineTransducerNeMoModel::~OfflineTransducerNeMoModel() = default;
|
||||||
|
|
||||||
@@ -305,4 +316,14 @@ std::string OfflineTransducerNeMoModel::FeatureNormalizationMethod() const {
|
|||||||
|
|
||||||
bool OfflineTransducerNeMoModel::IsGigaAM() const { return impl_->IsGigaAM(); }
|
bool OfflineTransducerNeMoModel::IsGigaAM() const { return impl_->IsGigaAM(); }
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineTransducerNeMoModel::OfflineTransducerNeMoModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineTransducerNeMoModel::OfflineTransducerNeMoModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
|
|
||||||
@@ -26,10 +21,8 @@ class OfflineTransducerNeMoModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineTransducerNeMoModel(const OfflineModelConfig &config);
|
explicit OfflineTransducerNeMoModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineTransducerNeMoModel(AAssetManager *mgr,
|
OfflineTransducerNeMoModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
const OfflineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineTransducerNeMoModel();
|
~OfflineTransducerNeMoModel();
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
#include "sherpa-onnx/csrc/offline-wenet-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-wenet-ctc-model.h"
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -23,8 +32,8 @@ class OfflineWenetCtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -32,7 +41,6 @@ class OfflineWenetCtcModel::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.wenet_ctc.model);
|
auto buf = ReadFile(mgr, config_.wenet_ctc.model);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value features,
|
std::vector<Ort::Value> Forward(Ort::Value features,
|
||||||
Ort::Value features_length) {
|
Ort::Value features_length) {
|
||||||
@@ -63,7 +71,11 @@ class OfflineWenetCtcModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -92,11 +104,10 @@ class OfflineWenetCtcModel::Impl {
|
|||||||
OfflineWenetCtcModel::OfflineWenetCtcModel(const OfflineModelConfig &config)
|
OfflineWenetCtcModel::OfflineWenetCtcModel(const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineWenetCtcModel::OfflineWenetCtcModel(AAssetManager *mgr,
|
OfflineWenetCtcModel::OfflineWenetCtcModel(Manager *mgr,
|
||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineWenetCtcModel::~OfflineWenetCtcModel() = default;
|
OfflineWenetCtcModel::~OfflineWenetCtcModel() = default;
|
||||||
|
|
||||||
@@ -115,4 +126,14 @@ OrtAllocator *OfflineWenetCtcModel::Allocator() const {
|
|||||||
return impl_->Allocator();
|
return impl_->Allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineWenetCtcModel::OfflineWenetCtcModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineWenetCtcModel::OfflineWenetCtcModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
@@ -31,9 +26,8 @@ class OfflineWenetCtcModel : public OfflineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineWenetCtcModel(const OfflineModelConfig &config);
|
explicit OfflineWenetCtcModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineWenetCtcModel(AAssetManager *mgr, const OfflineModelConfig &config);
|
OfflineWenetCtcModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineWenetCtcModel() override;
|
~OfflineWenetCtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,15 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -52,8 +61,8 @@ class OfflineWhisperModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -69,7 +78,8 @@ class OfflineWhisperModel::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Impl(AAssetManager *mgr, const SpokenLanguageIdentificationConfig &config)
|
template <typename Manager>
|
||||||
|
Impl(Manager *mgr, const SpokenLanguageIdentificationConfig &config)
|
||||||
: lid_config_(config),
|
: lid_config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -84,7 +94,6 @@ class OfflineWhisperModel::Impl {
|
|||||||
InitDecoder(buf.data(), buf.size());
|
InitDecoder(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::pair<Ort::Value, Ort::Value> ForwardEncoder(Ort::Value features) {
|
std::pair<Ort::Value, Ort::Value> ForwardEncoder(Ort::Value features) {
|
||||||
auto encoder_out = encoder_sess_->Run(
|
auto encoder_out = encoder_sess_->Run(
|
||||||
@@ -237,7 +246,11 @@ class OfflineWhisperModel::Impl {
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "---encoder---\n";
|
os << "---encoder---\n";
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
Ort::AllocatorWithDefaultOptions allocator; // used in the macro below
|
||||||
@@ -338,17 +351,16 @@ OfflineWhisperModel::OfflineWhisperModel(
|
|||||||
const SpokenLanguageIdentificationConfig &config)
|
const SpokenLanguageIdentificationConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineWhisperModel::OfflineWhisperModel(AAssetManager *mgr,
|
OfflineWhisperModel::OfflineWhisperModel(Manager *mgr,
|
||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
|
|
||||||
|
template <typename Manager>
|
||||||
OfflineWhisperModel::OfflineWhisperModel(
|
OfflineWhisperModel::OfflineWhisperModel(
|
||||||
AAssetManager *mgr, const SpokenLanguageIdentificationConfig &config)
|
Manager *mgr, const SpokenLanguageIdentificationConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineWhisperModel::~OfflineWhisperModel() = default;
|
OfflineWhisperModel::~OfflineWhisperModel() = default;
|
||||||
|
|
||||||
std::pair<Ort::Value, Ort::Value> OfflineWhisperModel::ForwardEncoder(
|
std::pair<Ort::Value, Ort::Value> OfflineWhisperModel::ForwardEncoder(
|
||||||
@@ -453,4 +465,21 @@ void OfflineWhisperModel::NormalizeFeatures(float *features, int32_t num_frames,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineWhisperModel::OfflineWhisperModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
|
||||||
|
template OfflineWhisperModel::OfflineWhisperModel(
|
||||||
|
AAssetManager *mgr, const SpokenLanguageIdentificationConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineWhisperModel::OfflineWhisperModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
|
||||||
|
template OfflineWhisperModel::OfflineWhisperModel(
|
||||||
|
NativeResourceManager *mgr,
|
||||||
|
const SpokenLanguageIdentificationConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -11,11 +11,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
#include "sherpa-onnx/csrc/spoken-language-identification.h"
|
#include "sherpa-onnx/csrc/spoken-language-identification.h"
|
||||||
@@ -29,11 +24,12 @@ class OfflineWhisperModel {
|
|||||||
explicit OfflineWhisperModel(
|
explicit OfflineWhisperModel(
|
||||||
const SpokenLanguageIdentificationConfig &config);
|
const SpokenLanguageIdentificationConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineWhisperModel(AAssetManager *mgr, const OfflineModelConfig &config);
|
OfflineWhisperModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
OfflineWhisperModel(AAssetManager *mgr,
|
|
||||||
|
template <typename Manager>
|
||||||
|
OfflineWhisperModel(Manager *mgr,
|
||||||
const SpokenLanguageIdentificationConfig &config);
|
const SpokenLanguageIdentificationConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineWhisperModel();
|
~OfflineWhisperModel();
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,15 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -25,8 +34,8 @@ class OfflineZipformerCtcModel::Impl {
|
|||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
Impl(AAssetManager *mgr, const OfflineModelConfig &config)
|
Impl(Manager *mgr, const OfflineModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
env_(ORT_LOGGING_LEVEL_ERROR),
|
env_(ORT_LOGGING_LEVEL_ERROR),
|
||||||
sess_opts_(GetSessionOptions(config)),
|
sess_opts_(GetSessionOptions(config)),
|
||||||
@@ -34,7 +43,6 @@ class OfflineZipformerCtcModel::Impl {
|
|||||||
auto buf = ReadFile(mgr, config_.zipformer_ctc.model);
|
auto buf = ReadFile(mgr, config_.zipformer_ctc.model);
|
||||||
Init(buf.data(), buf.size());
|
Init(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<Ort::Value> Forward(Ort::Value features,
|
std::vector<Ort::Value> Forward(Ort::Value features,
|
||||||
Ort::Value features_length) {
|
Ort::Value features_length) {
|
||||||
@@ -64,7 +72,11 @@ class OfflineZipformerCtcModel::Impl {
|
|||||||
if (config_.debug) {
|
if (config_.debug) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
PrintModelMetadata(os, meta_data);
|
PrintModelMetadata(os, meta_data);
|
||||||
|
#if __OHOS__
|
||||||
|
SHERPA_ONNX_LOGE("%{public}s\n", os.str().c_str());
|
||||||
|
#else
|
||||||
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
SHERPA_ONNX_LOGE("%s\n", os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// get vocab size from the output[0].shape, which is (N, T, vocab_size)
|
// get vocab size from the output[0].shape, which is (N, T, vocab_size)
|
||||||
@@ -93,11 +105,10 @@ OfflineZipformerCtcModel::OfflineZipformerCtcModel(
|
|||||||
const OfflineModelConfig &config)
|
const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineZipformerCtcModel::OfflineZipformerCtcModel(
|
OfflineZipformerCtcModel::OfflineZipformerCtcModel(
|
||||||
AAssetManager *mgr, const OfflineModelConfig &config)
|
Manager *mgr, const OfflineModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
OfflineZipformerCtcModel::~OfflineZipformerCtcModel() = default;
|
OfflineZipformerCtcModel::~OfflineZipformerCtcModel() = default;
|
||||||
|
|
||||||
@@ -118,4 +129,14 @@ int32_t OfflineZipformerCtcModel::SubsamplingFactor() const {
|
|||||||
return impl_->SubsamplingFactor();
|
return impl_->SubsamplingFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template OfflineZipformerCtcModel::OfflineZipformerCtcModel(
|
||||||
|
AAssetManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template OfflineZipformerCtcModel::OfflineZipformerCtcModel(
|
||||||
|
NativeResourceManager *mgr, const OfflineModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||||
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
#include "sherpa-onnx/csrc/offline-ctc-model.h"
|
||||||
#include "sherpa-onnx/csrc/offline-model-config.h"
|
#include "sherpa-onnx/csrc/offline-model-config.h"
|
||||||
@@ -28,10 +23,8 @@ class OfflineZipformerCtcModel : public OfflineCtcModel {
|
|||||||
public:
|
public:
|
||||||
explicit OfflineZipformerCtcModel(const OfflineModelConfig &config);
|
explicit OfflineZipformerCtcModel(const OfflineModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
OfflineZipformerCtcModel(AAssetManager *mgr,
|
OfflineZipformerCtcModel(Manager *mgr, const OfflineModelConfig &config);
|
||||||
const OfflineModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~OfflineZipformerCtcModel() override;
|
~OfflineZipformerCtcModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 "sherpa-onnx/csrc/macros.h"
|
#include "sherpa-onnx/csrc/macros.h"
|
||||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||||
#include "sherpa-onnx/csrc/session.h"
|
#include "sherpa-onnx/csrc/session.h"
|
||||||
@@ -37,7 +46,6 @@ class SileroVadModel::Impl {
|
|||||||
min_speech_samples_ = sample_rate_ * config_.silero_vad.min_speech_duration;
|
min_speech_samples_ = sample_rate_ * config_.silero_vad.min_speech_duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9 || defined(__OHOS__)
|
|
||||||
template <typename Manager>
|
template <typename Manager>
|
||||||
Impl(Manager *mgr, const VadModelConfig &config)
|
Impl(Manager *mgr, const VadModelConfig &config)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
@@ -59,7 +67,6 @@ class SileroVadModel::Impl {
|
|||||||
|
|
||||||
min_speech_samples_ = sample_rate_ * config_.silero_vad.min_speech_duration;
|
min_speech_samples_ = sample_rate_ * config_.silero_vad.min_speech_duration;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
if (is_v5_) {
|
if (is_v5_) {
|
||||||
@@ -433,16 +440,9 @@ class SileroVadModel::Impl {
|
|||||||
SileroVadModel::SileroVadModel(const VadModelConfig &config)
|
SileroVadModel::SileroVadModel(const VadModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(config)) {}
|
: impl_(std::make_unique<Impl>(config)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
SileroVadModel::SileroVadModel(AAssetManager *mgr, const VadModelConfig &config)
|
SileroVadModel::SileroVadModel(Manager *mgr, const VadModelConfig &config)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __OHOS__
|
|
||||||
SileroVadModel::SileroVadModel(NativeResourceManager *mgr,
|
|
||||||
const VadModelConfig &config)
|
|
||||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SileroVadModel::~SileroVadModel() = default;
|
SileroVadModel::~SileroVadModel() = default;
|
||||||
|
|
||||||
@@ -472,4 +472,14 @@ void SileroVadModel::SetThreshold(float threshold) {
|
|||||||
impl_->SetThreshold(threshold);
|
impl_->SetThreshold(threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template SileroVadModel::SileroVadModel(AAssetManager *mgr,
|
||||||
|
const VadModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template SileroVadModel::SileroVadModel(NativeResourceManager *mgr,
|
||||||
|
const VadModelConfig &config);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -6,15 +6,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#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 "sherpa-onnx/csrc/vad-model.h"
|
#include "sherpa-onnx/csrc/vad-model.h"
|
||||||
|
|
||||||
namespace sherpa_onnx {
|
namespace sherpa_onnx {
|
||||||
@@ -23,13 +14,8 @@ class SileroVadModel : public VadModel {
|
|||||||
public:
|
public:
|
||||||
explicit SileroVadModel(const VadModelConfig &config);
|
explicit SileroVadModel(const VadModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
SileroVadModel(AAssetManager *mgr, const VadModelConfig &config);
|
SileroVadModel(Manager *mgr, const VadModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __OHOS__
|
|
||||||
SileroVadModel(NativeResourceManager *mgr, const VadModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~SileroVadModel() override;
|
~SileroVadModel() override;
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
|
|
||||||
#include "android/asset_manager.h"
|
#include "android/asset_manager.h"
|
||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
|
#elif __OHOS__
|
||||||
|
#include <strstream>
|
||||||
|
|
||||||
|
#include "rawfile/raw_file_manager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sherpa-onnx/csrc/base64-decode.h"
|
#include "sherpa-onnx/csrc/base64-decode.h"
|
||||||
@@ -99,14 +103,13 @@ SymbolTable::SymbolTable(const std::string &filename, bool is_file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
SymbolTable::SymbolTable(AAssetManager *mgr, const std::string &filename) {
|
SymbolTable::SymbolTable(Manager *mgr, const std::string &filename) {
|
||||||
auto buf = ReadFile(mgr, filename);
|
auto buf = ReadFile(mgr, filename);
|
||||||
|
|
||||||
std::istrstream is(buf.data(), buf.size());
|
std::istrstream is(buf.data(), buf.size());
|
||||||
Init(is);
|
Init(is);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void SymbolTable::Init(std::istream &is) { sym2id_ = ReadTokens(is, &id2sym_); }
|
void SymbolTable::Init(std::istream &is) { sym2id_ = ReadTokens(is, &id2sym_); }
|
||||||
|
|
||||||
@@ -169,4 +172,14 @@ void SymbolTable::ApplyBase64Decode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template SymbolTable::SymbolTable(AAssetManager *mgr,
|
||||||
|
const std::string &filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template SymbolTable::SymbolTable(NativeResourceManager *mgr,
|
||||||
|
const std::string &filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -10,11 +10,6 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
|
||||||
#include "android/asset_manager.h"
|
|
||||||
#include "android/asset_manager_jni.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace sherpa_onnx {
|
namespace sherpa_onnx {
|
||||||
|
|
||||||
// The same token can be mapped to different integer IDs, so
|
// The same token can be mapped to different integer IDs, so
|
||||||
@@ -39,9 +34,8 @@ class SymbolTable {
|
|||||||
/// Fields are separated by space(s).
|
/// Fields are separated by space(s).
|
||||||
explicit SymbolTable(const std::string &filename, bool is_file = true);
|
explicit SymbolTable(const std::string &filename, bool is_file = true);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
SymbolTable(AAssetManager *mgr, const std::string &filename);
|
SymbolTable(Manager *mgr, const std::string &filename);
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Return a string representation of this symbol table
|
/// Return a string representation of this symbol table
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
#include "sherpa-onnx/csrc/vad-model.h"
|
#include "sherpa-onnx/csrc/vad-model.h"
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/silero-vad-model.h"
|
#include "sherpa-onnx/csrc/silero-vad-model.h"
|
||||||
|
|
||||||
namespace sherpa_onnx {
|
namespace sherpa_onnx {
|
||||||
@@ -13,20 +22,20 @@ std::unique_ptr<VadModel> VadModel::Create(const VadModelConfig &config) {
|
|||||||
return std::make_unique<SileroVadModel>(config);
|
return std::make_unique<SileroVadModel>(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
std::unique_ptr<VadModel> VadModel::Create(AAssetManager *mgr,
|
std::unique_ptr<VadModel> VadModel::Create(Manager *mgr,
|
||||||
const VadModelConfig &config) {
|
const VadModelConfig &config) {
|
||||||
// TODO(fangjun): Support other VAD models.
|
// TODO(fangjun): Support other VAD models.
|
||||||
return std::make_unique<SileroVadModel>(mgr, config);
|
return std::make_unique<SileroVadModel>(mgr, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template std::unique_ptr<VadModel> VadModel::Create(
|
||||||
|
AAssetManager *mgr, const VadModelConfig &config);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __OHOS__
|
#if __OHOS__
|
||||||
std::unique_ptr<VadModel> VadModel::Create(NativeResourceManager *mgr,
|
template std::unique_ptr<VadModel> VadModel::Create(
|
||||||
const VadModelConfig &config) {
|
NativeResourceManager *mgr, const VadModelConfig &config);
|
||||||
// TODO(fangjun): Support other VAD models.
|
|
||||||
return std::make_unique<SileroVadModel>(mgr, config);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -6,15 +6,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#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 "sherpa-onnx/csrc/vad-model-config.h"
|
#include "sherpa-onnx/csrc/vad-model-config.h"
|
||||||
|
|
||||||
namespace sherpa_onnx {
|
namespace sherpa_onnx {
|
||||||
@@ -25,15 +16,9 @@ class VadModel {
|
|||||||
|
|
||||||
static std::unique_ptr<VadModel> Create(const VadModelConfig &config);
|
static std::unique_ptr<VadModel> Create(const VadModelConfig &config);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
static std::unique_ptr<VadModel> Create(AAssetManager *mgr,
|
static std::unique_ptr<VadModel> Create(Manager *mgr,
|
||||||
const VadModelConfig &config);
|
const VadModelConfig &config);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __OHOS__
|
|
||||||
static std::unique_ptr<VadModel> Create(NativeResourceManager *mgr,
|
|
||||||
const VadModelConfig &config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// reset the internal model states
|
// reset the internal model states
|
||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#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 "sherpa-onnx/csrc/circular-buffer.h"
|
#include "sherpa-onnx/csrc/circular-buffer.h"
|
||||||
#include "sherpa-onnx/csrc/vad-model.h"
|
#include "sherpa-onnx/csrc/vad-model.h"
|
||||||
|
|
||||||
@@ -22,7 +31,6 @@ class VoiceActivityDetector::Impl {
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9 || defined(__OHOS__)
|
|
||||||
template <typename Manager>
|
template <typename Manager>
|
||||||
Impl(Manager *mgr, const VadModelConfig &config,
|
Impl(Manager *mgr, const VadModelConfig &config,
|
||||||
float buffer_size_in_seconds = 60)
|
float buffer_size_in_seconds = 60)
|
||||||
@@ -31,7 +39,6 @@ class VoiceActivityDetector::Impl {
|
|||||||
buffer_(buffer_size_in_seconds * config.sample_rate) {
|
buffer_(buffer_size_in_seconds * config.sample_rate) {
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void AcceptWaveform(const float *samples, int32_t n) {
|
void AcceptWaveform(const float *samples, int32_t n) {
|
||||||
if (buffer_.Size() > max_utterance_length_) {
|
if (buffer_.Size() > max_utterance_length_) {
|
||||||
@@ -178,19 +185,11 @@ VoiceActivityDetector::VoiceActivityDetector(
|
|||||||
const VadModelConfig &config, float buffer_size_in_seconds /*= 60*/)
|
const VadModelConfig &config, float buffer_size_in_seconds /*= 60*/)
|
||||||
: impl_(std::make_unique<Impl>(config, buffer_size_in_seconds)) {}
|
: impl_(std::make_unique<Impl>(config, buffer_size_in_seconds)) {}
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
VoiceActivityDetector::VoiceActivityDetector(
|
VoiceActivityDetector::VoiceActivityDetector(
|
||||||
AAssetManager *mgr, const VadModelConfig &config,
|
Manager *mgr, const VadModelConfig &config,
|
||||||
float buffer_size_in_seconds /*= 60*/)
|
float buffer_size_in_seconds /*= 60*/)
|
||||||
: impl_(std::make_unique<Impl>(mgr, config, buffer_size_in_seconds)) {}
|
: impl_(std::make_unique<Impl>(mgr, config, buffer_size_in_seconds)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __OHOS__
|
|
||||||
VoiceActivityDetector::VoiceActivityDetector(
|
|
||||||
NativeResourceManager *mgr, const VadModelConfig &config,
|
|
||||||
float buffer_size_in_seconds /*= 60*/)
|
|
||||||
: impl_(std::make_unique<Impl>(mgr, config, buffer_size_in_seconds)) {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VoiceActivityDetector::~VoiceActivityDetector() = default;
|
VoiceActivityDetector::~VoiceActivityDetector() = default;
|
||||||
|
|
||||||
@@ -220,4 +219,16 @@ const VadModelConfig &VoiceActivityDetector::GetConfig() const {
|
|||||||
return impl_->GetConfig();
|
return impl_->GetConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 9
|
||||||
|
template VoiceActivityDetector::VoiceActivityDetector(
|
||||||
|
AAssetManager *mgr, const VadModelConfig &config,
|
||||||
|
float buffer_size_in_seconds = 60);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __OHOS__
|
||||||
|
template VoiceActivityDetector::VoiceActivityDetector(
|
||||||
|
NativeResourceManager *mgr, const VadModelConfig &config,
|
||||||
|
float buffer_size_in_seconds = 60);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|||||||
@@ -7,15 +7,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#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 "sherpa-onnx/csrc/vad-model-config.h"
|
#include "sherpa-onnx/csrc/vad-model-config.h"
|
||||||
|
|
||||||
namespace sherpa_onnx {
|
namespace sherpa_onnx {
|
||||||
@@ -30,16 +21,9 @@ class VoiceActivityDetector {
|
|||||||
explicit VoiceActivityDetector(const VadModelConfig &config,
|
explicit VoiceActivityDetector(const VadModelConfig &config,
|
||||||
float buffer_size_in_seconds = 60);
|
float buffer_size_in_seconds = 60);
|
||||||
|
|
||||||
#if __ANDROID_API__ >= 9
|
template <typename Manager>
|
||||||
VoiceActivityDetector(AAssetManager *mgr, const VadModelConfig &config,
|
VoiceActivityDetector(Manager *mgr, const VadModelConfig &config,
|
||||||
float buffer_size_in_seconds = 60);
|
float buffer_size_in_seconds = 60);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __OHOS__
|
|
||||||
VoiceActivityDetector(NativeResourceManager *mgr,
|
|
||||||
const VadModelConfig &config,
|
|
||||||
float buffer_size_in_seconds = 60);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~VoiceActivityDetector();
|
~VoiceActivityDetector();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user