Hello All,

This is my first video tutorial. This tutorial demonstrates how to make a speech recognizer in java using Sphinx.

Requirements to work according to the tutorial :

1 ) JDK 6 ( J2SE )

2 ) Eclipse SDK ( Im using Eclipse 3.4.0 )

3 ) Sphinx 4.0

4 ) JSAPI ( Included in Sphinx 4.0 )

Tutorial is divided into 3 parts.

Please feel free to post your comments and suggestions on tutorial and help me to improve the quality.


98 Responses

  1. Pingback: Richelle Monclova
  2. Hi Puneet bhae

    your tutorial is great.

    i m working on a speech enabled search engine. i will be thankful if you give me some help.

    regard Shumaila

  3. Hi, your tutorial is of great help. I would like to ask some pointers, if it’s okay with you, regarding wav files and indexing. I need to get the time from a wav input. I’m working on it, and I’m sort of stuck. Thanks πŸ™‚

  4. Hi Puneet, My final year project is Home Automation System Using Speech Recognition. Now I am in trouble in speech recognition part. I have some class for testing speech recognition. But they throw me an exception, i.e NullPointerException and says mbrola.base is undefined.

    Now can you help me by giving some idea of this project in details…? Thank You.

  5. I saw your tutorial.. Very helpful one for me.. Great job. But Puneet, What will be the structure of helloworld.config.xml file?

  6. hey puneet…

    thanks a lot for ur tutorials…but i hav a question

    I want sphinx to recognize all the discrete words that the user speak..ie the words in the dictionary.. what grammar should i write??? ie without mentioning their token names separately in it.. please do help??

  7. hi kalra i have made a project on media player in java .Now i want to use sphinx for speech recognition as i want to play and stop the media through a speech .I have made a simple recogniser but when i run it give javax.speech.*; class not found error .so, can you give me the procedure for how to use sphinx for speech recognition.

    It is very urgent reply fast.

    Thanks in advance.

  8. Hi puneet i have studied your video you are using eclipse but i am using netbeans which does’nt give the same result ..Anyways i tried to run demo and it runs b’coz it was a jar file but when i make a java file and tried to run it through command prompt it won’t work .

    I am getting an error of Buildfile:build.xml does’nt exist.

    so tell me the steps of packing my java pgm into a jar file so that i can run it with java -Xmx256m -jar bin/HelloWorld.jar.

    Also i am using apache ant to build my sphinx and my pgm.

    please reply fast it’s urgent.

  9. how to make my recognizer to recognize complete english language instead of giving grammar for it. is it possible.

  10. Hello Puneet,

    I am developing a speech recogniser and translater in java. So i am using sphinx4 for the purpose. I am able to run all the demos (thanx to your video tutorial). I am very new in sphinx. I am stuck at how to use dictionary in my application so that i can get access to variety of words. I also need a little help in training. Please reply fast

  11. hi puneet,

    your post is very helpful.. Thanks for ur effort.

    Do u have any idea that how to handle punctuation marks in sphinx grammar??

    Thanks in advance.

  12. Hi puneet,

    I want to use sphinx in an applet.I have tried some demos to familier with sphinx in order to recognize and get the voice to text.but since in applet i don’t know how to access gram file.Can u please help me?thanks a lot!!

  13. hi puneet sir

    wil u plz tell me how to do changes in config.xml file.so we can add few more words to speech recognition system.

  14. please tell me how i put voice recognition in java project?

    i will do a project for autistic and the project have to take the voice response from the patient please help me in this part

    thanks a lot

  15. hi i want to ask how can i implement Helloworld program on the applet. i have tried bt it was not given any response neither result nor error. plz help me i’ll be thankful to you

  16. Good work making this tutorial.

    I was unable to understand the file required for my own implementation. It really helped.

    You could have saved some time by using voice input instead of typing it.

    Thanks, πŸ™‚

    Hassan Farid

  17. Hi….

    my name is Sangamesh. Now i am studying in final year B.E(Information Technology).For academic project in college I am doing one project which is based on sphinx4. My project is to develop application which will recognize our regional language “Kannada”. i am not getting that how to create new acoustic model for kannada language… so please help me.

  18. Pingback: paula alexander
  19. Hello. Just followed the tut and it works great. But i’m new to java and a i have a question for you. If i would say the word “beer” i want the program to give me a specific response for this word. Or if i say “Open browser” the program to open firefox. How can this be done? Thanks!

  20. ok, managed to make the modification, so you can delete the first request πŸ™‚ But now i have another problem. I’ve exported my project as .jar, and when i try to run it from command prompt i get this:

    Exception in thread “main” java.lang.NoClassDefFoundError: edu/cmu/sphinx/util/p


    at edu.cmu.sphinx.demo.helloworld.HelloWorld.main(HelloWorld.java:34)

    Caused by: java.lang.ClassNotFoundException: edu.cmu.sphinx.util.props.Configura


    at java.net.URLClassLoader$1.run(Unknown Source)

    at java.net.URLClassLoader$1.run(Unknown Source)

    at java.security.AccessController.doPrivileged(Native Method)

    at java.net.URLClassLoader.findClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    … 1 more

  21. hi,

    how to create a jar file of the speech recognizing program

    i want the jar file that can be executed that takes voice input and gives a text as output

    please respond fast.i have very less time to submit my project…thanks in advance

  22. Can we implement this in android ? I do not want to use the android Speech api for this because it is google dependent I can not customize my grammar.

  23. Hi Puneet, i’m 3th student, i’m doing my project about browse web by voice and used leangue is VietNamese, so How can i do that, because sphinx use English

  24. hello frd..!

    i gets some exception error like this during running the programe

    plzzz help me to solve this…! πŸ™

    Exception in thread “main” java.lang.NoSuchFieldError: engineListeners

    at com.sun.speech.engine.recognition.BaseRecognizer.fireRecognizerSuspended(BaseRecognizer.java:977)

    at com.sun.speech.engine.recognition.BaseRecognizer.dispatchSpeechEvent(BaseRecognizer.java:1273)

    at com.sun.speech.engine.SpeechEventUtilities.postSpeechEvent(SpeechEventUtilities.java:201)

    at com.sun.speech.engine.SpeechEventUtilities.postSpeechEvent(SpeechEventUtilities.java:132)

    at com.sun.speech.engine.recognition.BaseRecognizer.postRecognizerSuspended(BaseRecognizer.java:965)

    at com.sun.speech.engine.recognition.BaseRecognizer.commitChanges(BaseRecognizer.java:375)

    at edu.cmu.sphinx.jsapi.JSGFGrammar.createGrammar(JSGFGrammar.java:288)

    at edu.cmu.sphinx.linguist.language.grammar.Grammar.allocate(Grammar.java:123)

    at edu.cmu.sphinx.linguist.flat.FlatLinguist.allocate(FlatLinguist.java:225)

    at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.allocate(SimpleBreadthFirstSearchManager.java:576)

    at edu.cmu.sphinx.decoder.Decoder.allocate(Decoder.java:109)

    at edu.cmu.sphinx.recognizer.Recognizer.allocate(Recognizer.java:182)

    at demo.sphinx.helloworld.HelloWorld.main(HelloWorld.java:42)

    Java Result: 1

  25. Hello Sir. I am using Sphinx Voice Recognition tool in my project. Can u provide me a quick tutorial on its usage?

  26. Hello

    I am working on voice to text conversion for recorded calls on my website, calls will be in “UK accent”, I have mp3 files of those calls. I want calls to be kept in text document form.

    Please share your knowledge about this.

    I am using Linux OS, Please let me know if I can achieve my task using your software.

    Email for contact : sujitb@techhighway.co.in

    Thank you for your help

  27. i am trying the latticedemo sphinx but iam getting the error the code is

    package edu.cmu.sphinx.demo.lattice;

    import edu.cmu.sphinx.frontend.util.AudioFileDataSource;

    import edu.cmu.sphinx.recognizer.Recognizer;

    import edu.cmu.sphinx.result.Lattice;

    import edu.cmu.sphinx.result.LatticeOptimizer;

    import edu.cmu.sphinx.result.Result;

    import edu.cmu.sphinx.util.props.ConfigurationManager;

    import java.io.File;

    import java.io.IOException;

    import java.io.PrintStream;

    import java.net.URI;

    import java.net.URL;

    import javax.sound.sampled.UnsupportedAudioFileException;

    public class LatticeDemo


    public static void main(String[] args)

    throws IOException, UnsupportedAudioFileException


    URL audioURL;

    if (args.length > 0) {

    audioURL = new File(args[0]).toURI().toURL();

    } else {

    audioURL = LatticeDemo.class.getResource(“10001-90210-01803.wav”);


    URL url;

    if (args.length > 1) {

    url = new File(args[1]).toURI().toURL();

    } else {

    url = LatticeDemo.class.getResource(“config.xml”);



    ConfigurationManager cm = new ConfigurationManager(url);

    Recognizer recognizer = (Recognizer)cm.lookup(“recognizer”);


    AudioFileDataSource dataSource = (AudioFileDataSource)cm.lookup(“audioFileDataSource”);

    dataSource.setAudioFile(audioURL, null);

    boolean done = false;

    while (!done)


    Result result = recognizer.recognize();

    if (result != null)


    Lattice lattice = new Lattice( result);

    LatticeOptimizer optimizer = new LatticeOptimizer(lattice);



    String resultText = result.getBestResultNoFiller();

    System.out.println(“I heard: ” + resultText + “\n”);




    done = true;





    my error is:

    Exception in thread “main” java.lang.Error: Unresolved compilation problem:

    The constructor Lattice(Result) is undefined

    at edu.cmu.sphinx.demo.lattice.LatticeDemo.main(LatticeDemo.java:51)

    hepl me to solve the error

    1. Hi Puneet

      I need your help. I want to do a research on speech recognition on Kannada language. Please help me. I am unable to use ur tutorial properly. Please kindly help me



  28. Hi,

    When I run HelloWorld program the output is not as expected. For Example if I say Hello will it says Good morning. Why is this problem and how can I solve it?

  29. Dear Sir !

    I have a project on voice recognition system.i am new to this system & doesn’t know how to start.Can you please please guide me how can I start from scratch on Java or either MATLAB will be much better.Kindly guide me .Reply me ASAP.

    I will be waiting:)

  30. Dear Sir !

    I have a project on voice recognition system & doesn’t know how to start.Can you please please guide me how can I start from scratch on Java or either MATLAB will be much better.Kindly guide me .Reply me ASAP.

    I will be waiting:)

  31. I prepared custom message as per link. I updated in jar file also.But it throwing null pointer exception.

  32. Bro your explanation is excellent but I need to add extra words both manually and dynamically to the grammer file.So please help me to do that.

Leave a Reply

Your email address will not be published. Required fields are marked *