Package edu.cmu.pocketsphinx

Examples of edu.cmu.pocketsphinx.Decoder


        Config c = Decoder.defaultConfig();
        c.setFloat("-samprate", 8000);
        c.setString("-hmm", "../../model/hmm/en_US/hub4wsj_sc_8k");
        c.setString("-lm", "../../model/lm/en_US/hub4.5000.DMP");
        c.setString("-dict", "../../model/lm/en_US/hub4.5000.dic");
        Decoder d = new Decoder(c);
        AudioInputStream ais = null;
        try {
            URL testwav = new URL("file:../../test/data/wsj/n800_440c0207.wav");
            AudioInputStream tmp = AudioSystem.getAudioInputStream(testwav);
            // Convert it to the desired audio format for PocketSphinx.
            AudioFormat targetAudioFormat =
                new AudioFormat((float)c.getFloat("-samprate"),
                                16, 1, true, true);
            ais = AudioSystem.getAudioInputStream(targetAudioFormat, tmp);
        } catch (IOException e) {
            fail("Failed to open " + e.getMessage());
        } catch (UnsupportedAudioFileException e) {
            fail("Unsupported file type of " + e.getMessage());
        }

        d.startUtt("");
        byte[] b = new byte[4096];
        try {
            int nbytes;
            while ((nbytes = ais.read(b)) >= 0) {
                ByteBuffer bb = ByteBuffer.wrap(b, 0, nbytes);
                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());
        }
    }
View Full Code Here

TOP

Related Classes of edu.cmu.pocketsphinx.Decoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.