Add Kotlin and Java API for online punctuation models (#1936)

This commit is contained in:
Fangjun Kuang
2025-02-27 16:52:36 +08:00
committed by GitHub
parent 815ebac8f9
commit f5dfcf8d2f
16 changed files with 474 additions and 13 deletions

View File

@@ -0,0 +1,39 @@
// Copyright 2024 Xiaomi Corporation
package com.k2fsa.sherpa.onnx;
public class OnlinePunctuation {
static {
System.loadLibrary("sherpa-onnx-jni");
}
private long ptr = 0;
public OnlinePunctuation(OnlinePunctuationConfig 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(OnlinePunctuationConfig config);
private native String addPunctuation(long ptr, String text);
}