11 Replies Latest reply: Apr 13, 2007 3:28 AM by 843802 RSS

    this is an example of java speech synthesizer.. which is givin runtime err

    843802
      hi..
      this code i have taken from one of the site.. but its not workin.. this code also throwing the java.lang.nullpointer exception... i have load the speech api properly..
      please help me..
      import javax.speech.synthesis.*;
      import java.util.Locale;

      public class HelloWorld {
           public static void main(String args[]) {
                try {
                     // Create a synthesizer for English
                     Synthesizer synth = Central.createSynthesizer(
                          new SynthesizerModeDesc(Locale.ENGLISH));

                     // Get it ready to speak
                     synth.allocate();
                     synth.resume();

                     // Speak the "Hello world" string
                     synth.speakPlainText("Hello, world!", null);

                     // Wait till speaking is done
                     synth.waitEngineState(Synthesizer.QUEUE_EMPTY);

                     // Clean up
                     synth.deallocate();
                } catch (Exception e) {
                     e.printStackTrace();
                }
           }
      }
        • 1. Re: this is an example of java speech synthesizer.. which is givin runtime
          843802
          I don`t know which implementation you are using but generally you have to
                     synth.waitEngineState(Synthesizer.ALLOCATED);
          after a call to
            synth.allocate();
            synth.resume();
          regards
          • 2. Re: this is an example of java speech synthesizer.. which is givin runtime
            843802
            thanks for your reply..
            i add tht line on tht code too.. but its still throwin runtime exception jaba.lang.NullPointer exception...

            synth.allocate();

            it might be because of the Synthesizer object cannot be initialized properly..

            Synthesizer synth = Central.createSynthesizer(
                           new SynthesizerModeDesc(Locale.getDefault()));

            pls help me in this topic..
            • 3. Re: this is an example of java speech synthesizer.. which is givin runtime
              843802
              Which implemenation of the jsapi are you using?

              regards
              • 4. Re: this is an example of java speech synthesizer.. which is givin runtime
                843802
                hi there
                i am facing same error, null pointer exception, i was wandering if you manage to solve this issue. if so please let me know how did u manage to solve this error i have spent almost a week now but i am not able to fix it. i am looking forward to hear from you soon
                • 5. Re: this is an example of java speech synthesizer.. which is givin runtime err
                  843802
                  hello
                  i am also working on such project , and facing same problem .
                  as well as i think synthesizer is not initialized , when u call createSynthesizer() .

                  there is another case where u search for the existing engines and create one of the selected Engine from the list.

                  "JAVA 2 Unleashed " has dedicated chapter for speech api working and FAQs.

                  if U got any concerned material then let me know

                  thanks
                  • 6. Re: this is an example of java speech synthesizer.. which is givin runtime
                    843802
                    Hi
                    I am facing the same problem and have tried to fix it with all solutions are available here.
                    plz tell me which version of java is compatible to fix it?
                    • 7. Re: this is an example of java speech synthesizer.. which is givin runtime
                      843802
                      I have installed "j2sdk-1_4_2_17-windows-i586-p" and "j2re-1_4_2_17-windows-i586-p" and "TalkingjavaSDK-163"
                      If their should be any other instead of these plz let me know about that
                      waiting for you reply ASAp
                      Fakhra
                      • 8. Re: this is an example of java speech synthesizer.. which is givin runtime
                        843802
                        hey i used the "talkingjavasdk1.6.3 but the problem is that it doesnt allow me to change the pitch speed and the volume..can you help me with that? and other option for it is the FreeTTS you can get it from sourceforge.net but it throws the null pointer exception
                        • 9. Re: this is an example of java speech synthesizer.. which is givin runtime
                          843802
                          I had got same pbm in my java speech application in eclipse on Linux. I used freeTTS implementation for developing speech application. My code was throwing this error after run application..........
                          java.nullpointerException......
                          Synthesizer.allocate();

                          First, i put only jsapi.jar and freeTTS.jar files in jre/lib/ext folder and speech.property file in jre/lib folder
                          But still, i got same error...................

                          After that, I put following jar file in my jre/lib/ext folder and it's working

                          cumdict04.jar
                          cumlex.jar
                          cmu_time_awb.jar
                          cmutimelex.jar

                          You will get this all jar file from FreeTTS folder
                          • 10. Re: this is an example of java speech synthesizer.. which is givin runtime
                            843802
                            I had this problem as well - Classpaths at Runtime are the solution. You need it to have the JSAPI.jar classpath set with the runtime. In NetBeans this is under the project's properties panel. Idk about Eclipse. I'm using FreeTTS and had the error and now it works just fine.

                            Good luck!
                            • 11. Re: this is an example of java speech synthesizer.. which is givin runtime
                              843802
                              I just started off with JSAPI. And I immediately ran into problems. These are the configurations and the stuff I did:

                              My system:
                              OS: WinXP
                              JDK: JDK 6 Update 10
                              IDE: Netbeans 6.0

                              I downloaded the FreeTTS.zip from the FreeTTS site [http://freetts.sourceforge.net/docs/index.php] . I expanded it and in the lib folder I ran the jsapi.exe and as a result jsapi.jar war generated.

                              I included this jar in my project lib as jar. I also followed the steps above and added all that was required in runtime classpath.

                              Then I copy pasted HelloWorld speech recognition example code given in the site : [http://java.sun.com/products/java-media/speech/forDevelopers/jsapi-guide/Recognition.html#11644 ]

                              First it gave a compile time error that
                              rec.deallocate();
                              throws an exception which needs to be handled. Accordingly I surrounded it with a try catch block and caught the exceptions in the manner given below:
                              try{
                                      ...
                                      ...
                                       rec.deallocate();
                                                  System.exit(0);
                                              } catch (EngineException ex) {
                                                  Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex);
                                              } catch (EngineStateError ex) {
                                                  Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex);
                                              }
                              Now the code was compiling without problems.

                              When I executed the code a runtime exception (NullPointerException) was thrown at the line
                              rec.allocate();
                              in the psvm(String args[])

                              Can anybody please explain to me where I am going wrong? Or is there something more that needs to be added in the code?

                              Anxiously waiting to hear from your end.

                              Thanks and regards,