JSAPI 2.0

javax.speech
Class SpeechLocale

Object
  extended by SpeechLocale

public final class SpeechLocale
extends Object

Encapsulates information that defines a locale and provides matching functionality to facilitate Engine selection and other local-sensitive operations.

The EngineMode class contains examples of Engine selection with SpeechLocale. As described in the match method, empty String values represent "don't care" during the selection process. A SpeechLocale associated with an Engine instance will contain non-empty String values for language and country.

This class is compatible with java.util.Locale.

See Also:
Engine, EngineMode, match

Constructor Summary
SpeechLocale(String language)
          Construct a SpeechLocale from the language.
SpeechLocale(String language, String country)
          Construct a SpeechLocale from the language and country.
SpeechLocale(String language, String country, String variant)
          Construct a SpeechLocale from the language, country, and variant.
 
Method Summary
 boolean equals(Object obj)
          Returns true if and only if the parameter is a non-null SpeechLocale with equal values for language, country and variant.
static SpeechLocale[] getAvailableLocales()
          Returns a list of SpeechLocales representing all installed locales for the Java Virtual Machine.
 String getCountry()
          Returns the country/region code for this SpeechLocale.
static SpeechLocale getDefault()
          Gets a SpeechLocale representing the current value of the default locale for this instance of the Java Virtual Machine.
 String getLanguage()
          Returns the language code for this SpeechLocale.
 String getVariant()
          Returns the variant String for this SpeechLocale.
 int hashCode()
          Returns a hash code value for this Object.
 boolean match(SpeechLocale require)
          Determines whether this SpeechLocale has all the same values for language, country, and variant as the require object.
 String toString()
          Returns a String representation of this SpeechLocale.
 
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpeechLocale

public SpeechLocale(String language)
             throws NullPointerException
Construct a SpeechLocale from the language.

The country and variant are assigned the empty String. The corresponding accessor methods describe details about the parameter values and possible conversions.

Parameters:
language - a String representing a language code
Throws:
NullPointerException - thrown if argument is null
See Also:
getLanguage, getCountry, getVariant

SpeechLocale

public SpeechLocale(String language,
                    String country)
             throws NullPointerException
Construct a SpeechLocale from the language and country.

The variant is assigned the empty String. The corresponding accessor methods describe details about the parameter values and possible conversions.

Parameters:
language - a String representing a language code
country - a String representing a country/region code
Throws:
NullPointerException - thrown if either argument is null
See Also:
getLanguage, getCountry, getVariant

SpeechLocale

public SpeechLocale(String language,
                    String country,
                    String variant)
             throws NullPointerException
Construct a SpeechLocale from the language, country, and variant.

The corresponding accessor methods describe details about the parameter values and possible conversions.

Parameters:
language - a String representing a language code
country - a String representing a country/region code
variant - a String representing additional vendor-specific information
Throws:
NullPointerException - thrown if any argument is null
See Also:
getLanguage, getCountry, getVariant
Method Detail

getCountry

public String getCountry()
Returns the country/region code for this SpeechLocale.

Country codes specified in the constructor should correspond to an uppercase ISO 3166 code or the empty String. If needed, specified values are converted to uppercase.

Because country values are converted, avoid direct String comparison and only compare values obtained through this method.

Returns:
the country/region code for this SpeechLocale.

getVariant

public String getVariant()
Returns the variant String for this SpeechLocale.

The variant specified in the constructor may be any String including the empty String.

Returns:
the variant String for this SpeechLocale.

getLanguage

public String getLanguage()
Returns the language code for this SpeechLocale.

Language codes specified in the constructor should correspond to a lowercase ISO 639 code or the empty String. If needed, specified values are converted to lowercase. For backward compatibility, the codes "he", "yi", and "id" are converted to the codes "iw", "ji", and "in", respectively.

Because language values are converted, avoid direct String comparison and only compare values obtained through this method.

Returns:
the language code for this SpeechLocale.

toString

public String toString()
Returns a String representation of this SpeechLocale.

This method follows the conventions of java.util.Locale. In particular, the language, country, and variant are separated by underbars. The variant is included only if the language and country are not the empty String. The language and country are lower and uppercase, respectively.

Overrides:
toString in class Object
Returns:
the String representation of this SpeechLocale

getAvailableLocales

public static SpeechLocale[] getAvailableLocales()
Returns a list of SpeechLocales representing all installed locales for the Java Virtual Machine. The getDefault method describes the use of SpeechLocales in Engine selection.

Returns:
a list of SpeechLocales
See Also:
getDefault

getDefault

public static SpeechLocale getDefault()
Gets a SpeechLocale representing the current value of the default locale for this instance of the Java Virtual Machine.

The EngineManager class describes the process of selecting a speech Engine using a SpeechLocale. Note that the SpeechLocale of an Engine selected with the DEFAULT for an EngineMode subclass may differ from the return value of this method. Furthermore, a speech Engine of the desired subclass corresponding to the returned SpeechLocale may not exist.

Returns:
a SpeechLocale representing the default locale for this JVM
See Also:
EngineManager, Engine, EngineMode

hashCode

public int hashCode()
Returns a hash code value for this Object. This method is supported for the benefit of hashtables.

Overrides:
hashCode in class Object
Returns:
a hash code value for this Object.

equals

public boolean equals(Object obj)
Returns true if and only if the parameter is a non-null SpeechLocale with equal values for language, country and variant.

Overrides:
equals in class Object
Parameters:
obj - an Object to compare
Returns:
true if obj equals this SpeechLocale
See Also:
getLanguage, getCountry, getVariant

match

public boolean match(SpeechLocale require)
Determines whether this SpeechLocale has all the same values for language, country, and variant as the require object. Empty String values in require are not tested ("don't care").

The accessor methods for language and country describe possible value conversions that apply before comparison. All String comparisons are exact (case-sensitive).

Parameters:
require - a SpeechLocale to compare
Returns:
true if this SpeechLocale has all the required values
See Also:
getLanguage, getCountry, getVariant

JSAPI 2.0

JavaTM Speech API 2.0, Final Release v2.0.6.
© 2008, Conversay and Sun Microsystems.

Free Web Hosting