33 lines
712 B
Kotlin
33 lines
712 B
Kotlin
package com.k2fsa.sherpa.onnx
|
|
|
|
class OfflineStream(var ptr: Long) {
|
|
fun acceptWaveform(samples: FloatArray, sampleRate: Int) =
|
|
acceptWaveform(ptr, samples, sampleRate)
|
|
|
|
protected fun finalize() {
|
|
if (ptr != 0L) {
|
|
delete(ptr)
|
|
ptr = 0
|
|
}
|
|
}
|
|
|
|
fun release() = finalize()
|
|
|
|
fun use(block: (OfflineStream) -> Unit) {
|
|
try {
|
|
block(this)
|
|
} finally {
|
|
release()
|
|
}
|
|
}
|
|
|
|
private external fun acceptWaveform(ptr: Long, samples: FloatArray, sampleRate: Int)
|
|
private external fun delete(ptr: Long)
|
|
|
|
companion object {
|
|
init {
|
|
System.loadLibrary("sherpa-onnx-jni")
|
|
}
|
|
}
|
|
}
|