Results 1 to 8 of 8
- 04-16-2009, 06:01 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 8
- Rep Power
- 0
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();
- 04-16-2009, 06:08 PM #2
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
- 04-17-2009, 01:06 AM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
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
To determine the available engines.Java Code:EngineList list = Central.availableRecognizers(desc);
- 04-20-2009, 12:01 PM #4
Member
- Join Date
- Mar 2009
- Posts
- 8
- Rep Power
- 0
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?
- 04-21-2009, 06:38 AM #5
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
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).
- 07-30-2010, 09:04 AM #6
Member
- Join Date
- Jul 2010
- Posts
- 1
- Rep Power
- 0
Same problem but no solution!
Dear Lynx09,
i am facing your same problem with java speech recognition:
the method createRecognizer(desc) returns null !!
I need to know how you solved this problem i you had please.
thank you anyway :)
- 12-15-2010, 11:32 AM #7
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Hi,
I have downloaded the speech SDK from this website is it fine.
Download details: Speech SDK 5.1
- 12-15-2010, 11:35 AM #8
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Null pointer exception
By Stephenmak in forum New To JavaReplies: 5Last Post: 04-01-2009, 02:17 PM -
null pointer help
By mayhewj7 in forum New To JavaReplies: 5Last Post: 02-17-2009, 11:51 PM -
How to start voice based application
By pradnya in forum Sun Java Wireless ToolkitReplies: 3Last Post: 02-13-2009, 11:49 AM -
Null Pointer Exception
By ScKaSx in forum New To JavaReplies: 1Last Post: 01-24-2009, 11:27 AM -
Null Pointer Exception
By Jacinth in forum New To JavaReplies: 4Last Post: 01-22-2009, 01:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks