Add Java and Kotlin API for punctuation models (#818)

This commit is contained in:
Fangjun Kuang
2024-04-26 22:06:48 +08:00
committed by GitHub
parent db25986240
commit 5407f880c0
19 changed files with 515 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
// Copyright 2024 Xiaomi Corporation
package com.k2fsa.sherpa.onnx;
public class OfflinePunctuation {
static {
System.loadLibrary("sherpa-onnx-jni");
}
private long ptr = 0; // this is the asr engine ptrss
public OfflinePunctuation(OfflinePunctuationConfig config) {
ptr = newFromFile(config);
}
public String addPunctuation(String text) {
return addPunctuation(ptr, text);
}
@Override
protected void finalize() throws Throwable {
release();
}
// You'd better call it manually if it is not used anymore
public void release() {
if (this.ptr == 0) {
return;
}
delete(this.ptr);
this.ptr = 0;
}
private native void delete(long ptr);
private native long newFromFile(OfflinePunctuationConfig config);
private native String addPunctuation(long ptr, String text);
}