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

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



                                                                                  CHAPTER 5  ■  SPEECH   143


                              JNIEXPORT jfloat JNICALL➥
                              Java_com_scottpreston_javarobot_chapter5_TempConvert_FtoC
                                (JNIEnv *, jobject, jfloat f)
                              {
                                      // native code
                              return (f -= 32) /= 1.8;
                              }

                            8. Build the .dll and place it in system32.
                            9. Run the program.

                            By using the JNI, you can take advantage of some native voices for speech synthesis and
                        recognition. This way, if you already have some software or have configured your machine to
                        recognize your voice with native software, you won’t have to retrain your system. I’ll discuss
                        how to use the JNI for speech synthesis in section 5.2, but first let’s talk about Java Speech
                        Synthesis.


                        5.1 Speech Synthesis

                        Java Speech API (JSAPI) and Free Text To Speech (FreeTTS) are speech synthesis programs
                        written entirely in Java. It’s important to note that FreeTTS supports only a subset of JSAPI 1.0
                        and has some restrictions. Please reference the FreeTTS web site (http://freetts.sourceforge.net)
                        for more information on the software and its usage.
                            I’ll have three implementations for speech synthesis: two Java and one native. So, to
                        standardize behavior, I’ll create an interface called JVoice and then have two implementation
                        classes: one using JSAPI, called JavaVoice; and one using FreeTTS, called FreeTTSVoice. Figure 5-3
                        shows a class diagram of the setup.



























                        Figure 5-3. Java speech synthesis classes



                   97022d2480fe4a63cfdfa123a6e70098
   157   158   159   160   161   162   163   164   165   166   167