00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package voce;
00027
00028 import java.io.File;
00029 import java.util.Locale;
00030 import java.beans.PropertyChangeEvent;
00031 import java.beans.PropertyChangeListener;
00032
00033 import javax.speech.Central;
00034 import javax.speech.Engine;
00035 import javax.speech.EngineList;
00036 import javax.speech.EngineCreate;
00037 import javax.speech.EngineException;
00038 import javax.speech.EngineModeDesc;
00039 import javax.speech.synthesis.Synthesizer;
00040 import javax.speech.synthesis.SynthesizerModeDesc;
00041 import javax.speech.synthesis.SynthesizerProperties;
00042 import javax.speech.synthesis.Voice;
00043 import javax.speech.synthesis.Speakable;
00044 import javax.speech.synthesis.SpeakableAdapter;
00045 import javax.speech.synthesis.SpeakableEvent;
00046 import com.sun.speech.freetts.jsapi.FreeTTSEngineCentral;
00047
00050 public class SpeechSynthesizer
00051 {
00053 private Synthesizer mSynthesizer = null;
00054
00056 public SpeechSynthesizer(String name)
00057 {
00058
00059 Voice theVoice = new Voice(name,
00060 Voice.GENDER_DONT_CARE, Voice.AGE_DONT_CARE, null);
00061
00062 try
00063 {
00064
00065 SynthesizerModeDesc generalDesc = new SynthesizerModeDesc(
00066 null,
00067 "general",
00068 Locale.US,
00069 null,
00070 null);
00071
00072
00073
00074 FreeTTSEngineCentral central = new FreeTTSEngineCentral();
00075 EngineList list = central.createEngineList(generalDesc);
00076
00077 if (list.size() > 0)
00078 {
00079 EngineCreate creator = (EngineCreate)list.get(0);
00080 mSynthesizer = (Synthesizer)creator.createEngine();
00081 }
00082
00083 if (null == mSynthesizer)
00084 {
00085 Utils.log("ERROR", "Cannot create speech synthesizer");
00086 System.exit(1);
00087 }
00088
00089 mSynthesizer.allocate();
00090
00091
00092 mSynthesizer.getSynthesizerProperties().setVoice(theVoice);
00093
00094 mSynthesizer.resume();
00095
00096
00097
00098
00099 synthesize(" ");
00100 }
00101 catch (Exception e)
00102 {
00103 e.printStackTrace();
00104 }
00105 }
00106
00108 public void destroy()
00109 {
00110 mSynthesizer.cancelAll();
00111
00112 try
00113 {
00114 mSynthesizer.deallocate();
00115 }
00116 catch (Exception e)
00117 {
00118 e.printStackTrace();
00119 }
00120 }
00121
00124 public void synthesize(String message)
00125 {
00126
00127
00128
00129 mSynthesizer.speakPlainText(message, null);
00130 }
00131
00134 public void stopSynthesizing()
00135 {
00136 mSynthesizer.cancelAll();
00137 }
00138 }