Support running sherpa-onnx with RK NPU on Android (#2124)
This commit is contained in:
@@ -51,7 +51,9 @@ std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
|
||||
#else
|
||||
SHERPA_ONNX_LOGE(
|
||||
"Please rebuild sherpa-onnx with -DSHERPA_ONNX_ENABLE_RKNN=ON if you "
|
||||
"want to use rknn. Fallback to CPU");
|
||||
"want to use rknn.");
|
||||
SHERPA_ONNX_EXIT(-1);
|
||||
return nullptr
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -108,7 +110,9 @@ std::unique_ptr<OnlineRecognizerImpl> OnlineRecognizerImpl::Create(
|
||||
#else
|
||||
SHERPA_ONNX_LOGE(
|
||||
"Please rebuild sherpa-onnx with -DSHERPA_ONNX_ENABLE_RKNN=ON if you "
|
||||
"want to use rknn. Fallback to CPU");
|
||||
"want to use rknn.");
|
||||
SHERPA_ONNX_EXIT(-1);
|
||||
return nullptr
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -55,9 +55,9 @@ class OnlineRecognizerCtcRknnImpl : public OnlineRecognizerImpl {
|
||||
const OnlineRecognizerConfig &config)
|
||||
: OnlineRecognizerImpl(mgr, config),
|
||||
config_(config),
|
||||
model_(
|
||||
std::make_unique<OnlineZipformerCtcModelRknn>(config.model_config)),
|
||||
sym_(mgr, config.model_config.tokens),
|
||||
model_(std::make_unique<OnlineZipformerCtcModelRknn>(
|
||||
mgr, config_.model_config)),
|
||||
sym_(mgr, config_.model_config.tokens),
|
||||
endpoint_(config_.endpoint_config) {
|
||||
InitDecoder();
|
||||
}
|
||||
|
||||
@@ -111,9 +111,33 @@ class OnlineRecognizerTransducerRknnImpl : public OnlineRecognizerImpl {
|
||||
: OnlineRecognizerImpl(mgr, config),
|
||||
config_(config),
|
||||
endpoint_(config_.endpoint_config),
|
||||
model_(
|
||||
std::make_unique<OnlineZipformerTransducerModelRknn>(mgr, config)) {
|
||||
// TODO(fangjun): Support Android
|
||||
model_(std::make_unique<OnlineZipformerTransducerModelRknn>(
|
||||
mgr, config_.model_config)) {
|
||||
if (!config.model_config.tokens_buf.empty()) {
|
||||
sym_ = SymbolTable(config.model_config.tokens_buf, false);
|
||||
} else {
|
||||
/// assuming tokens_buf and tokens are guaranteed not being both empty
|
||||
sym_ = SymbolTable(mgr, config.model_config.tokens);
|
||||
}
|
||||
|
||||
if (sym_.Contains("<unk>")) {
|
||||
unk_id_ = sym_["<unk>"];
|
||||
}
|
||||
|
||||
if (config.decoding_method == "greedy_search") {
|
||||
decoder_ = std::make_unique<OnlineTransducerGreedySearchDecoderRknn>(
|
||||
model_.get(), unk_id_);
|
||||
} else if (config.decoding_method == "modified_beam_search") {
|
||||
decoder_ =
|
||||
std::make_unique<OnlineTransducerModifiedBeamSearchDecoderRknn>(
|
||||
model_.get(), config.max_active_paths, unk_id_);
|
||||
} else {
|
||||
SHERPA_ONNX_LOGE(
|
||||
"Invalid decoding method: '%s'. Support only greedy_search and "
|
||||
"modified_beam_search.",
|
||||
config.decoding_method.c_str());
|
||||
SHERPA_ONNX_EXIT(-1);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<OnlineStream> CreateStream() const override {
|
||||
|
||||
@@ -252,7 +252,7 @@ OnlineZipformerCtcModelRknn::OnlineZipformerCtcModelRknn(
|
||||
template <typename Manager>
|
||||
OnlineZipformerCtcModelRknn::OnlineZipformerCtcModelRknn(
|
||||
Manager *mgr, const OnlineModelConfig &config)
|
||||
: impl_(std::make_unique<OnlineZipformerCtcModelRknn>(mgr, config)) {}
|
||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||
|
||||
std::vector<std::vector<uint8_t>> OnlineZipformerCtcModelRknn::GetInitStates()
|
||||
const {
|
||||
|
||||
@@ -435,8 +435,7 @@ OnlineZipformerTransducerModelRknn::OnlineZipformerTransducerModelRknn(
|
||||
template <typename Manager>
|
||||
OnlineZipformerTransducerModelRknn::OnlineZipformerTransducerModelRknn(
|
||||
Manager *mgr, const OnlineModelConfig &config)
|
||||
: impl_(std::make_unique<OnlineZipformerTransducerModelRknn>(mgr, config)) {
|
||||
}
|
||||
: impl_(std::make_unique<Impl>(mgr, config)) {}
|
||||
|
||||
std::vector<std::vector<uint8_t>>
|
||||
OnlineZipformerTransducerModelRknn::GetEncoderInitStates() const {
|
||||
|
||||
@@ -22,22 +22,34 @@
|
||||
namespace sherpa_onnx {
|
||||
|
||||
std::unique_ptr<VadModel> VadModel::Create(const VadModelConfig &config) {
|
||||
#if SHERPA_ONNX_ENABLE_RKNN
|
||||
if (config.provider == "rknn") {
|
||||
#if SHERPA_ONNX_ENABLE_RKNN
|
||||
return std::make_unique<SileroVadModelRknn>(config);
|
||||
}
|
||||
#else
|
||||
SHERPA_ONNX_LOGE(
|
||||
"Please rebuild sherpa-onnx with -DSHERPA_ONNX_ENABLE_RKNN=ON if you "
|
||||
"want to use rknn.");
|
||||
SHERPA_ONNX_EXIT(-1);
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
return std::make_unique<SileroVadModel>(config);
|
||||
}
|
||||
|
||||
template <typename Manager>
|
||||
std::unique_ptr<VadModel> VadModel::Create(Manager *mgr,
|
||||
const VadModelConfig &config) {
|
||||
#if SHERPA_ONNX_ENABLE_RKNN
|
||||
if (config.provider == "rknn") {
|
||||
#if SHERPA_ONNX_ENABLE_RKNN
|
||||
return std::make_unique<SileroVadModelRknn>(mgr, config);
|
||||
}
|
||||
#else
|
||||
SHERPA_ONNX_LOGE(
|
||||
"Please rebuild sherpa-onnx with -DSHERPA_ONNX_ENABLE_RKNN=ON if you "
|
||||
"want to use rknn.");
|
||||
SHERPA_ONNX_EXIT(-1);
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
return std::make_unique<SileroVadModel>(mgr, config);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user