edu.cmu.sphinx.recognizer
Class Recognizer

java.lang.Object
  extended by edu.cmu.sphinx.recognizer.Recognizer
All Implemented Interfaces:
ResultProducer, Configurable

public class Recognizer
extends java.lang.Object
implements Configurable, ResultProducer

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.
 RecognizerState getState()
          Retrieves the recognizer state.
 void newProperties(PropertySheet ps)
          This method is called when this configurable component needs to be reconfigured.
 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 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

@S4Component(type=Decoder.class)
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

@S4ComponentList(type=StateListener.class)
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

newProperties

public void newProperties(PropertySheet ps)
                   throws PropertyException
Description copied from interface: Configurable
This method is called when this configurable component needs to be reconfigured.

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
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

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.

Specified by:
addResultListener in interface ResultProducer
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.

Specified by:
removeResultListener in interface ResultProducer
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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object