Hello everyone,
I've just been trying to run the basic JSAPI 'Hello World' program.

It's taken me a while to figure out how to get it to work (and
to download everything) but now I have it to this point.

I have a few of the same errors that pop up.

Here is the code:

package helloworldsynthesis;

import javax.speech.*;
import javax.speech.synthesis.*;
import java.util.Locale;

public class Main {
    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();
            }
	}
}

At lines: 14, 15, 18, 21 and 24 (WOW!) I have a java.lang.NullPointerException.

I would be very greatful for any help with this problem!

-WolfShield

Each of those lines uses the variable "synth" - so it's highly probable that that variable has not been initialised - which in turn suggests that line 11 (createSynthesiser) has failed at runtime. You can confirm this by printing synth immediately after line 11 to see if it is null.

Thanks,
Sorry about the time it took me to reply, I was gone for the weekend.

You are correct, when I ran the updated program it printed out 'null'
then the first error (line 16).

I'm assuming the error means that the variable 'synth' holds nothing despite
having the code after the '='.

So, does anyone have an idea as how to fix this problem?

Thank you very much for your help!!!

-WolfShield

The API doc for createSynthesiser syas

Create a Synthesizer with specified required properties. If there is no Synthesizer with the required properties the method returns null.

So, although you do have code after the =, that code may return "null", which is presumably what happened here.
I have never used this software, so I have no expertise in it, but reading the API leads me to two obvious things to try:
1. Call createSynthesiser with a null parameter to see if the default synth works.
2.. Call availableSynthesizers wiuth a null param to get a list of all the available synths, and use one of those in createSSynthesiser

Good luck

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