|
JSAPI 2.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface FinalResult
Provides information about a Result
that has been finalized -
that is, recognition is complete.
A finalized Result
is a Result
that has received
a RESULT_ACCEPTED
or RESULT_REJECTED
event that puts it
in either the ACCEPTED
or REJECTED
state
as indicated by the getResultState
method.
If any method of the FinalResult
interface is called
on a Result
in the UNFINALIZED
state,
a ResultStateException
is thrown.
This interface provides training/correction capabilities
and access to audio data.
It additionally provides access to
alternative ResultToken
s.
All three capabilities are optional because they are not all relevant
to all Result
s or all recognition environments.
Recognizer
Result
s are not always correct,
applications need to consider the possibility that a
recognition error might occur.
When an application detects an error,
the application should inform the Recognizer
so that it can
learn from the mistake and try to improve future performance.
The tokenCorrection
method is provided for an application to
provide feedback from user correction to the Recognizer
.
Sometimes, but certainly not always, the correct Result
is
selected by a user from the Result
's N-best alternatives.
In other cases, a user may type the correct Result
or the
application may infer a correction from following user input.
Recognizer
s must store considerable information to support training
from Result
s.
Applications need to be involved in the management
of that information so that it is not stored unnecessarily.
The isTrainingInfoAvailable
method tests whether training information
is available for a finalized Result
.
When an application/user has finished correction/training
for a Result
,
it should call releaseTrainingInfo
to free up system resources.
Also, a Recognizer
may choose at any time
to free up training information.
In both cases, the application is notified of the release with a
TRAINING_INFO_RELEASED
event to ResultListener
s.
Result
is
optionally provided by Recognizer
s.
Audio data can be stored for future use by an application or user and in
certain circumstances can be provided by one Recognizer
to another.
Since storing audio requires substantial system resources, audio
data requires special treatment.
If an application wants to use audio data, it indicate this with the
setResultAudioProvided
method.
Not all Recognizer
s provide access to audio data.
For those Recognizer
s, setResultAudioProvided
has no effect,
isAudioAvailable
always returns false
, and the
getAudio
methods always return null
.
Recognizer
s that provide access to audio data cannot
always provide audio for every Result
.
Applications should test audio availability for every FinalResult
and
should always test for null
on the getAudio
methods.
Result
,
getResultState
,
ACCEPTED
,
REJECTED
,
UNFINALIZED
,
ResultEvent
,
RESULT_ACCEPTED
,
RESULT_REJECTED
,
TRAINING_INFO_RELEASED
,
ResultListener
,
FinalRuleResult
,
setResultAudioProvided
Field Summary | |
---|---|
static int |
DONT_KNOW
Constant indicating that the application does not know whether a change is because of MISRECOGNITION or USER_CHANGE . |
static int |
MISRECOGNITION
Constant indicating that the change is a correction of an error made by the Recognizer . |
static int |
USER_CHANGE
Constant indicating that the user has modified the text that was returned by the Recognizer to something different from what they actually said. |
Fields inherited from interface Result |
---|
ACCEPTED, REJECTED, UNFINALIZED |
Method Summary | |
---|---|
ResultToken[] |
getAlternativeTokens(int nBest)
Gets the token sequence for the Nth-best alternative. |
AudioSegment |
getAudio()
Gets the audio for the complete utterance of this Result . |
AudioSegment |
getAudio(ResultToken fromToken,
ResultToken toToken)
Gets the audio for a token or sequence of tokens. |
int |
getConfidenceLevel()
Gets the confidence level for the best token sequence. |
int |
getConfidenceLevel(int nBest)
Gets the confidence level for the Nth-best alternative. |
Grammar |
getGrammar(int nBest)
Returns the Grammar matched by the Nth-best alternative. |
int |
getNumberAlternatives()
Returns the number of alternatives for this Result . |
Object[] |
getTags(int nBest)
Returns the list of tags matched by the token sequence for the Nth-best alternative. |
boolean |
isAudioAvailable()
Tests whether audio data is available for this Result . |
boolean |
isTrainingInfoAvailable()
Returns true if the Recognizer has
training information available for this Result . |
void |
releaseAudio()
Releases the audio for this Result . |
void |
releaseTrainingInfo()
Releases the training information for this Result . |
void |
tokenCorrection(String[] correctTokens,
ResultToken fromToken,
ResultToken toToken,
int correctionType)
Informs the Recognizer of a correction to
one or more tokens in a finalized Result
so that the Recognizer can improve itself. |
Methods inherited from interface Result |
---|
addResultListener, getBestToken, getBestTokens, getGrammar, getNumTokens, getResultState, getUnfinalizedTokens, removeResultListener |
Field Detail |
---|
static final int MISRECOGNITION
Recognizer
.
tokenCorrection
,
USER_CHANGE
,
DONT_KNOW
,
Constant Field Valuesstatic final int USER_CHANGE
Recognizer
to something different from what they actually said.
tokenCorrection
,
MISRECOGNITION
,
DONT_KNOW
,
Constant Field Valuesstatic final int DONT_KNOW
MISRECOGNITION
or USER_CHANGE
.
tokenCorrection
,
MISRECOGNITION
,
USER_CHANGE
,
Constant Field ValuesMethod Detail |
---|
ResultToken[] getAlternativeTokens(int nBest) throws ResultStateException, IllegalArgumentException
The range for nBest
is
0
to (getNumberAlternatives()-1)
, inclusive,
where 0
represents the best alternative.
If nBest == 0
, this method returns a token sequence identical
to the token sequence returned by the getBestTokens
method.
If nBest == 1
(or 2
, 3
...) the method returns
the token sequence for the 1st- (2nd-, 3rd- ...) best alternative.
The number of tokens returned may vary
for each nBest
alternative.
If the Result
is in the ACCEPTED
state (not rejected),
then the best ResultToken
s and all the alternatives are accepted.
If the Result
is in the REJECTED
state (not accepted),
the Recognizer
is not confident that the
best ResultToken
s or any of the alternatives
are what the user said.
nBest
- the Nth-best index
ResultToken
s for the nBest
alternative
ResultStateException
- if called before a Result
is finalized
IllegalArgumentException
- if nBest
is not in rangegetNumberAlternatives
,
ACCEPTED
,
REJECTED
AudioSegment getAudio() throws ResultStateException
Result
.
Returns null
if audio is not available or if it has been released.
null
ResultStateException
- if called before a Result
is finalizedisAudioAvailable
,
getAudio(ResultToken,ResultToken)
AudioSegment getAudio(ResultToken fromToken, ResultToken toToken) throws IllegalArgumentException, ResultStateException
Recognizer
s make a best effort at determining
the start and end of tokens,
however, it is not unusual for chunks of surrounding audio to be included
or for the start or end token to be chopped.
Returns null
if Result
audio is not available,
if it cannot be obtained for the specified sequence of tokens,
or if it has been released.
If toToken
is null
or if fromToken
and toToken
are the same,
the method returns audio for fromToken
.
If both fromToken
and toToken
are null
,
it returns the audio for the entire Result
(same as getAudio()
).
Not all Recognizer
s can provide per-token audio,
even if they can provide audio for a complete Result
.
fromToken
- the beginning ResultToken
for audiotoToken
- the ending ResultToken
for audio
IllegalArgumentException
- either ResultToken
is not from
this FinalResult
and the same token sequence,
or if toToken
comes before fromToken
ResultStateException
- if called before a Result
is finalizedisAudioAvailable
,
getAudio()
int getConfidenceLevel() throws ResultStateException
Recognizer
's confidence
in this token sequence.
This method is the same as
getConfidenceLevel(0)
.
See that method for details.
ResultStateException
- if called before a Result
is finalizedgetConfidenceLevel(int)
int getConfidenceLevel(int nBest) throws IllegalArgumentException, ResultStateException
Recognizer
's confidence in this alternative.
For an ACCEPTED
result, the value should be at or above
the current value of RecognizerProperties.getConfidenceThreshold
.
Values lie in the range
between MIN_CONFIDENCE
and MAX_CONFIDENCE
.
A value of UNKNOWN_CONFIDENCE
may be returned if the
confidence level is unavailable or not supported.
For a REJECTED
result, a useful confidence level may be returned,
but this is application and platform dependent.
The range for nBest
is
0
to (getNumberAlternatives()-1)
, inclusive,
where 0
represents the best alternative.
nBest
- the Nth-best index
IllegalArgumentException
- if nBest
is not in range
ResultStateException
- if called before a Result
is finalizedgetConfidenceLevel()
,
RecognizerProperties
,
setConfidenceThreshold
,
MIN_CONFIDENCE
,
MAX_CONFIDENCE
,
UNKNOWN_CONFIDENCE
,
getResultState
,
getNumberAlternatives
,
ACCEPTED
,
REJECTED
Grammar getGrammar(int nBest) throws ResultStateException, IllegalArgumentException
Grammar
matched by the Nth-best alternative.
The range for nBest
is
0
to (getNumberAlternatives()-1)
, inclusive,
where 0
represents the best alternative.
Note that for a finalized Result
, the following holds true
:
getGrammar(0) == getGrammar()
nBest
- the Nth-Best index
Grammar
matched by the nBest
alternative
ResultStateException
- if called before a Result
is finalized
IllegalArgumentException
- if nBest
is not in rangegetNumberAlternatives
,
getAlternativeTokens
,
getGrammar()
int getNumberAlternatives() throws ResultStateException
Result
.
The alternatives are numbered from 0
up.
Alternative 0
is the best alternative.
If only the best alternative is available (no other alternatives), the
return value is 1
.
If the Result
was REJECTED,
the return value may be 0
if no tokens are available.
If the best alternative and additional alternatives are available,
the return value is greater than 1
.
Result
.
ResultStateException
- if called before a Result
is finalizedgetBestTokens
,
REJECTED
,
getAlternativeTokens
Object[] getTags(int nBest) throws ResultStateException, IllegalArgumentException, IllegalStateException
The range for nBest
is
0
to (getNumberAlternatives()-1)
, inclusive,
where 0
represents the best alternative.
A REJECTED
Result
is not guaranteed
to return tags and an empty list may be returned instead.
This method uses Grammar
s committed with the last
call to resume
before Result
finalization and
throws an IllegalStateException
if Grammar
changes
are subsequently committed by resume
.
nBest
- the Nth-Best index
nBest
alternative
ResultStateException
- if called before this Result
is finalized
IllegalArgumentException
- if nBest
is not in range
IllegalStateException
- if Grammar
changes are subsequently
committed by resume
getNumberAlternatives
,
getBestTokens
,
REJECTED
,
resume
boolean isAudioAvailable() throws ResultStateException
Result
.
Audio is only available if:
resultAudioProvided
property of
RecognizerProperties
was set
to true
when the Result
was recognized.
Recognizer
was able to collect audio
for this Result
.
Result
does not mean
that all getAudio
calls will return audio.
For example, some Recognizer
s might
provide audio data only for the entire Result
, only for
individual tokens, or not for sequences of more than one token.
true
if audio data is available for this Result
ResultStateException
- if called before a Result
is finalizedgetAudio
,
getAudio
,
RecognizerProperties
,
setResultAudioProvided
boolean isTrainingInfoAvailable() throws ResultStateException
true
if the Recognizer
has
training information available for this Result
.
Training information is available if the following conditions are met:
trainingProvided
property of the
RecognizerProperties
is set to true
.
Result
has not been
released by the application or by the Recognizer
.
This means that the TRAINING_INFO_RELEASED
event has
not been issued.
tokenCorrection
have no effect if
the training information is not available.
true
if training information is available
for this Result
ResultStateException
- if called before a Result
is finalizedRecognizerProperties
,
isTrainingProvided
,
releaseTrainingInfo
,
tokenCorrection
,
TRAINING_INFO_RELEASED
void releaseAudio() throws ResultStateException
Result
.
After audio is released, isAudioAvailable
will return false
.
This call is ignored if the audio is not available or
has already been released.
This method is asynchronous -
audio data is not necessarily released immediately.
An AUDIO_RELEASED
event is issued to the ResultListener
when the audio is released by a call to this method.
An AUDIO_RELEASED
event is also issued if the Recognizer
releases the audio for some other reason
(for example, to reclaim memory).
ResultStateException
- if called before a Result
is finalizedisAudioAvailable
,
AUDIO_RELEASED
,
ResultListener
void releaseTrainingInfo() throws ResultStateException
Result
.
The release frees memory used for the training information -
this information can be substantial.
After training information is released,
isTrainingInfoAvailable
will return false
.
It is not an error to call the method when training information
is not available or has already been released.
This method is asynchronous - the training info is not necessarily
released when the call returns.
A TRAINING_INFO_RELEASED
event
is issued to the ResultListener
once the information is released.
The TRAINING_INFO_RELEASED
event is also issued if the
Recognizer
releases the training information for any other reason
(for example, to reclaim memory).
ResultStateException
- if called before a Result
is finalizedisTrainingInfoAvailable
,
TRAINING_INFO_RELEASED
,
ResultListener
void tokenCorrection(String[] correctTokens, ResultToken fromToken, ResultToken toToken, int correctionType) throws ResultStateException, IllegalArgumentException, SecurityException
Recognizer
of a correction to
one or more tokens in a finalized Result
so that the Recognizer
can improve itself.
Training the Recognizer
from its mistakes allows it to improve
its performance and accuracy in future recognition.
Correction improvements apply to the Recognizer
instance,
but may persist longer.
If the Recognizer
uses a SpeakerManager
,
improvements may only apply to the current SpeakerProfile
.
The fromToken
and toToken
parameters indicate the
inclusive sequence of tokens that are being trained or corrected.
If toToken
is null
or
if fromToken
and toToken
are the same,
the training applies to a single recognized token.
The correctTokens
sequence may have the same or different
length than the token sequence being corrected.
Setting correctTokens
to null
indicates the deletion of tokens.
The correctionType
parameter must be one of
MISRECOGNITION
, USER_CHANGE
, or DONT_KNOW
.
Note that tokenCorrection
does not change the
Result
object.
Future calls to the getBestToken
,
getBestTokens
and getAlternativeTokens
methods return exactly the same values as before this call.
correctTokens
- replacement sequence for
fromToken
to toToken
fromToken
- first token in the sequence being correctedtoToken
- last token in the sequence being correctedcorrectionType
- type of correction
IllegalArgumentException
- either token is not from
this FinalResult
or if toToken
comes
before fromToken
ResultStateException
- if called before a Result
is finalized
SecurityException
- if token correction is not allowed for the
applicationMISRECOGNITION
,
USER_CHANGE
,
DONT_KNOW
,
getBestTokens
,
SpeakerManager
,
SpeakerProfile
javax.speech.recognition.FinalResult.tokenCorrection
|
JSAPI 2.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaTM Speech API 2.0,
Final Release v2.0.6.
© 2008, Conversay and Sun Microsystems.