Add Java and Kotlin API for punctuation models (#818)
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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 {};
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -19,4 +24,16 @@ std::unique_ptr<OfflinePunctuationImpl> OfflinePunctuationImpl::Create(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
std::unique_ptr<OfflinePunctuationImpl> OfflinePunctuationImpl::Create(
|
||||
AAssetManager *mgr, const OfflinePunctuationConfig &config) {
|
||||
if (!config.model.ct_transformer.empty()) {
|
||||
return std::make_unique<OfflinePunctuationCtTransformerImpl>(mgr, config);
|
||||
}
|
||||
|
||||
SHERPA_ONNX_LOGE("Please specify a punctuation model! Return a null pointer");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#if __ANDROID_API__ >= 9
|
||||
#include "android/asset_manager.h"
|
||||
#include "android/asset_manager_jni.h"
|
||||
#endif
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-punctuation.h"
|
||||
|
||||
@@ -19,6 +23,11 @@ class OfflinePunctuationImpl {
|
||||
static std::unique_ptr<OfflinePunctuationImpl> Create(
|
||||
const OfflinePunctuationConfig &config);
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
static std::unique_ptr<OfflinePunctuationImpl> Create(
|
||||
AAssetManager *mgr, const OfflinePunctuationConfig &config);
|
||||
#endif
|
||||
|
||||
virtual std::string AddPunctuation(const std::string &text) const = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-punctuation.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-impl.h"
|
||||
|
||||
@@ -33,6 +38,12 @@ std::string OfflinePunctuationConfig::ToString() const {
|
||||
OfflinePunctuation::OfflinePunctuation(const OfflinePunctuationConfig &config)
|
||||
: impl_(OfflinePunctuationImpl::Create(config)) {}
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
OfflinePunctuation::OfflinePunctuation(AAssetManager *mgr,
|
||||
const OfflinePunctuationConfig &config)
|
||||
: impl_(OfflinePunctuationImpl::Create(mgr, config)) {}
|
||||
#endif
|
||||
|
||||
OfflinePunctuation::~OfflinePunctuation() = default;
|
||||
|
||||
std::string OfflinePunctuation::AddPunctuation(const std::string &text) const {
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
#include "android/asset_manager.h"
|
||||
#include "android/asset_manager_jni.h"
|
||||
#endif
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-punctuation-model-config.h"
|
||||
#include "sherpa-onnx/csrc/parse-options.h"
|
||||
|
||||
@@ -33,6 +38,11 @@ class OfflinePunctuation {
|
||||
public:
|
||||
explicit OfflinePunctuation(const OfflinePunctuationConfig &config);
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
OfflinePunctuation(AAssetManager *mgr,
|
||||
const OfflinePunctuationConfig &config);
|
||||
#endif
|
||||
|
||||
~OfflinePunctuation();
|
||||
|
||||
// Add punctuation to the input text and return it.
|
||||
|
||||
Reference in New Issue
Block a user