Results 1 to 8 of 8
  1. #1
    Lynx09 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    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();

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    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

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    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
    Java Code:
    EngineList list = Central.availableRecognizers(desc);
    To determine the available engines.

  4. #4
    Lynx09 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    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?

  5. #5
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    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).

  6. #6
    IM33 is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default 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 :)

  7. #7
    abhishekspage is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Hi,

    I have downloaded the speech SDK from this website is it fine.
    Download details: Speech SDK 5.1

  8. #8
    abhishekspage is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Null pointer exception
    By Stephenmak in forum New To Java
    Replies: 5
    Last Post: 04-01-2009, 02:17 PM
  2. null pointer help
    By mayhewj7 in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 11:51 PM
  3. How to start voice based application
    By pradnya in forum Sun Java Wireless Toolkit
    Replies: 3
    Last Post: 02-13-2009, 11:49 AM
  4. Null Pointer Exception
    By ScKaSx in forum New To Java
    Replies: 1
    Last Post: 01-24-2009, 11:27 AM
  5. Null Pointer Exception
    By Jacinth in forum New To Java
    Replies: 4
    Last Post: 01-22-2009, 01:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •