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

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



                 160    CHAPTER 5  ■  SPEECH



                            // sample program
                            public static void main(String args[]) {
                                int i;
                                i = 0;
                                String strRecognizedText;
                                System.out.println("Beginning speech recognition...");
                                // create speech recognition class
                                QuadmoreSR sr = new QuadmoreSR();
                                // wait until four words are heard
                                while (i < 4) {
                                    strRecognizedText = sr.TakeDictation();
                                    System.out.println("\n");
                                    System.out.println(strRecognizedText);
                                    i++;
                                }
                                System.out.println("Done.");
                            }
                        }

                            Just like Example 5-9, I could use the QuadmoreSR class in my programs, but I decided to
                        create a wrapper class that implements the SpeechRecognizer interface. There is no need to
                        implement the methods start(), stop(), open(), and close(), but they are required for the interface
                        so I will just create stubs. See Example 5-17.


                        Example 5-17. MicrosoftSR.java
                        package com.scottpreston.javarobot.chapter5;

                        public class MicrosoftSR implements JRecognizer {

                            // class used for recognizer
                            private QuadmoreSR ear;


                            // holds single instance of recognizer
                            private static MicrosoftSR instance;

                            // private constructor prevents initialization
                            // called by getInstance()
                            private MicrosoftSR() {

                                ear = new QuadmoreSR();
                            }
   174   175   176   177   178   179   180   181   182   183   184