Support running sherpa-onnx with RK NPU on Android (#2124)

This commit is contained in:
Fangjun Kuang
2025-04-15 16:42:28 +08:00
committed by GitHub
parent 4ed8ec367e
commit e3bce847c0
10 changed files with 427 additions and 15 deletions

View File

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