用FreeTTS兑现Java语音程序怎么解决
发布网友
发布时间:2022-04-22 01:33
我来回答
共1个回答
热心网友
时间:2023-11-05 17:23
用FreeTTS实现Java语音程序
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();
}
}
}