Overview | Package | Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Interface javax.speech.recognition.Result

Subinterfaces:
FinalResult

public abstract interface Result
A Result is issued by a Recognizer as it recognizes an incoming utterance that matches an active Grammar. The Result interface provides the application with access to the following information about a recognized utterance:

  1. A sequence of finalized tokens (words) that have been recognized,
  2. A sequence of unfinalized tokens,
  3. Reference to the grammar matched by the result,
  4. The result state: UNFINALIZED, ACCEPTED or REJECTED.

Multiple Result Interfaces

Every Result object provided by a Recognizer implements both the FinalRuleResult and FinalDictationResult interfaces. Thus, by extension every result also implements the FinalResult and Result interfaces.

These multiple interfaces are designed to explicitly indicate (a) what information is available at what times in the result life-cycle and (b) what information is available for different types of results. Appropriate casting of results allows compile-time checking of result-handling code and fewer bugs.

The FinalResult extends the Result interface. It provides access to the additional information about a result that is available once it has been finalized (once it is in either of the ACCEPTED or REJECTED states). Calling any method of the FinalResult interface for a result in the UNFINALIZED state causes a ResultStateError to be thrown.

The FinalRuleResult extends the FinalResult interface. It provides access to the additional information about a finalized result that matches a RuleGrammar. Calling any method of the FinalRuleResult interface for a non-finalized result or a result that matches a DictationGrammar causes a ResultStateError to be thrown.

The FinalDictationResult also extends the FinalResult interface. It provides access to the additional information about a finalized result that matches a DictationGrammar. Calling any method of the FinalDictationResult interface for a non-finalized result or a result that matches a RuleGrammar causes a ResultStateError to be thrown.

Note: every result implements both the FinalRuleResult and FinalDictationResult interfaces even though the result will match either a RuleGrammar or DictationGrammar, but never both. The reason for this is that when the result is created (RESULT_CREATED event), the grammar is not always known.

Result States

The separate interfaces determine what information is available for a result in the different stages of its life-cycle. The state of a Result is determined by calling the getResultState method. The three possible states are UNFINALIZED, ACCEPTED and REJECTED.

A new result starts in the UNFINALIZED state. When the result is finalized is moves to either the ACCEPTED or REJECTED state. An accepted or rejected result is termed a finalized result. All values and information regarding a finalized result are fixed (excepting that audio and training information may be released).

Following are descriptions of a result object in each of the three states including information on which interfaces can be used in each state.

getResultState() == Result.UNFINALIZED

getResultState() == Result.ACCEPTED

getResultState() == Result.REJECTED

Result State and Recognizer States

The state system of a Recognizer is linked to the state of recognition of the current result. The Recognizer interface documents the normal event cycle for a Recognizer and for Results. The following is an overview of the ways in which the two state systems are linked:

Accept or Reject?

Rejection of a result indicates that the recognizer is not confident that it has accurately recognized what a user says. Rejection can be controlled through the RecognizerProperties interface with the setConfidenceLevel method. Increasing the confidence level requires the recognizer to have greater confident to accept a result, so more results are likely to be rejected.

Important: the acceptance of a result (an RESULT_ACCEPTED event rather than a RESULT_REJECTED event) does not mean the result is correct. Instead acceptance implies that the recognizer has a sufficient level of confidence that the result is correct.

It is difficult for recognizers to reliably determine when they make mistakes. Applications need to determine the cost of incorrect recognition of any particular results and take appropriate actions. For example, confirm with a user that they said "delete all files" before deleting anything.

Result Events

Events are issued when a new result is created and when there is any change in the state or information content of a result. The following describes the event sequence for an accepted result. It provides the same information as above for result states, but focusses on legal event sequences.

Before a new result is created for incoming speech, a recognizer usually issues a SPEECH_STARTED event to the speechStarted method of RecognizerAudioListener. The

A newly created Result is provided to the application by calling the resultCreated method of each ResultListener attached to the Recognizer with a RESULT_CREATED event. The new result may or may not have any finalized tokens or unfinalized tokens.

At any time following the RESULT_CREATED event, an application may attach a ResultListener to an individual result. That listener will receive all subsequent events associated with that Result.

A new Result is created in the UNFINALIZED state. In this state, zero or more RESULT_UPDATED events may be issued to each ResultListener attached to the Recognizer and to each ResultListener attached to that Result. The RESULT_UPDATED indicates that one or more tokens have been finalized, or that the unfinalized tokens have changed, or both.

When the recognizer determines which grammar is the best match for incoming speech, it issues a GRAMMAR_FINALIZED event. This event is issued to each ResultListener attached to the Recognizer and to each ResultListener attached to that Result.

The GRAMMAR_FINALIZED event is also issued to each ResultListener attached to the matched Grammar. This is the first ResultEvent received by ResultListeners attached to the Grammar. All subsequent result events are issued to all ResultListeners attached to the matched Grammar (as well as to ResultListeners attached to the Result and to the Recognizer).

Zero or more RESULT_UPDATED events may be issued after the GRAMMAR_FINALIZED event but before the result is finalized.

Once the recognizer completes recognition of the Result that it choses to accept, it finalizes the result with an RESULT_ACCEPTED event that is issued to the ResultListeners attached to the Recognizer, the matched Grammar, and the Result. This event may also indicate finalization of zero or more tokens, and/or the reseting of the unfinalized tokens to null. The result finalization event occurs immediately after the Recognizer makes a transition from the PROCESSING state to the SUSPENDED state with a RECOGNIZER_SUSPENDED event.

A finalized result (accepted or rejected state) may issue a AUDIO_RELEASED or TRAINING_INFO_RELEASED event. These events may be issued in response to relevant release methods of FinalResult and FinalDictationResult or may be issued when the recognizer independently determines to release audio or training information.

When a result is rejected some of the events described above may be skipped. A result may be rejected with the RESULT_REJECTED event at any time after a RESULT_CREATED event instead of an RESULT_ACCEPTED event. A result may be rejected with or without any unfinalized or finalized tokens being created (no RESULT_UPDATED events), and with or without a GRAMMAR_FINALIZED event.

When does a Result start and end?

A new result object is created when a recognizer has detected possible incoming speech which may match an active grammar.

To accept the result (i.e. to issue a RESULT_ACCEPTED event), the best-guess tokens of the result must match the token patterns defined by the matched grammar. For a RuleGrammar this implies that a call to the parse method of the matched RuleGrammar must return successfully. (Note: the parse is not guaranteed if the grammar has been changed.)

Because there are no programmatically defined constraints upon word patterns for a DictationGrammar, a single result may represent a single word, a short phrase or sentence, or possibly many pages of text.

The set of conditions that may cause a result matching a DictationGrammar to be finalized includes:

The following conditions apply to all finalized results:

See Also:
FinalResult, FinalRuleResult, FinalDictationResult, ResultEvent, ResultListener, ResultAdapter, Grammar, RuleGrammar, DictationGrammar, forceFinalize, RecognizerEvent, setConfidenceLevel

Field Summary
static int ACCEPTED
          getResultState returns ACCEPTED once recognition of the result is completed and the Result object has been finalized by being accepted.
static int REJECTED
          getResultState returns REJECTED once recognition of the result complete and the Result object has been finalized by being rejected.
static int UNFINALIZED
          getResultState returns UNFINALIZED while a result is still being recognized.
 
Method Summary
void addResultListener(ResultListener listener)
          Request notifications of events of related to this Result.
ResultToken getBestToken(int tokNum)
          Returns the best guess for the tokNumth token.
ResultToken[] getBestTokens()
          Returns all the best guess tokens for this result.
Grammar getGrammar()
          Return the Grammar matched by the best-guess finalized tokens of this result or null if the grammar is not known.
int getResultState()
          Returns the current state of the Result object: UNFINALIZED, ACCEPTED or REJECTED.
ResultToken[] getUnfinalizedTokens()
          In the UNFINALIZED state, return the current guess of the tokens following the finalized tokens.
int numTokens()
          Returns the number of finalized tokens in a Result.
void removeResultListener(ResultListener listener)
          Remove a listener from this Result.
 

Field Detail

UNFINALIZED

public static final int UNFINALIZED
getResultState returns UNFINALIZED while a result is still being recognized. A Result is in the UNFINALIZED state when the RESULT_CREATED event is issued. Result states are described above in detail.

See Also:
getResultState, RESULT_CREATED

ACCEPTED

public static final int ACCEPTED
getResultState returns ACCEPTED once recognition of the result is completed and the Result object has been finalized by being accepted. When a Result changes to the ACCEPTED state a RESULT_ACCEPTED event is issued. Result states are described above in detail.

See Also:
getResultState, RESULT_ACCEPTED

REJECTED

public static final int REJECTED
getResultState returns REJECTED once recognition of the result complete and the Result object has been finalized by being rejected. When a Result changes to the REJECTED state a RESULT_REJECTED event is issued. Result states are described above in detail.

See Also:
getResultState, RESULT_REJECTED
Method Detail

getResultState

public int getResultState()
Returns the current state of the Result object: UNFINALIZED, ACCEPTED or REJECTED. The details of a Result in each state are described above.

See Also:
UNFINALIZED, ACCEPTED, REJECTED

getGrammar

public Grammar getGrammar()
Return the Grammar matched by the best-guess finalized tokens of this result or null if the grammar is not known. The return value is null before a GRAMMAR_FINALIZED event and non-null afterwards.

The grammar is guaranteed to be non-null for an accepted result. The grammar may be null or non-null for a rejected result, depending upon whether a GRAMMAR_FINALIZED event was issued prior to finalization.

For a finalized result, an application should determine the type of matched grammar with an instanceof test. For a result that matches a RuleGrammar, the methods of FinalRuleResult can be used (the methods of FinalDictationResult throw an error). For a result that matches a DictationGrammar, the methods of FinalDictationResult can be used (the methods of FinalRuleResult throw an error). The methods of FinalResult can be used for a result matching either kind of grammar.

Example:

    Result result;
    if (result.getGrammar() instanceof RuleGrammar) {
      FinalRuleResult frr = (FinalRuleResult)result;
      ...
    }
 

See Also:
getResultState

numTokens

public int numTokens()
Returns the number of finalized tokens in a Result. Tokens are numbered from 0 to numTokens()-1 and are obtained through the getBestToken and getBestTokens method of this (Result) interface and the getAlternativeTokens methods of the FinalRuleResult and FinalDictationResult interfaces for a finalized result.

Starting from the RESULT_CREATED event and while the result remains in the UNFINALIZED state, the number of finalized tokens may be zero or greater and can increase as tokens are finalized. When one or more tokens are finalized in the UNFINALIZED state, a RESULT_UPDATED event is issued with the tokenFinalized flag set true. The RESULT_ACCEPTED and RESULT_REJECTED events which finalize a result can also indicate that one or more tokens have been finalized.

In the ACCEPTED and REJECTED states, numTokens indicates the total number of tokens that were finalized. The number of finalized tokens never changes in these states. An ACCEPTED result must have one or more finalized token. A REJECTED result may have zero or more tokens.

See Also:
RESULT_UPDATED, getBestToken, getBestTokens, getAlternativeTokens, getAlternativeTokens

getBestToken

public ResultToken getBestToken(int tokNum)
                                                 throws IllegalArgumentException
Returns the best guess for the tokNumth token. tokNum must be in the range 0 to numTokens()-1.

If the result has zero tokens (possible in both the UNFINALIZED and REJECTED states) an exception is thrown.

If the result is in the REJECTED state, then the returned tokens are likely to be incorrect. In the ACCEPTED state (not rejected) the recognizer is confident that the tokens are correct but applications should consider the possibility that the tokens are incorrect.

The FinalRuleResult and FinalDictationResult interfaces provide getAlternativeTokens methods that return alternative token guesses for finalized results.

Throws:
IllegalArgumentException - if tokNum is out of range.
See Also:
getUnfinalizedTokens, getBestTokens, getAlternativeTokens, getAlternativeTokens

getBestTokens

public ResultToken[] getBestTokens()
Returns all the best guess tokens for this result. If the result has zero tokens, the return value is null.

getUnfinalizedTokens

public ResultToken[] getUnfinalizedTokens()
In the UNFINALIZED state, return the current guess of the tokens following the finalized tokens. Unfinalized tokens provide an indication of what a recognizer is considering as possible recognition tokens for speech following the finalized tokens.

. * Unfinalized tokens can provide users with feedback on the recognition process. The array may be any length (zero or more tokens), the length may change at any time, and successive calls to getUnfinalizedTokens may return different tokens or even different numbers of tokens. When the unfinalized tokens are changed, a RESULT_UPDATED event is issued to the ResultListener. The RESULT_ACCEPTED and RESULT_REJECTED events finalize a result and always guarantee that the return value is null. A new result created with a RESULT_CREATED event may have a null or non-null value.

The returned array is null if there are currently no unfinalized tokens, if the recognizer does not support unfinalized tokens, or after a Result is finalized (in the ACCEPTED or REJECTED state).

See Also:
isUnfinalizedTokensChanged, RESULT_UPDATED, RESULT_ACCEPTED, RESULT_REJECTED

addResultListener

public void addResultListener(ResultListener listener)
Request notifications of events of related to this Result. An application can attach multiple listeners to a Result. A listener can be removed with the removeResultListener method.

ResultListener objects can also be attached to a Recognizer and to any Grammar. A listener attached to the Recognizer receives all events for all results produced by that Recognizer. A listener attached to a Grammar receives all events for all results that have been finalized for that Grammar (all events starting with and including the GRAMMAR_FINALIZED event).

A ResultListener attached to a Result only receives events following the point in time at which the listener is attached. Because the listener can only be attached during or after the RESULT_CREATED, it will not receive the RESULT_CREATED event. Only ResultListeners attached to the Recognizer receive RESULT_CREATED events.

See Also:
removeResultListener, addResultListener, addResultListener

removeResultListener

public void removeResultListener(ResultListener listener)
Remove a listener from this Result.

See Also:
addResultListener, removeResultListener, removeResultListener

Overview | Package | Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

JavaTM Speech API
Copyright 1997-1998 Sun Microsystems, Inc. All rights reserved
Send comments to javaspeech-comments@sun.com