1. Download FreeTTS: http://freetts.sourceforge.net/
2. 解壓後運行:D:\software\freetts-1.2\lib\jsapi.exe, 選擇agree.
3. 寫helloworld程序,語音讀出"MPLS alarm: link down":

import java.util.Locale;

import javax.speech.Central;
import javax.speech.EngineList;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.Voice;

public class HelloWorld {

    public HelloWorld() {
    }

    public static void main(String args[]) {
        try {
            SynthesizerModeDesc desc = new SynthesizerModeDesc("FreeTTS en_US general synthesizer", "general",
                    Locale.US, null, null);
            Synthesizer synthesizer = Central.createSynthesizer(desc);
            if (synthesizer == null) {
                System.exit(1);
            }
            synthesizer.allocate();
            synthesizer.resume();
            desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
            Voice voices[] = desc.getVoices();
            if(voices != null && voices.length > 0){
                synthesizer.getSynthesizerProperties().setVoice(voices[0]);
                synthesizer.speakPlainText("MPLS alarm: link down", null);
                synthesizer.waitEngineState(0x10000L);
            }
            synthesizer.deallocate();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()