|
JSAPI 2.0 | |||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
Recognizer
s.
See:
Description
Interface Summary | |
---|---|
FinalResult | Provides information about a Result that has been finalized -
that is, recognition is complete. |
FinalRuleResult | Provides information on a finalized Result for
an utterance that matches a RuleGrammar . |
Grammar | Parent interface supported by all types of recognition grammars. |
GrammarListener | The listener interface for receiving notifications of
status change events for a Grammar . |
GrammarManager | Provides management of Grammar s. |
Recognizer | Provides access to speech recognition capabilities. |
RecognizerListener | The listener interface for events associated with a Recognizer . |
RecognizerProperties | Enables control of the properties of a Recognizer . |
Result | A Result is issued by a Recognizer as it recognizes
an incoming utterance that matches an active Grammar . |
ResultListener | The listener interface for ResultEvent s associated
with a Result . |
ResultToken | A token (usually a word) contained by a Result representing something
heard by a Recognizer . |
RuleGrammar | Defines a Grammar that specifies what users may
say by a set of Rule s. |
SpeakerManager | Provides management of speaker-specific data for a Recognizer . |
SpeakerManagerUI | Provides access to a user interface for managing speaker and training data. |
Class Summary | |
---|---|
GrammarEvent | Event issued to GrammarListener s
when events associated with Grammar s occur. |
GrammarExceptionDetail | Describes a problem found in a Grammar . |
RecognizerEvent | Event issued by a Recognizer to indicate a change
in state or other activity. |
RecognizerMode | Provides information about a specific operating mode of a Recognizer . |
ResultEvent | Event issued to indicate changes in the
Result state and recognized tokens. |
Rule | Represents a Rule in a RuleGrammar . |
RuleAlternatives | Represents a RuleComponent composed of a set of alternative
RuleComponent s. |
RuleComponent | Represents the different components
that may appear on the right-hand side of a Rule definition
in a RuleGrammar . |
RuleCount | Attaches repeat counts to a contained RuleComponent object to
indicate the number of times it may occur. |
RuleLocale | Defines the SpeechLocale for the enclosed RuleComponent . |
RuleParse | Represents the parse structure of a Result or String against
a RuleGrammar . |
RuleReference | Specifies a reference to a RuleGrammar or a named Rule
in a RuleGrammar . |
RuleSequence | Specifies a RuleComponent composed of a sequence of
sub-RuleComponent s that must each be spoken in sequence order. |
RuleSpecial | Defines special RuleReference s defined as constants. |
RuleTag | Defines a tag to be used within a RuleGrammar . |
RuleToken | Represents speakable text in a RuleGrammar . |
SpeakerProfile | Identifies speaker data in a SpeakerManager . |
Exception Summary | |
---|---|
GrammarException | Thrown if a problem is found with grammar text from a resource or
with a RuleGrammar object derived from grammar text. |
ResultStateException | Thrown if there is an illegal call to a method of FinalResult or
FinalRuleResult . |
Provides interfaces and classes for using speech Recognizer
s.
The Recognizer
interface provides methods to interact
with speech recognition Engine
s.
The
Overview
provides more general information and includes a
Table of Examples
and a
Table of Diagrams.
Here is a "Hello World" example for recognition:
import javax.speech.*;
import javax.speech.recognition.*;
public class HelloWorld implements ResultListener {
static Recognizer rec;
public static void main(String[] args) {
try {
// Create a recognizer that supports the default speech locale.
rec = (Recognizer)
EngineManager.createEngine(RecognizerMode.DEFAULT);
// Start up the recognizer
rec.allocate();
// Load the grammar, and enable it
String grammarMarkup =
"<grammar root='sentence' xml:lang='en' version='1.0' " +
"xmlns='http://www.w3.org/2001/06/grammar'>" +
"<rule id='sentence' scope='public'>" +
"<one-of>" +
"<item> hello world </item>" +
"<item> good morning </item>" +
"<item> hello mighty computer </item>" +
"</one-of>" +
"</rule>" +
"</grammar>";
rec.getGrammarManager().loadGrammar("grammar:HelloWorld", null, grammarMarkup);
// Add the listener to get results
rec.addResultListener(new HelloWorld());
// Request focus and start listening
rec.requestFocus();
rec.resume();
// Would do other things here - wait for deallocate
rec.waitEngineState(Engine.DEALLOCATED);
}
catch (Exception e) {
e.printStackTrace();
}
}
// Receive RESULT_ACCEPTED event: print it, clean up
public void resultUpdate(ResultEvent event) {
if (event.getId() == ResultEvent.RESULT_ACCEPTED) {
try {
Result r = (Result) (event.getSource());
ResultToken tokens[] = r.getBestTokens();
for (int i = 0; i < tokens.length; i++)
System.out.print(tokens[i].getText() + " ");
System.out.println();
// For this example, deallocate the recognizer
rec.deallocate();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
Recognizer
|
JSAPI 2.0 | |||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
JavaTM Speech API 2.0,
Final Release v2.0.6.
© 2008, Conversay and Sun Microsystems.