Overview | Package | Class | Tree | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ResultListener
receive notifications of
events related to a Result
object. A ResultListener
may be attached to any of three entities:
Recognizer
: a ResultListener
attached
to a Recognizer
receives notification of all
ResultEvents
for all results produced by that
recognizer.
Grammar
: a ResultListener
attached to a
Grammar
receives all events for all results that have
been finalized for that grammar. Specifically, it receives the
GRAMMAR_FINALIZED
event and following events.
(Note: it never receives a RESULT_CREATED
event because
that event always precedes the GRAMMAR_FINALIZED
event).
Result
: a ResultListener
attached to
a Result
receives all events for that result starting
from the time at which the listener is attached.
(Note: it never receives a RESULT_CREATED
event
because a listener can only be attached to a Result
once a RESULT_CREATED
event has already been issued.)
The events are issued to the listeners in the order of most specific
to least specific: ResultListeners
attached to the
Result
are notified first, then listeners attached
to the matched Grammar
, and finally to listeners
attached to the Recognizer
.
A single ResultListener
may be attached to multiple objects
(Recognizer
, Grammar
or Result
),
and multiple ResultListeners
may be attached to a single
object.
The source for all ResultEvents
issued to a
ResultListener
is the Result
that
generated the event. The full state system for results and the
associated events are described in the documentation
for ResultEvent
.
A trivial implementation of the ResultListener
interface is provided by the ResultAdapter
class.
Method Summary | |
void | audioReleased(ResultEvent e)
A AUDIO_RELEASED event has occured.
|
void | grammarFinalized(ResultEvent e)
A GRAMMAR_FINALIZED event has occured because
the Recognizer has determined which Grammar
is matched by the incoming speech.
|
void | resultAccepted(ResultEvent e)
An RESULT_ACCEPTED event has occured indicating
that a Result has transitioned from the
UNFINALIZED state to the ACCEPTED
state.
|
void | resultCreated(ResultEvent e)
A RESULT_CREATED event is issued when a
Recognizer detects incoming speech that
may match an active grammar of an application.
|
void | resultRejected(ResultEvent e)
An RESULT_REJECTED event has occured indicating
that a Result has transitioned from the
UNFINALIZED state to the REJECTED state.
|
void | resultUpdated(ResultEvent e)
A RESULT_UPDATED event has occured because a token has
been finalized and/or the unfinalized text of a result has changed.
|
void | trainingInfoReleased(ResultEvent e)
A TRAINING_INFO_RELEASED event has occured.
|
Method Detail |
public void resultCreated(ResultEvent e)
RESULT_CREATED
event is issued when a
Recognizer
detects incoming speech that
may match an active grammar of an application.
The event is issued to each ResultListener
attached to the Recognizer
.
(ResultListeners
attached to a Grammar
or to a Result
never receive a RESULT_CREATED
event.)
The RESULT_CREATED
follows the
RECOGNIZER_PROCESSING
event that is issued
RecognizerListeners
to indicate that the
Recognizer
has changed from the LISTENING
to the PROCESSING
state.
public void resultUpdated(ResultEvent e)
RESULT_UPDATED
event has occured because a token has
been finalized and/or the unfinalized text of a result has changed.
The event is issued to each ResultListener
attached
to the Recognizer
, to each ResultListener
attached to the Result
, and if the GRAMMAR_FINALIZED
event has already been released to each ResultListener
attached to the matched Grammar
.
public void grammarFinalized(ResultEvent e)
GRAMMAR_FINALIZED
event has occured because
the Recognizer
has determined which Grammar
is matched by the incoming speech.
The event is issued to each ResultListener
attached
to the Recognizer
, Result
, and
matched Grammar
.
public void resultAccepted(ResultEvent e)
RESULT_ACCEPTED
event has occured indicating
that a Result
has transitioned from the
UNFINALIZED
state to the ACCEPTED
state.
Since the Result
source for this event is
finalized, the Result
object can be safely cast
to the FinalResult
interface.
Because the result is accepted, the matched Grammar
for the result is guaranteed to be non-null. If the matched
Grammar
is a RuleGrammar
, then the
result object can be safely cast to FinalRuleResult
(methods of FinalDictationResult
throw an exception).
If the matched Grammar
is a DictationGrammar
,
then the result object can be safely cast to FinalDictationResult
(methods of FinalRuleResult
throw an exception).
For example:
void resultAccepted(ResultEvent e) { Object source = e.getSource(); // always safe Result result = (Result)source; FinalResult fr = (FinalResult)source; // find the grammar-specific details // the null test is only useful for rejected results if (result.getGrammar() != null) { if (result.getGrammar() instanceof RuleGrammar) { FinalRuleResult frr = (FinalRuleResult)source; ... } else if (result.getGrammar() instanceof DictationGrammar) { FinalDictationResult fdr = (FinalDictationResult)source; ... }The event is issued to each
ResultListener
attached
to the Recognizer
, Result
, and
matched Grammar
.
The RESULT_ACCEPTED
event is issued following
the RECOGNIZER_SUSPENDED
RecognizerEvent
and while the Recognizer
is in the SUSPENDED
state. Once the RESULT_ACCEPTED
event has been
processed by all listeners, the Recognizer
automatically
commits all changes to grammars and returns to the LISTENING
state. The only exception is when a call has been made to
suspend
without a following call to commitChanges
.
In this case the Recognizer
remains SUSPENDED
until commitChanges
is called.
public void resultRejected(ResultEvent e)
RESULT_REJECTED
event has occured indicating
that a Result
has transitioned from the
UNFINALIZED
state to the REJECTED
state.
The casting behavior of a rejected result is the same as for
a RESULT_ACCEPTED
event. The exception is that if the
grammar is not known (no GRAMMAR_FINALIZED
event),
then the result cannot be cast to either
FinalRuleResult
or FinalDictationResult
.
The state behavior and grammar committing actions are the
same as for the RESULT_ACCEPTED
event.
The event is issued to each ResultListener
attached
to the Recognizer
and to the Result
.
If a GRAMMAR_FINALIZED
event was issued, then
the matched Grammar
is known, and the
event is also issued to each ResultListener
attached
to that Grammar
.
public void audioReleased(ResultEvent e)
AUDIO_RELEASED
event has occured.
This event is only issued to finalized results.
See the documentation of the isAudioAvailable
method
the FinalResult
interface for details.
The event is issued to each ResultListener
attached
to the Recognizer
and to the Result
.
If a GRAMMAR_FINALIZED
event was issued, then
the matched Grammar
is known, and the
event is also issued to each ResultListener
attached
to that Grammar
.
public void trainingInfoReleased(ResultEvent e)
TRAINING_INFO_RELEASED
event has occured.
This event is only issued to finalized results.
See the documentation of the isTrainingInfoAvailable
method
the FinalResult
interface for details.
The event is issued to each ResultListener
attached
to the Recognizer
and to the Result
.
If a GRAMMAR_FINALIZED
event was issued, then
the matched Grammar
is known, and the
event is also issued to each ResultListener
attached
to that Grammar
.
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