1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
/**
* Copyright 2003 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and
* redistribution of this file, and for a DISCLAIMER OF ALL
* WARRANTIES.
*/
import com.sun.speech.freetts.jsapi.FreeTTSEngineCentral;
import java.util.Locale;
import javax.speech.EngineList;
import javax.speech.EngineCreate;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
/**
* A talking clock powered by FreeTTS.
*/
public class JSAPIClock extends Clock {
protected Synthesizer synthesizer;
/**
* Creates the synthesizer, called by the constructor.
*/
public void createSynthesizer() {
try {
SynthesizerModeDesc desc =
new SynthesizerModeDesc(null,
"time",
Locale.US,
Boolean.FALSE,
null);
FreeTTSEngineCentral central = new FreeTTSEngineCentral();
EngineList list = central.createEngineList(desc);
if (list.size() > 0) {
EngineCreate creator = (EngineCreate) list.get(0);
synthesizer = (Synthesizer) creator.createEngine();
}
if (synthesizer == null) {
System.err.println("Cannot create synthesizer");
System.exit(1);
}
synthesizer.allocate();
synthesizer.resume();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Speaks the given time in full text.
*
* @param time time in full text
*/
protected void speak(String time) {
synthesizer.speakPlainText(time, null);
}
/**
* main() method to run the JSAPIClock.
*/
public static void main(String args[]) {
Clock frame = new JSAPIClock();
frame.pack();
frame.setVisible(true);
frame.createSynthesizer();
frame.startClock();
}
}
|