Page 170 - The Definitive Guide to Building Java Robots
P. 170

Preston_5564C05.fm  Page 151  Tuesday, September 20, 2005  5:13 AM



                                                                                  CHAPTER 5  ■  SPEECH   151



                                    TTSCompare tts = new TTSCompare();
                                    // java voice
                                    JVoice voice1 = tts.getVoice(TTSCompare.JAVA_VOICE);
                                    // free tts voice
                                    JVoice voice2 = tts.getVoice(TTSCompare.FREETTS_VOICE);
                                    // microsoft voice
                                    JVoice voice3 = tts.getVoice(TTSCompare.MICROSOFT_VOICE);
                                    // open all of these
                                    voice1.open();
                                    voice2.open();
                                    voice3.open();
                                    // speak some text
                                    voice1.speak("Java Voice... Hello World!");
                                    voice2.speak("Free TTS Voice... Hello World!");
                                    voice3.speak("Microsoft Voice... Hello World!");
                                    // close them
                                    voice1.close();
                                    voice2.close();
                                    voice3.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.exit(1);
                                }


                            }
                        }
                            If you’d like to improve the quality of the FreeTTS voice, there are other extensions avail-
                        able at http://freetts.sourceforge.net.

                        Section Summary

                        In this section, I programmed my PC to talk using three different implementations of the
                        JVoice interface. Those classes are
                           • JavaVoice: This uses the JSAPI speech synthesis engine.

                           • FreeTTsVoice.java: This uses the FreeTTS speech synthesis engine.
                           • MicrosoftVoice.java: This uses JNI to connect the Microsoft Sound API and text-to-
                             speech engine.
                            Make sure you look at that site for more details. In the next section, I’m going to talk about
                        the second part of speech: recognition.
   165   166   167   168   169   170   171   172   173   174   175