public class Recognizer extends java.lang.Object implements Configurable, ResultProducer
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 stateModifier and Type | Class and Description |
---|---|
static class |
Recognizer.State
Defines the possible states of the recognizer.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PROP_DECODER
The property for the decoder to be used by this recognizer.
|
static java.lang.String |
PROP_MONITORS
The property for the set of monitors for this recognizer
|
Constructor and Description |
---|
Recognizer() |
Recognizer(Decoder decoder,
java.util.List<Monitor> monitors) |
Modifier and Type | Method and Description |
---|---|
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.
|
Recognizer.State |
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() |
@S4Component(type=Decoder.class) public static final java.lang.String PROP_DECODER
@S4ComponentList(type=Monitor.class) public static final java.lang.String PROP_MONITORS
public void newProperties(PropertySheet ps) throws PropertyException
Configurable
newProperties
in interface Configurable
ps
- a property sheet holding the new dataPropertyException
- if there is a problem with the properties.public Result recognize(java.lang.String referenceText) throws java.lang.IllegalStateException
allocated
state.referenceText
- what was actually spokenjava.lang.IllegalStateException
- if the recognizer is not in the ALLOCATED
statepublic Result recognize() throws java.lang.IllegalStateException
allocated
state.java.lang.IllegalStateException
- if the recognizer is not in the ALLOCATED
statepublic void allocate() throws java.lang.IllegalStateException
deallocated
state.java.lang.IllegalStateException
- if the recognizer is not in the DEALLOCATED
statepublic void deallocate() throws java.lang.IllegalStateException
allocated
state.java.lang.IllegalStateException
- if the recognizer is not in the ALLOCATED
statepublic Recognizer.State getState()
public void resetMonitors()
public void addResultListener(ResultListener resultListener)
addResultListener
in interface ResultProducer
resultListener
- the listener to addpublic void addStateListener(StateListener stateListener)
stateListener
- the listener to addpublic void removeResultListener(ResultListener resultListener)
removeResultListener
in interface ResultProducer
resultListener
- the listener to removepublic void removeStateListener(StateListener stateListener)
stateListener
- the state listener to removepublic java.lang.String toString()
toString
in class java.lang.Object