Hi, I have been trying to get the Jsapi (Java Speech API) embeded into my web applet but have had quite a few troubles. The script for the Jsapi from what I can see was designed for .Jav files where as I am trying to make a .class file. So my problem is that when I use the following code, although netbeans can view to code fine other than the draw function. But when I export the file and try it in the web browser the web browser repeats the following error hundreds of times:
Exception in thread "AWT-EventQueue-5" java.lang.NullPointerException
at java.awt.LightweightDispatcher$3.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
And my code is as follows:
// required when you create an applet
import java.applet.*;
// required to paint on screen
import java.awt.*;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
public class voice extends Applet {
public void init()
{
}
// This method gets called when the applet is terminated
// That's when the user goes to another page or exits the browser.
public void stop()
{
// meant be be empty.
}
// The standard method that you have to use to paint things on screen
public void paint(Graphics g)
{
//in here is the paint data.
g.drawString("This is a sample",10,20);
}
public static void main(String[] args) {
String voiceName = (args.length > 0)
? args[0]
: "kevin16";
/* The VoiceManager manages all the voices for FreeTTS.
*/
VoiceManager voiceManager = VoiceManager.getInstance();
Voice helloVoice = voiceManager.getVoice(voiceName);
/* Allocates the resources for the voice.
*/
helloVoice.allocate();
/* Synthesize speech.
*/
helloVoice.speak("Thank you for giving me a voice. "
+ "I'm so glad to say hello to this world.");
/* Clean up and leave.
*/
helloVoice.deallocate();
/// System.exit(0);
}
}
And the Jsapi is found at http://freetts.sourceforge.net/docs/index.php
I have read that there is some common error with the AWT-EventQueue and the Jsapi but cannot find a solution. Any other java applet text to speech alternatives are also welcome. Please help to solve this problem as I can't find any way around it.
PS: This is my second attempt at the language Java and although Java seems like a great language I just find it hard to find the right functions/code to use.