在Java中将数据发送到Windows桌面的PocketSphinx
这是我的线程函数在Java中将数据发送到Windows桌面的PocketSphinx,java,desktop,pocketsphinx,Java,Desktop,Pocketsphinx,这是我的线程函数 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 (
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();
}
在这种情况下,我的麦克风持续录制,甚至在停止麦克风之前,我会将音频输入流数据发送到decoder.processRaw。我试过了,但不知怎么的。dll库未返回任何日志和解码器。hyp()也将显示为null。连续不断地。我认为记录器线程和解码器库线程弄乱了。在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);
请帮助这一行:
d.processRaw(s, nbytes, false, false);
是一种冒犯,您发送了两次数据,但发送的数据大小错误。您需要将其删除,因为之前已发送数据进行处理
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());
}
您可以大胆地打开rawdata并聆听,它应该是干净的语言。在您的情况下,它已损坏,因为您没有正确地将数据发送到解码器。您需要说明如何初始化解码器。您还需要添加
-rawlogdir
来存储原始音频日志。@NikolayShmyrev请查看编辑您需要共享相关数据文件,您需要将日志存储到文件中并共享它。您能告诉我您需要哪些数据文件吗?原始音频日志,gramIs:我们有什么特殊的音频格式需要遵循吗?我不知道你说的“遵循”是什么意思。音频是16khz 16位单声道。非常感谢@Nikolay,我现在可以得到结果了。我想还有最后一步。当语音检测开始时,一旦它检测到某个东西,即使我一直在说其他东西,假设也不会改变。意思是根据我的语法。如果我说,先选22,我现在得到了正确的假设,没有停止任何操作。如果我改变我的陈述,选择85,那么它仍然只打印旧的假设。。它应该得到更新,正如我所说的,对吗?当检测到单词时,你需要在d.endUtt时结束话语,然后用d.startUtt重新开始。请查看此链接。我需要你尽快的帮助。[