alphacep_vosk-api/java/test/DecoderTest.java
2020-01-19 22:07:47 +01:00

36 lines
975 B
Java

package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.*;
import org.kaldi.KaldiRecognizer;
import org.kaldi.Model;
public class DecoderTest {
static {
System.loadLibrary("vosk_jni");
}
public static void main(String args[]) throws IOException {
FileInputStream ais = new FileInputStream(new File("../python/example/test.wav"));
Model model = new Model("model-en");
KaldiRecognizer rec = new KaldiRecognizer(model, 16000.0f);
int nbytes;
byte[] b = new byte[4096];
while ((nbytes = ais.read(b)) >= 0) {
if (rec.AcceptWaveform(b, nbytes)) {
System.out.println(rec.Result());
} else {
System.out.println(rec.PartialResult());
}
}
System.out.println(rec.FinalResult());
}
}