简体   繁体   English

FreeTTS Java程序中的ClassNotFoundException

[英]ClassNotFoundException in FreeTTS Java program

I am new to FreeTTS and this is my first program.The following program simply reads out a string passed. 我是FreeTTS的新手,这是我的第一个程序。以下程序只是读取传递的字符串。

I am using Linux Mint 32-bit if that matters.But I extracted jsapi.jar on my windows machine a day back.I believe it doesn't matter. 如果这很重要,我正在使用32位Linux Mint,但是jsapi.jar一天我在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");
    }
}

I am getting this as a gift. 我得到这个作为礼物。

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

What can I do not to accept this gift. 我不能接受什么礼物?

PS PS

I have added all the 4 archives viz en_us.jar , freetts-jsapi10.jar , jsapi.jar , mbrola.jar 我已经添加了所有4个档案,即en_us.jarfreetts-jsapi10.jarjsapi.jarmbrola.jar

1) Find in which jar this class is usually defined: 1)查找此类通常在哪个jar中定义:
com.sun.speech.freetts.ValidationException com.sun.speech.freetts.ValidationException

2) See if you have the jar 2)看你是否有罐子

3) See if you have the right version of this jar 3)看看您是否拥有此罐子的正确版本
(open it, see if the class file is there) (打开它,看看是否有类文件)

4) See if the jar is in the classpath at runtime 4)在运行时查看jar是否在类路径中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM