Simple Java Speech API program always gives a null pointer exception on synthesizer.allocate()...why?? how can i use system voice in my java program using JSAPI ?
Printable View
Simple Java Speech API program always gives a null pointer exception on synthesizer.allocate()...why?? how can i use system voice in my java program using JSAPI ?
Can you post a small program that compiles, execute and shows the problems.
Also copy the full text of the error messages and post it here.
import javax.speech.synthesis.*;
import java.util.Locale;
public class HelloWorld {
public static void main(String args[]) {
try {
// Create a synthesizer for English
Synthesizer synth = Central.createSynthesizer(
new SynthesizerModeDesc(Locale.ENGLISH));
// Get it ready to speak
synth.allocate();
synth.resume();
// Speak the "Hello world" string
synth.speakPlainText("Hello, world!", null);
// Wait till speaking is done
synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
// Clean up
synth.deallocate();
} catch (Exception e) {
e.printStackTrace();
}
}
}
error.....
java.lang.NullPointerException
at HelloWorld.main(HelloWorld.java:22)
Where did you get the javax.speech package you are using?