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

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



                 152    CHAPTER 5  ■  SPEECH


                        5.2 Speech Recognition

                        In this section, I’ll show you two ways to create a speech recognition engine: the first using Java
                        and the second using JNI. In these two examples, I’ll show the two ways of speech recognition:
                        one using continuous dictation, and one using command and control. Also, because I’m going
                        to use two different implementations, I’ll create an interface that both will implement.
                            A class diagram of the classes I’ll create in this section is shown in Figure 5-4.




































                        Figure 5-4. Recognition classes

                        Code Objective
                        The objective of this section is to create an interface that standardizes behavior between the
                        two implementing speech recognition classes.

                        Code Discussion

                        This interface includes five methods. The open() and close() methods allocate and deallocate
                        the same way that the JVoice interfaces implementation classes do. The start() method starts
                        the recording device(), while the stop() method stops the recording device. Finally, the listen()
                        method returns a String of the spoken phrase or word. See Example 5-11.
   166   167   168   169   170   171   172   173   174   175   176