问题
Here is my thread function
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();
}
In this my microphone is continuously recording and i am sending the audioInputStream data to decoder.processRaw before even stopping microphone. I tried this but somehow. .dll library is not returning any logs and decoder.hyp() is also coming as null. continuously. I think that recorder thread is messing with the decoder library thread. in C library.
EDIT: initialization of decoder
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);
PLEASE help
回答1:
This line:
d.processRaw(s, nbytes, false, false);
is offensive, you send the data twice and you send the wrong size of the data. You need to remove it since you already send data for processing before.
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());
}
You can open rawdata in audacity and listen, it should be clean speech. In your case it is corrupted since you do not send data properly to the decoder.
来源:https://stackoverflow.com/questions/35084097/sending-data-to-pocketsphinx-for-windows-desktop-in-java