这是我的线程函数
public void run() {
recorder.start();
d.startUtt();
d.setRawdataSize(300000);
byte[] b = new byte[4096];
// Skip the first buffer, usually zeroes
recorder.read(b, 0, b.length);
while ((!interrupted()))
{
int nbytes;
short[] s = null;
nbytes = recorder.read(b, 0, b.length);
ByteBuffer bb = ByteBuffer.wrap(b, 0, nbytes);
s = new short[nbytes/2];
bb.asShortBuffer().get(s);
d.processRaw(s, nbytes/2, false, false);
if (nbytes > 0)
{
d.processRaw(s, nbytes, false, false);
Hypothesis hypothesis = d.hyp();
if(hypothesis != null)
System.out.println(hypothesis.getHypstr());
}
if (this.timeoutSamples != -1) {
this.remainingSamples -= nbytes;
}
}
recorder.stopRecording();
d.endUtt();
}
在这种情况下,我的麦克风正在连续录制,我什至在停止麦克风之前将 audioInputStream 数据发送到 decoder.processRaw。我试过这个,但不知何故。.dll 库不返回任何日志,decoder.hyp() 也为空。不断地。我认为记录器线程正在与解码器库线程混淆。在 C 库中。
编辑:解码器的初始化
Config c = Decoder.defaultConfig();
String acousticModelLoc = "speech\\model\\en-us-ptm";
String dictLoc = "dictionary\\cmudict-en-us.dict";
String kwFileLoc = "speech\\grammar\\digits.gram";
c.setString("-hmm", acousticModelLoc);
c.setString("-jsgf", kwFileLoc);
c.setString("-dict", dictLoc);
d = new Decoder(c);
请帮忙