954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Runtime Error - JSAPI HelloWorld Program

While running basic HelloWorld program using JSAPI, it is showing error "java.lang.NullPointerException at HelloWorld.main(HelloWorld.java:11)"

Following is the code:

import javax.speech.*;
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();
    }
}
}

I edit my program:

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

public class HelloWorld {
public static void main(String args[]) {
    try {
        // Create a synthesizer for English
        SynthesizerModeDesc modeDesc = new SynthesizerModeDesc(null,"general",Locale.US,null,null);
        System.out.println(modeDesc);
        Synthesizer synth = Central.createSynthesizer(modeDesc);
        //Synthesizer synth = Central.createSynthesizer(null);
        // Get it ready to speak
        System.out.println(synth);
        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();
    }
}
}

and it is giving output:

javax.speech.synthesis.SynthesizerModeDesc@9304b1
null
java.lang.NullPointerException
    at HelloWorld.main(HelloWorld.java:15)

It seems that SynthesizerModeDesc is working fine but it is not detecting any engine as i tried passing null also to the function Central.createSynthesizer (i.e get default engine) but still it is returning null. I checked number of engines it is detecting, but it shows 0.

Please help me !! :(

roshan_iiita
Light Poster
30 posts since Nov 2011
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: