Text to Speech

Y

yuen

I would like to write a program support Text to Speech, here is the source
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));

System.out.println(synth);
// 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 don't why it returns null for "synth". I have already installed SAPI5.1,
can someone give me advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top