Results 1 to 14 of 14

Thread: Java TTS

  1. #1
    cuschu is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default 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...

    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 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...

    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)
    I thought that the javax.speech.Central class would be included when I compile with the jsapi.jar in the classpath...
    Does anyone have any ideas of what is causing this error?

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    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?

  3. #3
    cuschu is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    ok, so I have tried to run the program in two ways...

    1: without the cp switch (it prints "Hello World", then fails)
    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
    2: with the cp switch (it seems like it can't find the main)
    Java 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.
    this is the line I used to compile
    ~$ javac -cp jsapi.jar:freetts.jar HelloWorld.java

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    if you have included a java file outside standard java files you will need to write your own manifest file?

  5. #5
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    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!

  6. #6
    cuschu is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default 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
    Java 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.)
    I included these jar files when I compiled
    javac -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
    In order to use the Manifest file I created a jar file with this line
    jar 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 tried to execute the code using this command
    java -Dmbrola.base=mbrola -jar HelloWorld.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.

    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.*
    import javax.speech.Central
    but I didn't notice and difference

    Any ideas why this would hang or what needs to be changed?

    Thanks,
    Last edited by cuschu; 07-15-2010 at 08:32 AM.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    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,

    Jos
    Last edited by JosAH; 07-15-2010 at 09:26 AM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    One observation. The current directory(.) is not set in the classpath. Try:
    java -cp jsapi.jar:freetts.jar:. HelloWorld

  9. #9
    cuschu is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    By adding the current directory, like this...
    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
    It clears up the error finding the main class and has the same result as when I made the manifest file and HelloWorld.jar.

    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?

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by cuschu View Post
    Any ideas what would cause this?
    Have you read my reply #7 and read the linked thread I supplied?

    kind regards,

    Jos

  11. #11
    cuschu is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    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.java
    java -cp freetts.jar:cmudict04.jar:cmulex.jar:cmu_time_awb. jar:cmu_us_kal.jar:en_us.jar:. HelloWorld2
    I 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)

    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"
    if(synth == null){
    System.err.println("synth is null");
    }
    Another thing I just tried to troubleshoot where this program is hanging up is adding a
    System.out.println("Made it this far");
    after each line. It will makes it up to, but not past
    synth.allocate();
    ...Interestingly if I try doing that in the program Jos provided in a link I end up hanging at
    voice.speak("Oh man this is a crappy voice");
    Last edited by cuschu; 07-17-2010 at 03:44 AM.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by cuschu View Post
    ...Interestingly if I try doing that in the program Jos provided in a link I end up hanging at
    Can you try the following?

    Java Code:
    java -jar freetts.jar -streaming
    You are prompted to type a bit of text. Can you hear that crappy voice?

    kind regards,

    Jos

  13. #13
    cuschu is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    I really appreciate your help on this...

    I tried
    java -jar freetts.jar -streaming
    and 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.

    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.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by cuschu View Post
    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.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •