diff --git a/java-api-examples/AddPunctuation.java b/java-api-examples/AddPunctuation.java index a0e3878a0..5eeba4eb2 100644 --- a/java-api-examples/AddPunctuation.java +++ b/java-api-examples/AddPunctuation.java @@ -1,13 +1,13 @@ // Copyright 2024 Xiaomi Corporation -// This file shows how to use a punctuation model to text. +// This file shows how to use a punctuation model to add punctuations to text. // -// The modes supports both English and Chinese. +// The model supports both English and Chinese. import com.k2fsa.sherpa.onnx.*; public class AddPunctuation { public static void main(String[] args) { - // please download model and test files from + // please download the model from // https://github.com/k2-fsa/sherpa-onnx/releases/tag/punctuation-models String model = "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx"; OfflinePunctuationModelConfig modelConfig = diff --git a/sherpa-onnx/csrc/offline-punctuation-ct-transformer-impl.h b/sherpa-onnx/csrc/offline-punctuation-ct-transformer-impl.h index 4414a5a8f..9699563cb 100644 --- a/sherpa-onnx/csrc/offline-punctuation-ct-transformer-impl.h +++ b/sherpa-onnx/csrc/offline-punctuation-ct-transformer-impl.h @@ -9,6 +9,11 @@ #include #include +#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/math.h" #include "sherpa-onnx/csrc/offline-ct-transformer-model.h" @@ -24,6 +29,12 @@ class OfflinePunctuationCtTransformerImpl : public OfflinePunctuationImpl { const OfflinePunctuationConfig &config) : config_(config), model_(config.model) {} +#if __ANDROID_API__ >= 9 + OfflinePunctuationCtTransformerImpl(AAssetManager *mgr, + const OfflinePunctuationConfig &config) + : config_(config), model_(mgr, config.model) {} +#endif + std::string AddPunctuation(const std::string &text) const override { if (text.empty()) { return {}; diff --git a/sherpa-onnx/csrc/offline-punctuation-impl.cc b/sherpa-onnx/csrc/offline-punctuation-impl.cc index 730a25c8a..ed943fcc4 100644 --- a/sherpa-onnx/csrc/offline-punctuation-impl.cc +++ b/sherpa-onnx/csrc/offline-punctuation-impl.cc @@ -4,6 +4,11 @@ #include "sherpa-onnx/csrc/offline-punctuation-impl.h" +#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/offline-punctuation-ct-transformer-impl.h"