edu.cmu.sphinx.recognizer
Class Recognizer

java.lang.Object
  extended byedu.cmu.sphinx.recognizer.Recognizer
All Implemented Interfaces:
Configurable

public class Recognizer
extends java.lang.Object
implements Configurable

The Sphinx-4 recognizer. This is the main entry point for Sphinx-4. Typical usage of a recognizer is like so:


  public void recognizeDigits() {
      URL digitsConfig = new URL("file:./digits.xml");
      ConfigurationManager cm = new ConfigurationManager(digitsConfig);
      Recognizer sphinxDigitsRecognizer 
          = (Recognizer) cm.lookup("digitsRecognizer"");
      boolean done = false;
      Result result;

      sphinxDigitsRecognizer.allocate();

     // echo spoken digits, quit when 'nine' is spoken

      while (!done) {
           result = sphinxDigitsRecognizer.recognize();
           System.out.println("Result: " + result);
           done = result.toString().equals("nine");
      }

      sphinxDigitsRecognizer.deallocate(); 
   }
 
Note that some Recognizer methods may throw an IllegalStateException if the recognizer is not in the proper state


Field Summary
static java.lang.String PROP_DECODER
          Property name for the decoder to be used by this recognizer.
static java.lang.String PROP_MONITORS
          Property name for the set of monitors for this recognizer
 
Constructor Summary
Recognizer()
           
 
Method Summary
 void addResultListener(ResultListener resultListener)
          Adds a result listener to this recognizer.
 void addStateListener(StateListener stateListener)
          Adds a status listener to this recognizer.
 void allocate()
          Allocate the resources needed for the recognizer.
 void deallocate()
          Deallocates the recognizer.
 java.lang.String getName()
          Retrieves the name for this configurable component
 RecognizerState getState()
          Retrieves the recognizer state.
 void newProperties(PropertySheet ps)
          This method is called when this configurable component has new data.
 Result recognize()
          Performs recognition for the given number of input frames, or until a 'final' result is generated.
 Result recognize(java.lang.String referenceText)
          Performs recognition for the given number of input frames, or until a 'final' result is generated.
 void register(java.lang.String name, Registry registry)
          Register my properties.
 void removeResultListener(ResultListener resultListener)
          Removes a previously added result listener.
 void removeStateListener(StateListener stateListener)
          Removes a previously added state listener.
 void resetMonitors()
          Resets the monitors monitoring this recognizer
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_DECODER

public static final java.lang.String PROP_DECODER
Property name for the decoder to be used by this recognizer.

See Also:
Constant Field Values

PROP_MONITORS

public static final java.lang.String PROP_MONITORS
Property name for the set of monitors for this recognizer

See Also:
Constant Field Values
Constructor Detail

Recognizer

public Recognizer()
Method Detail

register

public void register(java.lang.String name,
                     Registry registry)
              throws PropertyException
Description copied from interface: Configurable
Register my properties. This method is called once early in the time of the component, shortly after the component is constructed. This component should register any configuration properties that it needs to register. If this configurable extends another configurable, super.register should also be called

Specified by:
register in interface Configurable
Parameters:
name - the name of the component
registry - the registry for this component
Throws:
PropertyException

newProperties

public void newProperties(PropertySheet ps)
                   throws PropertyException
Description copied from interface: Configurable
This method is called when this configurable component has new data. The component should first validate the data. If it is bad the component should return false. If the data is good, the component should record the the data internally and return true.

Specified by:
newProperties in interface Configurable
Parameters:
ps - a property sheet holding the new data
Throws:
PropertyException - if there is a problem with the properties.

recognize

public Result recognize(java.lang.String referenceText)
                 throws java.lang.IllegalStateException
Performs recognition for the given number of input frames, or until a 'final' result is generated. This method should only be called when the recognizer is in the allocated state.

Parameters:
referenceText - what was actually spoken
Returns:
a recognition result
Throws:
java.lang.IllegalStateException - if the recognizer is not in the ALLOCATED state

recognize

public Result recognize()
                 throws java.lang.IllegalStateException
Performs recognition for the given number of input frames, or until a 'final' result is generated. This method should only be called when the recognizer is in the allocated state.

Returns:
a recognition result
Throws:
java.lang.IllegalStateException - if the recognizer is not in the ALLOCATED state

allocate

public void allocate()
              throws java.lang.IllegalStateException,
                     java.io.IOException
Allocate the resources needed for the recognizer. Note this method make take some time to complete. This method should only be called when the recognizer is in the deallocated state.

Throws:
java.lang.IllegalStateException - if the recognizer is not in the DEALLOCATED state
java.io.IOException

deallocate

public void deallocate()
                throws java.lang.IllegalStateException
Deallocates the recognizer. This method should only be called if the recognizer is in the allocated state.

Throws:
java.lang.IllegalStateException - if the recognizer is not in the ALLOCATED state

getState

public RecognizerState getState()
Retrieves the recognizer state. This method can be called in any state.

Returns:
the recognizer state

resetMonitors

public void resetMonitors()
Resets the monitors monitoring this recognizer


addResultListener

public void addResultListener(ResultListener resultListener)
Adds a result listener to this recognizer. A result listener is called whenever a new result is generated by the recognizer. This method can be called in any state.

Parameters:
resultListener - the listener to add

addStateListener

public void addStateListener(StateListener stateListener)
Adds a status listener to this recognizer. The status listener is called whenever the status of the recognizer changes. This method can be called in any state.

Parameters:
stateListener - the listener to add

removeResultListener

public void removeResultListener(ResultListener resultListener)
Removes a previously added result listener. This method can be called in any state.

Parameters:
resultListener - the listener to remove

removeStateListener

public void removeStateListener(StateListener stateListener)
Removes a previously added state listener. This method can be called in any state.

Parameters:
stateListener - the state listener to remove

getName

public java.lang.String getName()
Description copied from interface: Configurable
Retrieves the name for this configurable component

Specified by:
getName in interface Configurable
Returns:
the name

toString

public java.lang.String toString()