ClassNotFoundException in FreeTTS Java program

2.2k views Asked by At

I am new to FreeTTS and this is my first program.The following program simply reads out a string passed.

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.

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

I have added all the 4 archives viz en_us.jar,freetts-jsapi10.jar, jsapi.jar,mbrola.jar

1

There are 1 answers

4
peter.petrov On

1) Find in which jar this class is usually defined:
com.sun.speech.freetts.ValidationException

2) See if you have the jar

3) See if you have the right version of this jar
(open it, see if the class file is there)

4) See if the jar is in the classpath at runtime