hi! i am trying to build an application which will recognize speech and convert into text.For that i have installed jdk 1.6, Apache ant 1.8, sphinx4-1.0beta3-src and also set the paths etc. i am able to run the demos like given in C:\Program Files\Java\sphinx4-1.0beta3-src\sphinx4-1.0beta3\bin\HelloWorld.jar using java -mx256m -jar bin/HelloWorld.jar which is already built classes but if i am trying to compile the java the same java program HelloWorld.java wiith its grammar.gram file its giving me errors

HelloWorld.java:1: package javax.speech does not exist
import javax.speech.*;
^
HelloWorld.java:2: package javax.speech.recognition does not exist
import javax.speech.recognition.*;
^
HelloWorld.java:6: cannot find symbol
symbol: class ResultAdapter
public class HelloWorld extends ResultAdapter {
                                ^
HelloWorld.java:7: cannot find symbol
symbol  : class Recognizer
location: class HelloWorld
        static Recognizer rec;
               ^
HelloWorld.java:10: cannot find symbol
symbol  : class ResultEvent
location: class HelloWorld
        public void resultAccepted(ResultEvent e) {
                                   ^
HelloWorld.java:11: cannot find symbol
symbol  : class Result
location: class HelloWorld
                Result r = (Result)(e.getSource());
                ^
HelloWorld.java:11: cannot find symbol
symbol  : class Result
location: class HelloWorld
                Result r = (Result)(e.getSource());
                            ^
HelloWorld.java:12: cannot find symbol
symbol  : class ResultToken
location: class HelloWorld
                ResultToken tokens[] = r.getBestTokens();
                ^
HelloWorld.java:27: cannot find symbol
symbol  : class EngineModeDesc
location: class HelloWorld
                                                        new EngineModeDesc(Local
e.ENGLISH));
                                                            ^
HelloWorld.java:26: cannot find symbol
symbol  : variable Central
location: class HelloWorld
                        rec = Central.createRecognizer(
                              ^
HelloWorld.java:34: cannot find symbol
symbol  : class RuleGrammar
location: class HelloWorld
                        RuleGrammar gram = rec.loadJSGF(reader);

plz help me asap
thanx
                        ^
11 errors

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Isn't it kind of obvious? :D You dont have the javax.speech package, for that you need to download the JSAPI.jar, I dont think you are allowed to post download links here, but either ways some simple googling would suffice. In order for you to use it properly though, you might need an IDE like eclipse or netbeans. You can automatically import it from them ,and use it.

My note of warning to you, just using the demo CODE they supply might not work, I have tried speech recognition myself, it is NOT as easy as it seems, and is prone to error a LOT. If you do manage to get it working, I would suggest posting a tutorial, it can help others :) Good luck!

thanx for replying. I ve already downloaded sphinx which is containing jsapi.jar and i ve already set the environment variables but it's not wrking. I also copied the speech folder after xtracting from this jar file nd put it into the javax folder in jdk.bt still it's not working...plz help

Oh I see, infact your post intrigued me about Sphinx, I have always seen it, but never tried it, I followed their directions very closely, doing everything just like they said. It just seems not to work, no matter what I tried as well, not even the regular jars in the precompiled BINs worked properly. It seems to me that speech in java is just something beyond our control, at least at the moment. If I figure out a solution, I will tell you ;) :D

hi! i am trying to build an application which will recognize speech and convert into text.For that i have installed jdk 1.6, Apache ant 1.8, sphinx4-1.0beta3-src and also set the paths etc. i am able to run the demos like given in C:\Program Files\Java\sphinx4-1.0beta3-src\sphinx4-1.0beta3\bin\HelloWorld.jar using java -mx256m -jar bin/HelloWorld.jar which is already built classes but if i am trying to compile the java the same java program HelloWorld.java wiith its grammar.gram file its giving me errors

Code:

import javax.speech.*;
import javax.speech.recognition.*;
import java.io.FileReader;
import java.util.Locale;
import java.lang.NullPointerException;
import java.util.logging.Level; 
import java.util.logging.Logger;


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[i].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();


}
}
}

Errors:

java.lang.NullPointerException
    at HelloWorld.main(HelloWorld.java:40)

Edited 3 Years Ago by Nick Evan: Fixed formatting

You need to do three thing:

  1. What you need to do is you need to install the recogniser engine you need to download it from
    http://cloudgarden1.com/TalkingJavaSDK-170.zip

  2. After downloading it extract it and copy two files cgjsapi.jar,cgjsapi170.dll to \jre\lib\ext.

  3. Add this code to register your recogniser & speech engine.
    Add this code above any code inside the main

    public static void main(String args[]) {
    try {
    //Set the sound Properties
    System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");

    Central.registerEngineCentral
    ("com.cloudgarden.speech.CGEngineCentral");

If these code worked for just let me know..... :-)
Thanks.

Kind regards
Tumelo Modise

Edited 3 Years Ago by pyTony: fixed formatting

This article has been dead for over six months. Start a new discussion instead.