我是FreeTTS的新手,这是我的第一个程序。以下程序只是读出一个字符串传递。
如果重要的话,我正在使用Linux Mint 32位。但是我在一天前在我的Windows机器上提取jsapi.jar
。我相信这没关系。
import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;
public class Speak
{
String speaktext;
public void dospeak(String speak,String voicename)
{
speaktext=speak;
String voiceName =voicename;
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++)
{
if (voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
System.out.print("Speaking : "+speaktext);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch (Exception e)
{
String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
System.out.println(""+e);
System.out.println(message);
}
}
public static void main(String[] args)
{
Speak obj=new Speak();
obj.dospeak("Finally It speaks and speaks and speaks","kevin16");
}
}
我将此作为礼物。
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/ValidationException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at javax.speech.Central.registerEngineCentral(Central.java:703)
at javax.speech.Central.loadProps(Central.java:775)
at javax.speech.Central.availableSynthesizers(Central.java:651)
at javax.speech.Central.createSynthesizer(Central.java:553)
at Speak.dospeak(Speak.java:16)
at Speak.main(Speak.java:47)
Caused by: java.lang.ClassNotFoundException: com.sun.speech.freetts.ValidationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
我不能接受这份礼物。
PS
我添加了所有4个档案en_us.jar
,freetts-jsapi10.jar
,jsapi.jar
,mbrola.jar
答案 0 :(得分:1)
1)找出通常定义这个类的jar:
com.sun.speech.freetts.ValidationException
2)看看你是否有罐子
3)看看你是否有正确版本的这个罐子 (打开它,看看是否有类文件)
4)查看jar是否在运行时位于类路径中