This discussion is archived
1 Reply Latest reply: Jul 11, 2010 11:32 AM by 843802 RSS

problem whith jsapi(nullpointerException) help! help! help!

843802 Newbie
Currently Being Moderated
hello,

I have a code for speech to text converting!

but i have a problem!

please help me to convert Speech to text!

tnx everyone!

my code is a hello world class:

import javax.speech.*;
import javax.speech.recognition.*;
import java.io.FileReader;
import java.util.Locale;


public class HelloWorld extends ResultAdapter {
     static Recognizer rec;



     // Receives RESULT_ACCEPTED event: print it, clean up, exit
     public void resultAccepted(ResultEvent e)
throws EngineException // declare the exception!
{
try{
          Result r = (Result)(e.getSource());
          ResultToken tokens[] = r.getBestTokens();

          for (int i = 0; i < tokens.length; i++)
               System.out.print(tokens.getSpokenText() + " ");
          System.out.println();

          // Deallocate the recognizer and exit
          rec.deallocate();
          System.exit(0);
}catch(EngineException eeee){System.out.print(eeee);}
     }

     public static void main(String args[]) {
          try {
               // Create a recognizer that supports English.
               rec = Central.createRecognizer(
                                   new EngineModeDesc(Locale.ENGLISH));

               // Start up the recognizer
               rec.allocate();

               // Load the grammar from a file, and enable it
               FileReader reader = new FileReader("g.in");
               RuleGrammar gram = rec.loadJSGF(reader);
               gram.setEnabled(true);

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

               // Commit the grammar
               rec.commitChanges();

               // Request focus and start listening
               rec.requestFocus();
               rec.resume();
          } catch (Exception e) {
               e.printStackTrace();
          }
     }
}


the problem is:

java.lang.NullPointerException

at testapi.HelloWorld.main(HelloWorld.java:38)
  • 1. Re: problem whith jsapi(nullpointerException) help! help! help!
    843802 Newbie
    Currently Being Moderated
    hai did u executed this program,if u had can u say me how to solve " nullpointerException"
    import javax.speech.*;
    import javax.speech.recognition.*;
    import java.io.FileReader;
    import java.util.Locale;

    public class HelloWorld 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() + " ");
              System.out.println();

              // Deallocate the recognizer and exit
              try
              {
              rec.deallocate();
              }
              catch(Exception e1)
              {
              }
              System.exit(0);
         }

         public static void main(String args[]) {
              try {
                   // Create a recognizer that supports English.
                   rec = Central.createRecognizer(
                                       new EngineModeDesc(Locale.ENGLISH));
                   
                   // Start up the recognizer
                   rec.allocate();
         
                   // Load the grammar from a file, and enable it
                   FileReader reader = new FileReader(args[0]);
                   RuleGrammar gram = rec.loadJSGF(reader);
                   gram.setEnabled(true);
         
                   // Add the listener to get results
                   rec.addResultListener(new HelloWorld());
         
                   // Commit the grammar
                   rec.commitChanges();
         
                   // Request focus and start listening
                   rec.requestFocus();
                   rec.resume();
              } catch (Exception e) {
                   e.printStackTrace();
              }
         }
    }