I try to get run the live transcription of mozilla deepspeech, but I have a few problems. This is the class code:
import org.mozilla.deepspeech.libdeepspeech.DeepSpeechModel;
import org.mozilla.deepspeech.libdeepspeech.DeepSpeechStreamingState;
import javax.sound.sampled.*;
import java.io.IOException;
public class Handler implements Runnable {
private DeepSpeechModel model;
private AudioInputStream audio;
private boolean active = false;
private String slash;
public Handler(String slash){
this.slash=slash;
}
@Override
public void run() {
active = true;
//model = new DeepSpeechModel("G:"+slash+"deepspeech"+slash+"deepspeech-0.7.0-models.pbmm", 50);
model=new DeepSpeechModel("/home/jochen/deepspeech/deepspeech-0.7.1-models.pbmm");
DeepSpeechStreamingState state = model.createStream();
int sampleRate = 16000;
AudioFormat format = new AudioFormat(sampleRate, 16, 1, true, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported");
System.exit(0);
}
TargetDataLine line = null;
try {
line = (TargetDataLine) AudioSystem.getLine(info);
} catch (LineUnavailableException e) {
e.printStackTrace();
}
try {
line.open(format);
} catch (LineUnavailableException e) {
e.printStackTrace();
}
line.start();
AudioInputStream audio = new AudioInputStream(line);
while (active) {
byte[] bytes = new byte[16];
short[] buffer = new short[8];
try {
audio.read(bytes);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < buffer.length; i++) {
buffer[i] = (short) ((buffer[i * 2] & 0xff) | (buffer[i * 2 + 1] << 8));
}
model.feedAudioContent(state, buffer, 8);
System.out.println(model.intermediateDecode(state));
}
System.out.println("final:" + model.finishStream(state));
}
public void stopTranscription() {
active = false;
}
public static void main(String[] args) {
Handler handler = new Handler("\\");
Thread thr = new Thread(handler);
thr.start();
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.stopTranscription();
}
}
Sorry I'm new here. So I put two .so-files in /usr/lib, called libdeepspeech.so and libdeepspeech-jni.so. Then I got the error, that there is no liblog.so. So I put this file from the android-ndk in /usr/lib, too. But here is my problem: I did the 32-bit liblog.so in /usr/lib, so I got the following error:
Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: /usr/lib/libdeepspeech-jni.so: liblog.so: falsche ELF-Klasse: ELFCLASS32
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2452)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2508)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2704)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2669)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:807)
at java.base/java.lang.System.loadLibrary(System.java:1907)
at org.mozilla.deepspeech.libdeepspeech.DeepSpeechModel.<clinit>(DeepSpeechModel.java:9)
at ProjectAthene.ebene1.deepspeech.Handler.run(Handler.java:24)
at java.base/java.lang.Thread.run(Thread.java:832)
Process finished with exit code 0
So I thought that I have to put the 64-bit liblog.so in /usr/lib, but his error happened:
Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: /usr/lib/libdeepspeech-jni.so: liblog.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2452)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2508)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2704)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2669)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:807)
at java.base/java.lang.System.loadLibrary(System.java:1907)
at org.mozilla.deepspeech.libdeepspeech.DeepSpeechModel.<clinit>(DeepSpeechModel.java:9)
at ProjectAthene.ebene1.deepspeech.Handler.run(Handler.java:24)
at java.base/java.lang.Thread.run(Thread.java:832)
Process finished with exit code 0
And yes the .so-file is really in /usr/lib, together with the android-ndk. Does anybody has an idea how to fix that? I'm also ok with a completely new code, but it has to be a live transcription during speaking. Something like aws or the live-transcribe-speech-engine from google. I hope you can help me!
Have a nice day and sorry for my bad english!