I am using the java code given below for decoding a wav file in my pocketsphinx android application .
Its working, but its sometimes not giving correct decoding results. Can I set any type of threshold for recognition accuracy with this code? And how?
public class PocketSphinxAsync extends AsyncTask<void, void,="" string=""> {
final Decoder[] d = new Decoder[1];
final String[] result = new String[1];
private Assets assets;
Context ctx;
public AsyncResponse delegate=null;
File assetsDir;
File ff;</void,>
PocketSphinxAsync(Context c, File f, AsyncResponse asyncResponse)
{
this.delegate=asyncResponse;
this.ctx=c;
this.ff=f;
}
static {
System.loadLibrary("pocketsphinx_jni");
}
@Override
protected String doInBackground(Void... voids) {
try {
FileInputStream st;
Config c;
Assets assets = new Assets(ctx);
File assetsDir = assets.syncAssets();
st = new FileInputStream(ff);
boolean isCancelled=false;
c= Decoder.defaultConfig();
c.setString("-hmm", new File(assetsDir, "Model_full").getPath());
c.setString("-dict", new File(assetsDir, "Model_full.dic").getPath());
c.setBoolean("-allphone_ci", true);
c.setString("-lm", new File(assetsDir, "Model_full.arpa").getPath());
d[0] = new Decoder(c);
d[0].startUtt();
byte[] b = new byte[4096];
try {
int nbytes;
while ((nbytes = st.read(b)) >= 0) {
ByteBuffer bb = ByteBuffer.wrap(b, 0, nbytes);
// Not needed on desktop but required on android
bb.order(ByteOrder.LITTLE_ENDIAN);
short[] s = new short[nbytes/2];
bb.asShortBuffer().get(s);
d[0].processRaw(s, nbytes/2, false, false);
}
} catch (IOException e) {
fail("Error when reading inputstream" + e.getMessage());
}
d[0].endUtt();
result[0] = d[0].hyp().getHypstr();
for (Segment seg : d[0].seg()) {
//do something with the result here
}
isCancelled=true;
} catch (IOException e) {
e.printStackTrace();
}
return result[0];
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hai all,
I am using the java code given below for decoding a wav file in my pocketsphinx android application .
Its working, but its sometimes not giving correct decoding results. Can I set any type of threshold for recognition accuracy with this code? And how?
public class PocketSphinxAsync extends AsyncTask<void, void,="" string=""> {
final Decoder[] d = new Decoder[1];
final String[] result = new String[1];
private Assets assets;
Context ctx;
public AsyncResponse delegate=null;
File assetsDir;
File ff;</void,>
}