在 Java 中将 Windows 桌面的数据发送到 PocketSphinx
Sending data to PocketSphinx for Windows desktop in Java
这是我的线程函数
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);
请帮忙
这一行:
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());
}
你可以在audacity中打开rawdata听,应该是干净的语音。在您的情况下,它已损坏,因为您没有将数据正确发送到解码器。
这是我的线程函数
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);
请帮忙
这一行:
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());
}
你可以在audacity中打开rawdata听,应该是干净的语音。在您的情况下,它已损坏,因为您没有将数据正确发送到解码器。