Results 1 to 14 of 14
Thread: Java TTS
- 07-15-2010, 02:37 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 6
- Rep Power
- 0
Java TTS
Hello, I have recently been playing with FreeTTS and JSAPI to try and get my little HelloWorld program to speak. I have spent a decent amount of time on Google trying whatever solutions I could find, but I think I must be overlooking something simple. The program I am trying to build out of a simple text editor looks like this...
I have copied the speech.properties file to both the java.home and user.home locations and the program compiles just fine with the jsapi.jar and freetts.jar included with the -cp. However, I think it is not finding the javax.speech.Central because I get this error every time I try to run the program...Java Code:import javax.speech.*; import javax.speech.synthesis.*; import javax.speech.Central.*; //import java.util.Locale; class HelloWorld { public static void main(String args[]) { System.out.println("Hello World"); try { Synthesizer synth = Central.createSynthesizer(null); synth.allocate(); synth.resume(); synth.speakPlainText("Hello World", null); synth.waitEngineState(Synthesizer.QUEUE_EMPTY); synth.deallocate(); } catch(Exception e) { //System.out.println("Failure"); e.printStackTrace(); } } }
I thought that the javax.speech.Central class would be included when I compile with the jsapi.jar in the classpath...Exception in thread "main" java.lang.NoClassDefFoundError: javax/speech/Central
at HelloWorld.main(HelloWorld.java:17)
Caused by: java.lang.ClassNotFoundException: javax.speech.Central
at java.net.URLClassLoader$1.run(URLClassLoader.java: 217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 21)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:334)
Does anyone have any ideas of what is causing this error?
Thanks
- 07-15-2010, 03:25 AM #2
If the class was found in the jar when you compiled the program, the class should be in the jar file when you execute it the class.
How did you put the jar file on the classpath for the java.exe command?
- 07-15-2010, 04:14 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 6
- Rep Power
- 0
ok, so I have tried to run the program in two ways...
1: without the cp switch (it prints "Hello World", then fails)
2: with the cp switch (it seems like it can't find the main)Java Code:~$ java HelloWorld Hello World Exception in thread "main" java.lang.NoClassDefFoundError: javax/speech/Central at HelloWorld.main(HelloWorld.java:17) Caused by: java.lang.ClassNotFoundException: javax.speech.Central at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334) ... 1 more
this is the line I used to compileJava Code:~$ java -cp jsapi.jar:freetts.jar HelloWorld Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld Caused by: java.lang.ClassNotFoundException: HelloWorld at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334) Could not find the main class: HelloWorld. Program will exit.
~$ javac -cp jsapi.jar:freetts.jar HelloWorld.java
- 07-15-2010, 04:16 AM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
if you have included a java file outside standard java files you will need to write your own manifest file?
- 07-15-2010, 06:54 AM #5
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Don't think the OP is creating a jar file, al. He's USING them, but I don't think that he's creating them.
This import statement looks odd: import javax.speech.Central.*;
shouldn't it be this? import javax.speech.Central;
Not sure it would solve your problem, but you never know :)If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 07-15-2010, 08:29 AM #6
Member
- Join Date
- Jul 2010
- Posts
- 6
- Rep Power
- 0
HelloWorld TTS hangs
ok, I made a couple changes...
I included all the jar files that come with the FreeTTS
I made a manifest file which looks like this
I included these jar files when I compiledJava Code:Manifest-Version: 1.2 Main-Class: HelloWorld Class-Path: jsapi.jar freetts.jar cmudict04.jar cmulex.jar cmu_time_awb.jar cmutimelex.jar en_us.jar freetts-jsapi10.jar cmu_us_kal.jar Created-By: 1.4 (Sun Microsystems Inc.)
In order to use the Manifest file I created a jar file with this linejavac -cp cmudict04.jar:cmulex.jar:cmu_time_awb.jar:cmutimel ex.jar:cmu_us_kal.jar:en_us.jar:freetts.jar:freett s-jsapi10.jar:jsapi.jar HelloWorld.java
I tried to execute the code using this commandjar cmf MANIFEST.MF HelloWorld.jar HelloWorld.class cmudict04.jar cmulex.jar cmu_time_awb.jar cmutimelex.jar cmu_us_kal.jar en_us.jar freetts.jar freetts-jsapi10.jar jsapi.jar
I don't get any errors this time, but the program simply hangs. I give it a few minutes, but there is no audio and I have to use Ctrl-C to stop the program.java -Dmbrola.base=mbrola -jar HelloWorld.jar
specs on the machine I am currently using for this:
HP Pavilion dv5223om laptop
1.8GHz AMD Turion
1GB RAM
...its a few years old, but it should be able to run this without too much trouble.
I also used both
import javax.speech.Central.*but I didn't notice and differenceimport javax.speech.Central
Any ideas why this would hang or what needs to be changed?
Thanks,Last edited by cuschu; 07-15-2010 at 08:32 AM.
- 07-15-2010, 09:22 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
There was another thread running in the 'Advanced Java' section of this forum a little while ago; I managed to get FreeTTS running with its own iterface (not the JSAPI). I didn't manage to get those mbrola voices running. Maybe that thread helps, here's the link.
kind regards,
JosLast edited by JosAH; 07-15-2010 at 09:26 AM.
- 07-15-2010, 01:27 PM #8
One observation. The current directory(.) is not set in the classpath. Try:
java -cp jsapi.jar:freetts.jar:. HelloWorld
- 07-16-2010, 04:15 AM #9
Member
- Join Date
- Jul 2010
- Posts
- 6
- Rep Power
- 0
By adding the current directory, like this...
It clears up the error finding the main class and has the same result as when I made the manifest file and HelloWorld.jar.java -cp jsapi.jar:freetts.jar:cmudict04.jar:cmulex.jar:cmu _time_awb.jar:cmutimelex.jar:cmu_us_kal.jar:en_us. jar:freetts-jsapi10.jar:. HelloWorld
However, the program still hangs for some reason. I am not getting any errors and it prints "Hello World" to the screen, but then all I get is a blinking cursor.
Any ideas what would cause this?
- 07-16-2010, 06:57 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 07-17-2010, 03:11 AM #11
Member
- Join Date
- Jul 2010
- Posts
- 6
- Rep Power
- 0
Hey Jos,
I read through the forums you linked to. Also, I copied the little program you wrote to a HelloWorld2.java and used the following lines...
javac -cp freetts.jar:cmudict04.jar:cmulex.jar:cmu_time_awb. jar:cmu_us_kal.jar:en_us.jar:. HelloWorld2.javaI omitted the jsapi jars because from the forum you linked to it seemed that they were unnecessary. (I also tried running the program including them in the classpath and did not see any difference)java -cp freetts.jar:cmudict04.jar:cmulex.jar:cmu_time_awb. jar:cmu_us_kal.jar:en_us.jar:. HelloWorld2
However, I have the same problem, which is that when I run the program I don't get any audio...all I end up seeing is a blinking cursor.
This machine is running Ubuntu 10.04 and I know that the sound drivers work. Is there anything else you can see that I am doing incorrectly?:confused:
I also added this line to my previously posted code to check if the synth object was null, but when I run the program it didn't say "synth is null"
Another thing I just tried to troubleshoot where this program is hanging up is adding aif(synth == null){
System.err.println("synth is null");
}after each line. It will makes it up to, but not pastSystem.out.println("Made it this far");...Interestingly if I try doing that in the program Jos provided in a link I end up hanging atsynth.allocate();voice.speak("Oh man this is a crappy voice");Last edited by cuschu; 07-17-2010 at 03:44 AM.
- 07-17-2010, 07:29 AM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 07-17-2010, 10:54 AM #13
Member
- Join Date
- Jul 2010
- Posts
- 6
- Rep Power
- 0
I really appreciate your help on this...
I triedand I got exactly the same result as when I try to run the little Hello World programs. It did prompt me for the text, but the all I end up with is a blinking cursor and no voice.java -jar freetts.jar -streaming
Thinking this could be related to a bad version of the freetts.jar or it was missing something, I followed these instructions to install freetts.
FreeTTS-1.2.1
Unfortunately, that didn't help much...when I run the freetts.jar that was created from those instructions I get the same results as before.
- 07-17-2010, 11:40 AM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Hrmph, that freetts stuff gave me problems too; reread my other reply in that other thread topic: I dumped all those .jar files in the JRE/lib/ext directory and used my little test program; that worked for me on an MS Windows machine ... (I still don't have those mbrola voices up and running though). The freetts test program works for me using those settings ...
kind regards,
Jos


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks