Speech Synthesis:
javax.speech.synthesis
· A speech synthesizer is a speech engine that converts text to speech. The javax.speech.synthesispackage defines the Synthesizer interface to support speech synthesis plus a set of supporting classes and interfaces. "Hello World!"
The following code shows a simple use of speech synthesis to speak the string "Hello World".
import javax.speech.synthesis.*;
public class HelloWorld { public static void main(String args[]) { // Create a synthesizer for English Synthesizer synth = Central.createSynthesizer( new SynthesizerModeDesc(Locale.ENGLISH));
// Speak the "Hello world" string synth.speakPlainText("Hello, world!", null);
// Wait till speaking is done synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
This example illustrates the four basic steps which all speech synthesis applications must perform. Let's examine each step in detail. · Create: The Central class of javax.speech package is used to obtain a speech synthesizer by calling the createSynthesizer method. The SynthesizerModeDesc argument provides the information needed to locate an appropriate synthesizer. In this example a synthesizer that speaks English is requested. · Allocate and Resume: The allocate and resume methods prepare the Synthesizer to produce speech by allocating all required resources and putting it in the RESUMED state. · Generate: The speakPlainText method requests the generation of synthesized speech from a string. · Deallocate: The waitEngineState method blocks the caller until the Synthesizer is in theQUEUE_EMPTY state - until it has finished speaking the text. The deallocate method frees the synthesizer's resources.
No comments:
Post a Comment