用FreeTTS兑现Java语音程序怎么解决
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用FreeTTS兑现Java语音程序怎么解决相关的知识,希望对你有一定的参考价值。
参考技术A 用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();
怎么用java语音编写把一个四位数倒置过来输出
public static void main(String[] args)// TODO Auto-generated method stub
int num = 1234;
String str = num + "";// 将数字转换成字符串
char[] chs = str.toCharArray();// 将字符串转成字符数组
String result = "";// 新的string用来接收倒置的数字
//从数组的最后一个字符开始到第一个,依次拼到string中
for (int i = chs.length - 1; i >= 0; i--)
result = result + chs[i];
int num2 = Integer.parseInt(result);// 还原成int类型
System.out.println(num2);
任意位数的int型数字,或者任意长度的字符串都可以。只是int型数字需要先转成String。
* 反转一个int值
* @param number_4_bit 待反转数据
* @return
*/
public static String reversal (int number_4_bit)
String rs = "";
String tp = number_4_bit + "";
for(int i = tp.length() - 1 ; i >= 0;i--)
rs += tp.charAt(i);
return rs;
参考技术B public class Main
public static void main(String[] args)
int shu = 1234;
int result = 0;
for (int i = 1000; i > 0; i /= 10)
result += shu % 10 * i;
shu /= 10;
System.out.println(result);
以上是关于用FreeTTS兑现Java语音程序怎么解决的主要内容,如果未能解决你的问题,请参考以下文章