0 Replies Latest reply on Nov 5, 2011 6:53 PM by 898165

    Suitable Engine

      I used HelloWorld sample code from http://java.sun.com/products/java-media/speech/forDevelopers/jsapi-guide/Recognition.html#7408
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javax.speech.*;
      import javax.speech.recognition.*;
      import java.io.FileReader;
      import java.util.Locale;
      public class Main extends ResultAdapter {
           static Recognizer rec;
           // Receives RESULT_ACCEPTED event: print it, clean up, exit
           public void resultAccepted(ResultEvent e) {
                Result r = (Result)(e.getSource());
                ResultToken tokens[] = r.getBestTokens();
                for (int i = 0; i < tokens.length; i++)
                     System.out.print(tokens.getSpokenText() + " ");
      try {
      // Deallocate the recognizer and exit
      } catch (EngineException ex) {
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
      } catch (EngineStateError ex) {
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

           public static void main(String args[]) {
                try {

                     // Create a recognizer that supports English.

      EngineModeDesc mode =new EngineModeDesc(Locale.ENGLISH);
      rec = Central.createRecognizer(mode);
      //rec = Central.createRecognizer(new EngineModeDesc(null, null,java.util.Locale.ENGLISH, null));
      //rec = Central.createRecognizer();
      /*EngineList list = Central.availableRecognizers(mode);
      System.out.println("Recognizer yok");

      System.out.println("MODE IS NULL");
      System.out.println("MODE IS NOT NULL");

      if (rec == null)
      System.out.println("REC IS NULL");
      //EngineList list = Central.availableRecognizers(rec);*/

                     // Start up the recognizer
                     // Load the grammar from a file, and enable it
                     //FileReader reader = new FileReader(args[0]);
      String gramer="C:\\Users\\zackeriya\\Documents\\NetBeansProjects\\Hello_World_1\\dil.gram";
      FileReader reader = new FileReader(gramer);
                     RuleGrammar gram = rec.loadJSGF(reader);

                     // Add the listener to get results
                     rec.addResultListener(new Main());

                     // Commit the grammar

                     // Request focus and start listening
                } catch (Exception e) {
      When I compiled, I got this error "java.lang.NullPointerException at Main.main(Main.java:56)" ---> 
      56. rec.allocate();
       ... After long search I learnt that If no suitable engine is available, the methods return null. Here is the code which returns null 
      rec = Central.createRecognizer(mode);
      ... So how can I get or install engine to my computer ?