|
JSAPI 2.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectEngineManager
public class EngineManager
The initial access point to all speech
input and output capabilities.
The EngineManager
provides the ability to
locate, select and create speech Engine
instances.
createEngine
method creates speech Engine
s.
It accepts a single parameter that
defines the required features of the Engine
to create.
The parameter is a subclass of EngineMode
corresponding to a
subinterface of Engine
.
The createEngine
method operates differently
depending on the type of the EngineMode
subclass:
DEFAULT
for an EngineMode
subclass:
the EngineManager
selects a suitable Engine
with default values.
EngineMode
:
the EngineManager
attempts to locate an Engine
with all application-specified features.
EngineMode
selected from availableEngines
:
the EngineManager
creates an instance
of the specific Engine
identified by the EngineMode
.
These EngineMode
s implement the EngineFactory
interface.
// Create a Synthesizer for the default speech locale
Synthesizer synth = (Synthesizer)
EngineManager.createEngine(SynthesizerMode.DEFAULT);
// Create a Recognizer for British English
// Use the language and country codes for English spoken in Great Britain
RecognizerMode mode = new RecognizerMode(new SpeechLocale("en", "GB"));
Recognizer rec = (Recognizer) EngineManager.createEngine(mode);
// Obtain a list of all German recognizers
RecognizerMode mode = new RecognizerMode(new SpeechLocale("de"));
EngineList list = EngineManager.availableEngines(mode);
// Filter by other desired engine features
RecognizerMode chosen = ...
// Create a Recognizer from "chosen" -
// an EngineManager-provided EngineMode
Recognizer rec = (Recognizer) EngineManager.createEngine(chosen);
Engine
to create.
(For case 3, the application can apply its own selection procedure.)
SpeechLocale
is treated specially in the selection to ensure
that language is always considered when selecting an Engine
.
If a SpeechLocale
is not provided, the default SpeechLocale
(SpeechLocale.getDefault) is used.
The selection procedure is:
SpeechLocale
not specified, use the language of the
default SpeechLocale
in the required features.
Engine
has been started already and
it has the required features,
return a new corresponding Engine
instance
that shares the previously allocated underlying resources.
The running
feature is true
.
Depending on the implementation, underlying Engine
s
may be shared by multiple JVMs.
EngineMode
s that match
the required features.
Engine
s, give preference to:
running
Engine
(EngineMode.getRunning
is true
),
Engine
that matches the default SpeechLocale
's
country.
Engine
is a legal match in the final step,
the Engine
s are preference ordered as returned
by the availableEngines
method.
Engine
s is restricted.
This is to ensure that malicious applications do not use
Engine
s inappropriately.
For example, a Recognizer
should not be usable without
explicit permission because it could be used to monitor ("bug") an office.
A number of methods throughout the API throw SecurityException
.
Implementations of Engine
s may throw SecurityException
as
appropriate for the platform.
EngineManager
class locates, selects and creates
speech Engine
s from amongst a list of registered Engine
s.
Thus, for an Engine
to be used by Java applications,
the Engine
must register itself with EngineManager
.
There are two registration mechanisms:
EngineListFactory
class to
the speech.properties
resource,
Engine
by calling the
registerEngineListFactory
method.
speech.properties
resource provides
persistent registration of speech Engine
implementations.
When EngineManager
is first called, it reads the properties using
the following:
EngineManager.class.getResourceAsStream("speech.properties")
Specifically, getResourceAsStream
looks for
/javax/speech/speech.properties
as a resource.
Engine
s identified are made available through the methods of
EngineManager
.
The speech.properties
resource must contain data in the format
that is read by the load method of the Properties
class.
EngineManager
looks for properties of the form
com.acme.recognizer.EngineListFactory=com.acme.recognizer.AcmeEngineListFactory
This line is interpreted as "the EngineListFactory
object for the
com.acme.recognizer
Engine
is
the class called com.acme.recognizer.AcmeEngineListFactory
."
When it is first used, the EngineManager
class will attempt
to create an instance of each EngineListFactory
object and
will ensure that it implements the EngineListFactory
interface.
The speech.properties
resource may or may not be
implemented as a file.
The specific details depend on the platform and the implementation
of getResourceAsStream
.
If changes for these properties are permitted, it may be through a user
interface provided by the implementation rather than by direct
editing of the values.
RecognizerMode
,
SynthesizerMode
,
getResourceAsStream
,
EngineFactory
,
EngineListFactory
Method Summary | |
---|---|
static EngineList |
availableEngines(EngineMode required)
Lists available EngineMode objects
that match the required features. |
static Engine |
createEngine(EngineMode required)
Creates an Engine with specified required features. |
static String |
getVersion()
Returns the version of this API. |
static void |
registerEngineListFactory(String className)
Registers a speech Engine implementation with the
EngineManager for use by the current application. |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final EngineList availableEngines(EngineMode required)
EngineMode
objects
that match the required
features.
If the required
parameter is null
,
then all EngineMode
s for known Engine
s are listed.
Returns a zero-length list if no Engine
s are available or
if no Engine
s have the required
features.
This method never returns null.
The order of the EngineMode
objects in the list is
partially defined.
For each registered Engine
implementation
(technically, each registered EngineListFactory
object)
the order of the EngineMode
s is preserved.
Thus, each installed speech Engine
implementation should order
its EngineMode
objects with the most useful ones first.
For example, an EngineMode
that is already loaded and running.
required
- an EngineMode
defining the required features
or null
for all
EngineMode
s with the required featuresEngine
,
EngineMode
public static final Engine createEngine(EngineMode required) throws IllegalArgumentException, EngineException
Engine
with specified required
features.
If there is no Engine
with the required
features
then this method returns null
.
The required
features defined in the input parameter are
provided as an EngineMode
object.
Subinterfaces of Engine
provide examples of how to create
a particular kind of Engine
.
Subclasses of EngineMode
provide a DEFAULT
field
to select an Engine
that supports the language of the default
SpeechLocale
.
An EngineMode
may be either created by an application,
returned by the availableEngines
method,
or returned by an Engine
instance
with the getEngineMode
method.
The mechanisms for creating an Engine
are described
in the preamble.
required
- EngineMode
features that are required
Engine
matching the required
features or
null
if none is available
IllegalArgumentException
- if the EngineMode
is null
EngineException
- if the Engine
defined by the EngineMode
could not be properly createdavailableEngines
,
EngineMode
,
getEngineMode
public static String getVersion()
"2.0.6.0"
.
public static final void registerEngineListFactory(String className) throws IllegalArgumentException, SecurityException, EngineException
Engine
implementation with the
EngineManager
for use by the current application.
This method adds the specified className
to the list of
EngineListFactory
objects.
The registered Engine
implementation is not stored persistently
in speech.properties
.
If className
is already registered, this method has no effect.
The class identified by className
must have an empty constructor.
Note that not all devices support the dynamic class loading required by this method.
className
- name of a class that implements the
EngineListFactory
interface and provides access to
an Engine
implementation
IllegalArgumentException
- if className
is not a legal
class or does not implement the EngineListFactory
interface
EngineException
- if this implementation does not support
this method
SecurityException
- if this method is not allowed by
the calling applicationEngineListFactory
javax.speech.EngineManager.registerEngineListFactory
|
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.