I am a bit stuck. The first line in main method executes. After that I get a null pointer Exception. I printed a number after each line to find out which line is throwing the exception. heres my code:
import javax.speech.*;
import javax.speech.recognition.*;
import java.util.Locale;
import java.io.FileReader;
import java.io.*;
import javax.speech.EngineException;
import javax.speech.AudioException;
import java.net.*;
//used for robot
import java.awt.Robot.*;
import java.awt.*;
public class Rec extends ResultAdapter
{
static Recognizer rec;
private String str;
public void resultAccepted(ResultEvent re)
{
try{
Robot robot = new Robot();
}catch(Exception e){}
System.out.println("Error");
}
public static void main(String[] args){
try{
rec = Central.createRecognizer(new EngineModeDesc(Locale.ENGLISH));
FileReader grammar = new FileReader("E:/VoiceRecognition/voice.command.txt"); System.out.println("1");
RuleGrammar rg = rec.loadJSGF(grammar); System.out.println("2");
rg.setEnabled(true); System.out.println("3");
rec.addResultListener(new Rec()); System.out.println("4");
rec.commitChanges(); System.out.println("5");
rec.requestFocus(); System.out.println("6");
rec.resume(); System.out.println("7");
}
catch(EngineException e){
System.out.println("EngineException");}
catch(GrammarException e){System.out.println("GrammarException");}
catch(IOException e){System.out.println(" IOException");}
catch(EngineStateError e){System.out.println("EngineStateError");}
catch(AudioException e){System.out.println("AudioException");}
}
}
and here is my code for the grammars in case it is that the program is having a hard time finding the grammars.:
#JSGF V1.0;
grammar voice.command;
// Body
public <command> = <action> (one | two | three | four | five | six | seven | eight | ate | nine | ten | tin | tab | shift | space);
<action> = press | release;
All I need to know how to make the program to work so the listener can call resultAccepted();