8 Replies Latest reply: Nov 12, 2009 2:37 AM by PhHein RSS

    Freetts problem

    843802
      I downloaded the package freetts-1.2.1 and put al the libraries, including the freetts.jar, in the java sdk lib directory.

      I'm trying to compile the FreeTTSHelloWorld.java file tha is in the demo directory of the package.

      The file is this:
      import com.sun.speech.freetts.Voice;
      import com.sun.speech.freetts.VoiceManager;
      import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
      
      public class FreeTTSHelloWorld {
      
          /**
           * Example of how to list all the known voices.
           */
          public static void listAllVoices() {
              System.out.println();
              System.out.println("All voices available:");
              VoiceManager voiceManager = VoiceManager.getInstance();
              Voice[] voices = voiceManager.getVoices();
              for (int i = 0; i < voices.length; i++) {
                  System.out.println("    " + voices.getName()
      + " (" + voices[i].getDomain() + " domain)");
      }
      }

      public static void main(String[] args) {

      listAllVoices();

      String voiceName = (args.length > 0)
      ? args[0]
      : "kevin16";

      System.out.println();
      System.out.println("Using voice: " + voiceName);

      /* The VoiceManager manages all the voices for FreeTTS.
      */
      VoiceManager voiceManager = VoiceManager.getInstance();
      Voice helloVoice = voiceManager.getVoice(voiceName);

      if (helloVoice == null) {
      System.err.println(
      "Cannot find a voice named "
      + voiceName + ". Please specify a different voice.");
      System.exit(1);
      }

      /* Allocates the resources for the voice.
      */
      helloVoice.allocate();

      /* Synthesize speech.
      */
      helloVoice.speak("Thank you for giving me a voice. "
      + "I'm so glad to say hello to this world.");

      /* Clean up and leave.
      */
      helloVoice.deallocate();
      System.exit(0);
      }
      }



      The compiler throws me this result:

      -------------------------------------------------------------------------------
      D:\JavaApps\freetts-1.2.1\demo\freetts\HelloWorld>javac FreeTTSHelloWorld.java
      FreeTTSHelloWorld.java:1: package com.sun.speech.freetts does not exist
      import com.sun.speech.freetts.Voice;
      ^
      FreeTTSHelloWorld.java:2: package com.sun.speech.freetts does not exist
      import com.sun.speech.freetts.VoiceManager;
      ^
      FreeTTSHelloWorld.java:3: package com.sun.speech.freetts.audio does not exist
      import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
      ^
      FreeTTSHelloWorld.java:13: cannot resolve symbol
      symbol : class VoiceManager
      location: class FreeTTSHelloWorld
      VoiceManager voiceManager = VoiceManager.getInstance();
      ^
      FreeTTSHelloWorld.java:13: cannot resolve symbol
      symbol : variable VoiceManager
      location: class FreeTTSHelloWorld
      VoiceManager voiceManager = VoiceManager.getInstance();
      ^
      FreeTTSHelloWorld.java:14: cannot resolve symbol
      symbol : class Voice
      location: class FreeTTSHelloWorld
      Voice[] voices = voiceManager.getVoices();
      ^
      FreeTTSHelloWorld.java:34: cannot resolve symbol
      symbol : class VoiceManager
      location: class FreeTTSHelloWorld
      VoiceManager voiceManager = VoiceManager.getInstance();
      ^
      FreeTTSHelloWorld.java:34: cannot resolve symbol
      symbol : variable VoiceManager
      location: class FreeTTSHelloWorld
      VoiceManager voiceManager = VoiceManager.getInstance();
      ^
      FreeTTSHelloWorld.java:35: cannot resolve symbol
      symbol : class Voice
      location: class FreeTTSHelloWorld
      Voice helloVoice = voiceManager.getVoice(voiceName);
      ^
      9 errors

      D:\JavaApps\freetts-1.2.1\demo\freetts\HelloWorld>

      --------------------------------------------------------------------------------------
      I don't really know what's wrong or what else I have to do to install the freetts package.

      Can anybody give me a hand, please?
        • 1. Re: Freetts problem
          843802
          The short version is that you don't have the libraries in your classpath when you compile. But once you run the test in your own environment, you also need to make sure the following property is set:

          -Dfreetts.voices=com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory

          The long version: You may have already resolved this issue, but just in case and for the sake of closure, here are some pointers.

          First, the freetts libraries make copious and unruly use of classpaths built into the Manifest.mf files of the libraries. They all have relative paths hardcoded in them (!) which require their dependencies to all be located in specific locations.

          So it sounds like two things went wrong in your environment. First, the libraries don't go in your jdk install, they go along with you application. Next, they must go in the same directory - it is not enough for them to all be on the classpath (breaks maven unit testing for example). Finally, you need to have the speech.properties file in your home directory or in your jdk install's lib. Otherwise you must set a system property according to the javadocs: freetts.sourceforge.net/javadoc/com/sun/speech/freetts/VoiceManager.html

          I've testing this by setting it via System.setProperty with success.

          For anyone reading this and using maven, I strongly suggest using the dependency:unpack-dependencies goal (or unpack in your ant script as well) if you intend to deploy in a "normal" application (jar, war, ejb, etc): Here is what I am using.

          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
          <execution>
          <id>unpack</id>
          <phase>compile</phase>
          <goals>
          <goal>unpack-dependencies</goal>
          </goals>
          <configuration>
          <outputDirectory>${project.build.directory}/classes</outputDirectory>
          <includeScope>runtime</includeScope>
          </configuration>
          </execution>
          </executions>
          </plugin>

          I spent a weekend trying to get this library to behave. Outside of the demo files, it does not reliably "just go". It takes some serious tweaking. I chose to unpack and consolidate the class files into my jar file to work around the built in classpath dependencies (even stripping the classpath directives out of the manifests didn't take).
          • 2. Re: Freetts problem
            843802
            Thanks Kris.Bravo for your help.
            • 3. Re: Freetts problem
              843802
              Hi
              I am also having problems using FreeTTS. I am trying to run a phonebook example.Here is the code:
              //PhoneBook.ja
              // An application announces phone number with FreeTTS.
              import java.awt.*;
              import java.awt.event.*;
              import java.util.*;
              import javax.swing.*;
              import javax.speech.*;
              import javax.speech.synthesis.*;

              public class PhoneBook extends JFrame
              {
              // JLabels to display instructions
              private JLabel instruction1JLabel;
              private JLabel instruction2JLabel;

              // JComboBox for names
              private JComboBox nameJComboBox;

              // JButton to get phone number
              private JButton getPhoneNumberJButton;

              // Synthesizer to speak phone number
              private Synthesizer speechSynthesizer;

              // fill array with people's names
              private String[] namesArray = { "John", "Jennifer", "Howard" };

              // fill array with people's phone numbers
              private String[] numbersArray =
              { "(555) 555-9876", "(555) 555-1234", "(555) 555-4567" };

              // no-argument constructor
              public PhoneBook()
              {
              // initialize Synthesizer
              try
              {
              // create SynthesizerModeDesc for FreeTTS synthesizer.
              SynthesizerModeDesc descriptor = new SynthesizerModeDesc(
              "Unlimited domain FreeTTS Speech Synthesizer " +
              "from Sun Labs", null, Locale.US, Boolean.FALSE, null );

              // create a Synthesizer
              speechSynthesizer = Central.createSynthesizer( descriptor );

              // Synthesizer created successfully
              if ( speechSynthesizer != null )
              {
              // prepare synthesizer to speak
              speechSynthesizer.allocate();
              speechSynthesizer.resume();
                   
              // get synthesizer properties
              SynthesizerProperties properties =
              speechSynthesizer.getSynthesizerProperties();

              // set up speaking rate
              properties.setSpeakingRate( 100.0f );
                   
              } // end if
                   
              else
              {
              System.err.println( "Synthesizer creation failed." );
                   System.exit( 1 );
              }

              } // end try

              catch ( Exception myException )
              {
              myException.printStackTrace();
              }

              createUserInterface(); // set up GUI

              } // end constructor

              // create and position GUI components; register event handler
              private void createUserInterface()
              {
              // get content pane for attaching GUI components
              Container contentPane = getContentPane();

              // enable explicit positioning of GUI components
              contentPane.setLayout( null );

              // set up instruction1JLabel
              instruction1JLabel = new JLabel();
              instruction1JLabel.setBounds( 16, 8, 264, 23 );
              instruction1JLabel.setText(
              "Select a name from the combo box." );
              contentPane.add( instruction1JLabel );

              // set up instruction2JLabel
              instruction2JLabel = new JLabel();
              instruction2JLabel.setBounds( 16, 35, 264, 23 );
              instruction2JLabel.setText(
              "Click the button to listen to the phone number." );
              contentPane.add( instruction2JLabel );

              // set up nameJComboBox
              nameJComboBox = new JComboBox( namesArray );
              nameJComboBox.setBounds( 50, 65, 150, 23 );
              contentPane.add( nameJComboBox );

              // set up getPhoneNumberJButton
              getPhoneNumberJButton = new JButton();
              getPhoneNumberJButton.setBounds( 50, 100, 150, 23 );
              getPhoneNumberJButton.setText( "Get Phone Number" );
              contentPane.add( getPhoneNumberJButton );
              getPhoneNumberJButton.addActionListener(

              new ActionListener() // anonymous inner class
              {
              // event handler called when getPhoneNumberJButton
              // is clicked
              public void actionPerformed( ActionEvent event )
              {
              getPhoneNumberJButtonActionPerformed( event );
              }

              } // end anonymous inner class

              ); // end call to addActionListener

              // set properties of application's window
              setTitle( "Phone Book" ); // set title bar string
              setSize( 300, 160 ); // set window size
              setVisible( true ); // display window

              // ensure synthesizer is cleaned up
              // when user closes application
              addWindowListener(

              new WindowAdapter() // anonymous inner class
              {
              public void windowClosing( WindowEvent event )
              {
              frameWindowClosing( event );
              }

              } // end anonymous inner class

              ); // end addWindowListener

              } // end method createUserInterface

              // speak a person's phone number
              private void getPhoneNumberJButtonActionPerformed(
              ActionEvent event )
              {
              // get index of the selected person
              int selectedName = nameJComboBox.getSelectedIndex();

              // declare text to speak
              String textToSpeak = namesArray[ selectedName ] +
              "'s phone number is " + numbersArray[ selectedName ];

                        //String textToSpeak = "This is sample text";
              // speak the person's name and phone number
              speechSynthesizer.speakPlainText( textToSpeak, null );

              } // end method getPhoneNumberJButtonActionPerformed

              // clean up synthesizer
              private void frameWindowClosing( WindowEvent event )
              {
              // deallocate synthesizer
              try
              {
              speechSynthesizer.deallocate();
              }
              catch ( Exception myException )
              {
              myException.printStackTrace();
              }
              finally
              {
              System.exit( 0 );
              }

              } // end method frameWindowClosing

              // main method
              public static void main( String[] args )
              {
              PhoneBook application = new PhoneBook();

              } // end method main

              } // end class PhoneBook

              I have a chapter on how to install FreeTTS exactly and how to run the example but i keep getting these errors:

              --------------------Configuration: <Default>--------------------
              C:\PhoneBook\PhoneBook\PhoneBook.java:7: package javax.speech does not exist
              import javax.speech.*;
              ^
              C:\PhoneBook\PhoneBook\PhoneBook.java:8: package javax.speech.synthesis does not exist
              import javax.speech.synthesis.*;
              ^
              C:\PhoneBook\PhoneBook\PhoneBook.java:23: cannot find symbol
              symbol : class Synthesizer
              location: class PhoneBook
              private Synthesizer speechSynthesizer;
              ^
              C:\PhoneBook\PhoneBook\PhoneBook.java:39: cannot find symbol
              symbol : class SynthesizerModeDesc
              location: class PhoneBook
              SynthesizerModeDesc descriptor = new SynthesizerModeDesc(
              ^
              C:\PhoneBook\PhoneBook\PhoneBook.java:39: cannot find symbol
              symbol : class SynthesizerModeDesc
              location: class PhoneBook
              SynthesizerModeDesc descriptor = new SynthesizerModeDesc(
              ^
              C:\PhoneBook\PhoneBook\PhoneBook.java:44: cannot find symbol
              symbol : variable Central
              location: class PhoneBook
              speechSynthesizer = Central.createSynthesizer( descriptor );
              ^
              C:\PhoneBook\PhoneBook\PhoneBook.java:54: cannot find symbol
              symbol : class SynthesizerProperties
              location: class PhoneBook
              SynthesizerProperties properties =
              ^
              7 errors

              any ideas what I might be doing wrong?I am developing an email voice application for visually impaired people for my FYP so if i could get this example working it would help me to develop my project,i hope!!
              • 4. Re: Freetts problem
                843802
                Hello...
                Im also facing the exact problem as faced by rocket...

                I'm able to generate voice files (.wav) using the freetts engine and its working just fine but when i try to compile
                the demo FreeTTSHelloWorld. it gives the same errors as faced by rocket
                I used this code in a batch file to set my CLASSPATH:
                @ECHO off
                
                set JAVA_HOME=E:\Software\JDK 1.5
                set SPEECH_SYNTHESIS_HOME=E:\JAVA SPEECH RECOGNITION\Frree TTS 1.2.1\freetts-1.2.1
                
                IF "%JAVA_HOME%"=="" GOTO java_home_missing
                IF "%SPEECH_SYNTHESIS_HOME%"=="" GOTO speech_synthesis_home_missing
                
                set PATH=%JAVA_HOME%\bin;.;%PATH%
                set CLASSPATH=%JAVA_HOME%\lib\dt.jar;.;%CLASSPATH%
                set CLASSPATH=%SPEECH_SYNTHESIS_HOME%\lib\jsapi.jar;%CLASSPATH%
                set CLASSPATH=%SPEECH_SYNTHESIS_HOME%\lib\freetts.jar;%CLASSPATH%
                set CLASSPATH=%SPEECH_SYNTHESIS_HOME%\lib\cmuawb.jar;%CLASSPATH%
                set CLASSPATH=%SPEECH_SYNTHESIS_HOME%\lib\cmukal16.jar;%CLASSPATH%
                set CLASSPATH=%SPEECH_SYNTHESIS_HOME%\lib\cmukal8.jar;%CLASSPATH%
                set CLASSPATH=%SPEECH_SYNTHESIS_HOME%\lib\cmulex.jar;%CLASSPATH%
                set CLASSPATH=%SPEECH_SYNTHESIS_HOME%\lib\cmutimelex.jar;%CLASSPATH%
                
                GOTO end
                
                :java_home_missing
                ECHO Error: JAVA_HOME environment variable is not defined.
                
                :speech_synthesis_home_missing
                ECHO Error: SPEECH_SYNTHESIS_HOME environment variable is not defined.
                
                :end
                @ECHO on
                please help me out...
                • 5. Re: Freetts problem
                  843802
                  import java.util.Locale;
                  import javax.speech.*;
                  import javax.speech.synthesis.*;


                  public class Text2Speech
                  {
                  private static Synthesizer synth;

                  public static void main(String[] args)
                  {
                  try
                  {
                  synth = Central.createSynthesizer(new SynthesizerModeDesc(null,"general",Locale.ENGLISH,null,null));
                  synth.allocate();
                  synth.resume();
                  synth.speakPlainText("Hello World!", null);
                  synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
                  synth.deallocate();
                  }
                  catch (Exception e) { e.printStackTrace(); }
                  }
                  }

                  I have saved Text2Speech.java file in freetts-1_1_1.2.1-bin\freetts-1.2.1\lib
                  i have placed speech.properties file in home dir
                  nd compiled using dis
                  C:\> javac -classpath .\;C:\freetts-1_1_1.2.1-bin\freetts-1.2.1\lib\jsapi.jar Text2Speech.java

                  m gettin error
                  cannot read: Text2Speech.java
                  1 error
                  • 6. Re: Freetts problem
                    843802
                    I just wanted to share my general story about setting up freetts with maven so others might benefit.
                    I had similar problems setting everything up with all those path issues - especially since I was doing it through maven.
                    One thing to note, this was for setting up Sound Captcha for jcaptcha so my solution includes another dependency on "jcaptcha-extension-sound-freetts" and I can't get it to work without this jar (see below for pom dependencies).

                    To get this working I first got a copy of the FreeTTSHelloWorld source and played around with it in my webapp until I finally got it to run.
                    The only thing I had to do to the copied source code was add the freetts.voices at the beginning:
                        
                    public static void main(String[] args) { 
                             System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory"); 
                    Other than that, I turned to the demos and found that the demo depends on cmu_us_kal.jar and cmulex.jar so I installed those in my local repo:
                    mvn install:install-file -DgroupId=captcha-sound -DartifactId=kevin-voice -Dversion=1.0 -Dpackaging=jar -Dfile=cmu_us_kal.jar
                    mvn install:install-file -DgroupId=captcha-sound -DartifactId=lexicon -Dversion=1.0 -Dpackaging=jar -Dfile=cmulex.jar 
                    Then finally added the following dependencies to my pom.xml:
                              <!-- Audio Captcha -->
                              <dependency>
                                   <groupId>captcha-sound</groupId>                    
                                   <artifactId>kevin-voice</artifactId>
                                   <version>1.0</version>
                              </dependency>     
                                   
                              <dependency>
                                   <groupId>captcha-sound</groupId>                    
                                   <artifactId>lexicon</artifactId>
                                   <version>1.0</version>
                              </dependency>               
                    
                              <dependency>
                                   <groupId>com.octo.captcha</groupId>                    
                                   <artifactId>voice-en</artifactId>
                                   <version>1.0.0</version>
                              </dependency>     
                                   
                              <dependency>
                                      <groupId>com.octo.captcha</groupId>
                                           <artifactId>jcaptcha-extension-sound-freetts</artifactId>
                                      <version>1.0-SNAPSHOT</version>
                                     </dependency>
                    and Voila! It finally ran.
                    • 7. Re: Freetts problem
                      843802
                      Hi, everyone!

                      I'm building an Maven project ...I've added some entries such these:

                      <dependency>
                                     <groupId>com.sun.speech.freetts.en.us</groupId>
                                     <artifactId>cmulex</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>com.sun.speech.freetts.en.us</groupId>
                                     <artifactId>cmutimelex</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>com.sun.speech.freetts.en.us</groupId>
                                     <artifactId>cmu_dict_04</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>com.sun.speech.freetts.en.us</groupId>
                                     <artifactId>cmu_time_awb</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>com.sun.speech.freetts.en.us</groupId>
                                     <artifactId>cmu_us_kal</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>com.sun.speech.freetts</groupId>
                                     <artifactId>freetts</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>com.sun.speech.freetts</groupId>
                                     <artifactId>freetts-jsapi</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>de.dfki.lt</groupId>
                                     <artifactId>mbola_freetts</artifactId>
                                     <version>1.0.1</version>
                                     </dependency>
                                     <dependency>
                                     <groupId>captcha-sound</groupId>                    
                                     <artifactId>kevin-voice</artifactId>
                                     <version>1.0</version>
                                </dependency>     
                                <dependency>
                                     <groupId>captcha-sound</groupId>                    
                                     <artifactId>lexicon</artifactId>
                                     <version>1.0</version>
                                </dependency>


                      but it appears this issue:

                      java.lang.Error: Unable to load voice directory. java.lang.ClassNotFoundException: com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory


                      Into my code:

                      String voiceName = "kevin16";
                           VoiceManager voiceManager = VoiceManager.getInstance();
                           Voice helloVoice = voiceManager.getVoice(voiceName);
                           System.setProperty("com.sun.speech.freetts.voice.defaultAudioPlayer", "com.sun.speech.freetts.audio.SingleFileAudioPlayer");
                           System.setProperty("freetts.voices", "KevinVoiceDirectory");

                      ....

                      helloVoice.allocate();
                           /* Synthesize speech.
                      */
                           String texto = "hello world";
                           byte b[] = texto.getBytes();
                           helloVoice.speak(texto);
                           
                      System.out.println("despues del speak");


                      I think it can be generated by CMULexicon (i've inspectioned the KevinVoiceDirectory class and Eclipse show the line where the CMULexicon object is created)

                      How can I add the CMULexicon reference into my pom.xml file?

                      Thanks in advanced!
                      • 8. Re: Freetts problem
                        PhHein
                        Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.

                        I'm locking this thread now.