CrimsonKnight - 2016-06-01

This is a repost because I believe I was not very explicit in my question last time but I seem to be stuck. Please bear with me, I apologize in advance, I am new to pocketSphinx and Android.

So I am trying to read an audio file on my android device and I know that I need to change my config for this (something similar to this):

 Config c = Decoder.defaultConfig();
    c.setString("-hmm", "../../model/en-us/en-us");
    c.setString("-lm", "../../model/en-us/en-us.lm.dmp");
    c.setString("-dict", "../../model/en-us/cmudict-en-us.dict");
    Decoder d = new Decoder(c);

    URL testwav = new URL("file:../../test/data/goforward.wav");
    FileInputStream stream = new FileInputStream(new File(testwav)));

    d.startUtt();
    byte[] b = new byte[4096];
    try {
        int nbytes;
        while ((nbytes = stream.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.processRaw(s, nbytes/2, false, false);
        }
    } catch (IOException e) {
        fail("Error when reading goforward.wav" + e.getMessage());
    }
    d.endUtt();
    System.out.println(d.hyp().getHypstr());
    for (Segment seg : d.seg()) {
        System.out.println(seg.getWord());
    }
}

Now, I have seen a few examples online and on GitHub where this was implemented in the class RecognizerTask which was shipped with the Android Demo. However, I could not find any such class in the demo that I downloaded from the official site.

So could someone clarify where I should implement this or what s going on and what I should do to achieve my goal (read an audio file from memory and output text)?

Thanks!

 

Last edit: CrimsonKnight 2016-06-01