Skip to content

Commit

Permalink
fix for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Apr 26, 2024
1 parent d29902c commit d118e0d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions java-api-examples/AddPunctuation.java
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
11 changes: 11 additions & 0 deletions sherpa-onnx/csrc/offline-punctuation-ct-transformer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {};
Expand Down
5 changes: 5 additions & 0 deletions sherpa-onnx/csrc/offline-punctuation-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit d118e0d

Please sign in to comment.