1

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

Naveen
  • 7,944
  • 12
  • 78
  • 165

1 Answers1

1

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

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
  • :I have solved that problem by adding `freetts.jar` but now I am getting another problem -`System property "mbrola.base" is undefined. Will not use MBROLA voices. java.lang.NullPointerException`. – Naveen Dec 12 '13 at 09:13
  • Well, it says this property is not defined. You have to define it, I guess. Hard to troubleshoot further as I am not on your machine. – peter.petrov Dec 12 '13 at 09:17
  • Same question at `http://stackoverflow.com/questions/3975906/troubleshooting-system-property-mbrola-base-is-undefined-will-not-use-mbrola` but no one has answered for 3 years – Naveen Dec 12 '13 at 09:24
  • Hm, well then I would try to post a question on the respective technology's forum and even check the source code. Who knows might be bug or something. – peter.petrov Dec 12 '13 at 09:26