Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2009, 07:01 PM
Member
 
Join Date: Mar 2009
Posts: 8
Rep Power: 0
Lynx09 is on a distinguished road
Default Help with null pointer in voice recognition application
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();
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 04-16-2009, 07:08 PM
OrangeDog's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Cambridge, UK
Posts: 838
Rep Power: 2
OrangeDog is on a distinguished road
Default
Putting your code in [code] tags will make it far easier to read.

There's nothing in the second line that can throw a NullPointerException. Unless you mean the line that prints a 2, in which case grammer or rec or both are null. You'll need to add more checks to find out which.
__________________
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-17-2009, 02:06 AM
Senior Member
 
Join Date: Jan 2009
Posts: 360
Rep Power: 2
toadaly is on a distinguished road
Default
FileReader throws an exception if the file is not a normal readbale file, so it should not be possible for the constructor to return 'null'. So the problem is not that.

Central.createRecognizer will return null if no recognizer is available matching your request, so my guess is that's what's going on, and 'rec' is null.

You can use
Code:
EngineList list = Central.availableRecognizers(desc);
To determine the available engines.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-20-2009, 01:01 PM
Member
 
Join Date: Mar 2009
Posts: 8
Rep Power: 0
Lynx09 is on a distinguished road
Default
I looked up EngineList and availableRecognizers() in the java speech api specification. When I looked at the debugger to see the size of EngineList it showed me a zero. In other posts I saw that people had problems just like me with nullpointers in their recognition code. They said that I needed Microsoft Speech SDK 5.1. Other than that I would not know why the EngineList is saying I don't have any available recognizers, I created a recognizer object. I briefly looked at locales up in the specifiaction, it deals with area codes and information on the country that is typed in. Do I need mircosoft Speech SDK 5.1?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-21-2009, 07:38 AM
Senior Member
 
Join Date: Jan 2009
Posts: 360
Rep Power: 2
toadaly is on a distinguished road
Default
If it's returnign a zero length list, then yes, it sounds like you don't have a speech engine installed. The java speech API requires a third party extension for both synthesis and recognition. Microsoft Speech API will work, but if you want opensource, you might look into FreeTTS (I think this is synthesis only, not recognition).
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Null pointer exception Stephenmak New To Java 5 04-01-2009 03:17 PM
null pointer help mayhewj7 New To Java 5 02-18-2009 12:51 AM
How to start voice based application pradnya Sun Java Wireless Toolkit 3 02-13-2009 12:49 PM
Null Pointer Exception ScKaSx New To Java 1 01-24-2009 12:27 PM
Null Pointer Exception Jacinth New To Java 4 01-22-2009 02:47 PM


All times are GMT +2. The time now is 10:49 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org