Support Android (#59)

This commit is contained in:
Fangjun Kuang
2023-02-24 13:57:03 +08:00
committed by GitHub
parent 5a5d029490
commit 9064b3f016
68 changed files with 1469 additions and 220 deletions

View File

@@ -5,6 +5,23 @@
#ifndef SHERPA_ONNX_CSRC_MACROS_H_
#define SHERPA_ONNX_CSRC_MACROS_H_
#include <stdio.h>
#if __ANDROID_API__ >= 8
#include "android/log.h"
#define SHERPA_ONNX_LOGE(...) \
do { \
fprintf(stderr, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
__android_log_print(ANDROID_LOG_WARN, "sherpa-onnx", ##__VA_ARGS__); \
} while (0)
#else
#define SHERPA_ONNX_LOGE(...) \
do { \
fprintf(stderr, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
} while (0)
#endif
#define SHERPA_ONNX_READ_META_DATA(dst, src_key) \
do { \

View File

@@ -37,7 +37,6 @@ std::string OnlineRecognizerConfig::ToString() const {
os << "OnlineRecognizerConfig(";
os << "feat_config=" << feat_config.ToString() << ", ";
os << "model_config=" << model_config.ToString() << ", ";
os << "tokens=\"" << tokens << "\", ";
os << "endpoint_config=" << endpoint_config.ToString() << ", ";
os << "enable_endpoint=" << (enable_endpoint ? "True" : "False") << ")";
@@ -49,7 +48,7 @@ class OnlineRecognizer::Impl {
explicit Impl(const OnlineRecognizerConfig &config)
: config_(config),
model_(OnlineTransducerModel::Create(config.model_config)),
sym_(config.tokens),
sym_(config.model_config.tokens),
endpoint_(config_.endpoint_config) {
decoder_ =
std::make_unique<OnlineTransducerGreedySearchDecoder>(model_.get());
@@ -59,7 +58,7 @@ class OnlineRecognizer::Impl {
explicit Impl(AAssetManager *mgr, const OnlineRecognizerConfig &config)
: config_(config),
model_(OnlineTransducerModel::Create(mgr, config.model_config)),
sym_(mgr, config.tokens),
sym_(mgr, config.model_config.tokens),
endpoint_(config_.endpoint_config) {
decoder_ =
std::make_unique<OnlineTransducerGreedySearchDecoder>(model_.get());

View File

@@ -27,7 +27,6 @@ struct OnlineRecognizerResult {
struct OnlineRecognizerConfig {
FeatureExtractorConfig feat_config;
OnlineTransducerModelConfig model_config;
std::string tokens;
EndpointConfig endpoint_config;
bool enable_endpoint;
@@ -35,12 +34,10 @@ struct OnlineRecognizerConfig {
OnlineRecognizerConfig(const FeatureExtractorConfig &feat_config,
const OnlineTransducerModelConfig &model_config,
const std::string &tokens,
const EndpointConfig &endpoint_config,
bool enable_endpoint)
: feat_config(feat_config),
model_config(model_config),
tokens(tokens),
endpoint_config(endpoint_config),
enable_endpoint(enable_endpoint) {}

View File

@@ -14,6 +14,7 @@ std::string OnlineTransducerModelConfig::ToString() const {
os << "encoder_filename=\"" << encoder_filename << "\", ";
os << "decoder_filename=\"" << decoder_filename << "\", ";
os << "joiner_filename=\"" << joiner_filename << "\", ";
os << "tokens=\"" << tokens << "\", ";
os << "num_threads=" << num_threads << ", ";
os << "debug=" << (debug ? "True" : "False") << ")";

View File

@@ -12,6 +12,7 @@ struct OnlineTransducerModelConfig {
std::string encoder_filename;
std::string decoder_filename;
std::string joiner_filename;
std::string tokens;
int32_t num_threads;
bool debug = false;
@@ -19,10 +20,12 @@ struct OnlineTransducerModelConfig {
OnlineTransducerModelConfig(const std::string &encoder_filename,
const std::string &decoder_filename,
const std::string &joiner_filename,
int32_t num_threads, bool debug)
const std::string &tokens, int32_t num_threads,
bool debug)
: encoder_filename(encoder_filename),
decoder_filename(decoder_filename),
joiner_filename(joiner_filename),
tokens(tokens),
num_threads(num_threads),
debug(debug) {}

View File

@@ -141,9 +141,8 @@ std::vector<char> ReadFile(AAssetManager *mgr, const std::string &filename) {
auto p = reinterpret_cast<const char *>(AAsset_getBuffer(asset));
size_t asset_length = AAsset_getLength(asset);
AAsset_close(asset);
std::vector<char> buffer(p, p + asset_length);
AAsset_close(asset);
return buffer;
}

View File

@@ -65,7 +65,7 @@ as the device_name.
sherpa_onnx::OnlineRecognizerConfig config;
config.tokens = argv[1];
config.model_config.tokens = argv[1];
config.model_config.debug = false;
config.model_config.encoder_filename = argv[2];

View File

@@ -58,7 +58,7 @@ for a list of pre-trained models to download.
signal(SIGINT, Handler);
sherpa_onnx::OnlineRecognizerConfig config;
config.tokens = argv[1];
config.model_config.tokens = argv[1];
config.model_config.debug = false;
config.model_config.encoder_filename = argv[2];

View File

@@ -35,7 +35,7 @@ for a list of pre-trained models to download.
sherpa_onnx::OnlineRecognizerConfig config;
config.tokens = argv[1];
config.model_config.tokens = argv[1];
config.model_config.debug = false;
config.model_config.encoder_filename = argv[2];