Page 172 - The Definitive Guide to Building Java Robots
P. 172
Preston_5564C05.fm Page 153 Tuesday, September 20, 2005 5:13 AM
CHAPTER 5 ■ SPEECH 153
Example 5-11. JRecognizer.java
package com.scottpreston.javarobot.chapter5;
public interface JRecognizer {
// opens device or allocates it
public void open();
// closes device or deallocates it
public void close();
// starts recognizer engine
public void start();
// stops recognizer engine
public void stop();
// starts listening
public String listen();
}
First, speech recognition implementation uses the Sphinx-4 project at SourceForge. You
can find more information and other detailed examples at the project home page at http://
cmusphinx.sourceforge.net/sphinx4/. The Sphinx-4 is a speech recognition system written
entirely in the Java programming language. It was created as a joint project between the Sphinx
group at Carnegie Mellon University, Sun Microsystems, Mitsubishi Electric Research Labs
(MERL), and Hewlett Packard (HP), with contributions from the University of California at
Santa Cruz (USCS) and the Massachusetts Institute of Technology (MIT).
This program utilizes the “Command & Control” aspect of speech recognition. This means
I must specify a grammar file. The format is called Java Speech Grammar Format.
The first part of the grammar file is the grammar header. The header format is
#JSGF version char-encoding local;
The second part is called the grammar name declaration. It’s just a name; you can use
either a package or a name.
grammar packageName.someName;
grammar someName;
The third part is optional and gives you the ability to import other grammars.
import <fullyQualifiedRuleName>;
import <fullGrammarName>;
The fourth part is the grammar body. This is where your rule definitions are located. You
can use either pattern for the rule definition.
<ruleName> = rule expression;
public <ruleName> = rule expression;
Example 5-12 is a grammar file I’ll use to open notepad. It has two rules, one for notepad
and another for exiting.