Java Api for a speech recognizer
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jayaranjani_G
Posted On:   Tuesday, March 31, 2009 01:25 AM

Hi...How to create audio recognizer API in java. pl provide the code asap...Also this the code im using to develop the api. im getting null pointer exception in this. can u solve this .. import javax.speech.*; import javax.speech.recognition.*; import java.io.FileReader; import java.util.Locale; 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() + " ");    More>>

Hi...How to create audio recognizer API in java. pl provide the code asap...Also this the code im using to develop the api. im getting null pointer exception in this. can u solve this ..

import javax.speech.*;
import javax.speech.recognition.*;
import java.io.FileReader;
import java.util.Locale;

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
//rec.deallocate();
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());

if (rec.testEngineState(Recognizer.FOCUS_ON)) {
// we have focus so release it
rec.releaseFocus();
}
// wait until we lose it
rec.waitEngineState(Recognizer.FOCUS_OFF);



// Commit the grammar
rec.commitChanges();

// Request focus and start listening
rec.requestFocus();
rec.resume();
} catch (Exception e) {
e.printStackTrace();
}
}
}

   <<Less
About | Sitemap | Contact