Skip to content

Commit 82cb8a5

Browse files
authored
Minor fixes for rknn (#1925)
1 parent 2f9a2b2 commit 82cb8a5

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

sherpa-onnx/csrc/offline-whisper-greedy-search-decoder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ OfflineWhisperGreedySearchDecoder::Decode(Ort::Value cross_k,
9999
int32_t n_text_ctx = model_->TextCtx();
100100

101101
std::vector<int32_t> predicted_tokens;
102-
for (int32_t i = 0; i < n_text_ctx; ++i) {
102+
for (int32_t i = 0; i < n_text_ctx / 2; ++i) {
103103
if (max_token_id == model_->EOT()) {
104104
break;
105105
}

sherpa-onnx/csrc/online-model-config.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "sherpa-onnx/csrc/file-utils.h"
99
#include "sherpa-onnx/csrc/macros.h"
10+
#include "sherpa-onnx/csrc/text-utils.h"
1011

1112
namespace sherpa_onnx {
1213

@@ -65,6 +66,29 @@ bool OnlineModelConfig::Validate() const {
6566
SHERPA_ONNX_LOGE("num_threads should be > 0. Given %d", num_threads);
6667
return false;
6768
}
69+
if (!transducer.encoder.empty() && (EndsWith(transducer.encoder, ".rknn") ||
70+
EndsWith(transducer.decoder, ".rknn") ||
71+
EndsWith(transducer.joiner, ".rknn"))) {
72+
SHERPA_ONNX_LOGE(
73+
"--provider is %s, which is not rknn, but you pass rknn model "
74+
"filenames. encoder: '%s', decoder: '%s', joiner: '%s'",
75+
provider_config.provider.c_str(), transducer.encoder.c_str(),
76+
transducer.decoder.c_str(), transducer.joiner.c_str());
77+
return false;
78+
}
79+
}
80+
81+
if (provider_config.provider == "rknn") {
82+
if (!transducer.encoder.empty() && (EndsWith(transducer.encoder, ".onnx") ||
83+
EndsWith(transducer.decoder, ".onnx") ||
84+
EndsWith(transducer.joiner, ".onnx"))) {
85+
SHERPA_ONNX_LOGE(
86+
"--provider is rknn, but you pass onnx model "
87+
"filenames. encoder: '%s', decoder: '%s', joiner: %'s'",
88+
transducer.encoder.c_str(), transducer.decoder.c_str(),
89+
transducer.joiner.c_str());
90+
return false;
91+
}
6892
}
6993

7094
if (!tokens_buf.empty() && FileExists(tokens)) {

sherpa-onnx/csrc/rknn/online-zipformer-transducer-model-rknn.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,10 @@ class OnlineZipformerTransducerModelRknn::Impl {
463463
}
464464
auto meta = Parse(custom_string);
465465

466-
for (const auto &p : meta) {
467-
SHERPA_ONNX_LOGE("%s: %s", p.first.c_str(), p.second.c_str());
466+
if (config_.debug) {
467+
for (const auto &p : meta) {
468+
SHERPA_ONNX_LOGE("%s: %s", p.first.c_str(), p.second.c_str());
469+
}
468470
}
469471

470472
if (meta.count("encoder_dims")) {

sherpa-onnx/csrc/sherpa-onnx-alsa.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ as the device_name.
9090
exit(-1);
9191
}
9292

93+
fprintf(stderr, "Started! Please speak\n");
94+
9395
int32_t chunk = 0.1 * alsa.GetActualSampleRate();
9496

9597
std::string last_text;

sherpa-onnx/csrc/sherpa-onnx.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ for a list of pre-trained models to download.
158158
const float rtf = s.elapsed_seconds / s.duration;
159159

160160
os << po.GetArg(i) << "\n";
161-
os << std::setprecision(2) << "Elapsed seconds: " << s.elapsed_seconds
162-
<< ", Real time factor (RTF): " << rtf << "\n";
161+
os << "Number of threads: " << config.model_config.num_threads << ", "
162+
<< std::setprecision(2) << "Elapsed seconds: " << s.elapsed_seconds
163+
<< ", Audio duration (s): " << s.duration
164+
<< ", Real time factor (RTF) = " << s.elapsed_seconds << "/"
165+
<< s.duration << " = " << rtf << "\n";
163166
const auto r = recognizer.GetResult(s.online_stream.get());
164167
os << r.text << "\n";
165168
os << r.AsJsonString() << "\n\n";

sherpa-onnx/csrc/text-utils.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,4 +699,12 @@ std::string ToString(const std::wstring &s) {
699699
return converter.to_bytes(s);
700700
}
701701

702+
bool EndsWith(const std::string &haystack, const std::string &needle) {
703+
if (needle.size() > haystack.size()) {
704+
return false;
705+
}
706+
707+
return std::equal(needle.rbegin(), needle.rend(), haystack.rbegin());
708+
}
709+
702710
} // namespace sherpa_onnx

sherpa-onnx/csrc/text-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ std::wstring ToWideString(const std::string &s);
145145

146146
std::string ToString(const std::wstring &s);
147147

148+
bool EndsWith(const std::string &haystack, const std::string &needle);
149+
148150
} // namespace sherpa_onnx
149151

150152
#endif // SHERPA_ONNX_CSRC_TEXT_UTILS_H_

0 commit comments

Comments
 (0)