JSAPI 2.0

javax.speech.synthesis
Class Voice

Object
  extended by Voice

public class Voice
extends Object

Describes one output Voice of a speech Synthesizer.

Voice objects can be used in selection of synthesis engines through SynthesizerMode. From the SynthesizerProperties object (returned for a Synthesizer with the getSynthesizerProperties method), the current speaking Voice of a Synthesizer can be retrieved using the getVoice method and can be changed during operation with the setVoice method.

See Also:
Synthesizer, SynthesizerMode, getSynthesizerProperties, SynthesizerProperties, getVoice, setVoice

Field Summary
static int AGE_CHILD
          Constant representing the Voice of a child.
static int AGE_DONT_CARE
          Constant that will match with any age.
static int AGE_MIDDLE_ADULT
          Constant representing the Voice of a middle-aged adult.
static int AGE_OLDER_ADULT
          Constant representing the Voice of an older adult.
static int AGE_SPECIFIC
          Constant flag to limit an age value to a single value.
static int AGE_TEENAGER
          Constant representing the Voice of a teenager.
static int AGE_YOUNGER_ADULT
          Constant representing the Voice of a younger adult.
static int GENDER_DONT_CARE
          Ignore gender when performing a match of Voices.
static int GENDER_FEMALE
          Female Voice.
static int GENDER_MALE
          Male Voice.
static int GENDER_NEUTRAL
          Neutral Voice that is neither male or female.
static int VARIANT_DEFAULT
          The default variant for a Voice.
static int VARIANT_DONT_CARE
          Ignore the variant when performing a match of Voices.
 
Constructor Summary
Voice()
          Constructs a Voice with locale, name, gender, age, and variant set to "don't care" values.
Voice(SpeechLocale locale, String name, int gender, int age, int variant)
          Constructs a Voice with locale, name, gender, age, and variant.
 
Method Summary
 boolean equals(Object obj)
          Returns true if and only if the parameter is not null and is a Voice with equal values.
 int getAge()
          Gets the Voice age.
 int getGender()
          Gets the Voice gender.
 String getName()
          Gets the Voice name.
 SpeechLocale getSpeechLocale()
          Gets the Voice SpeechLocale.
 int getVariant()
          Gets the Voice variant.
 int hashCode()
          Returns a hash code value for the object.
 boolean match(Voice require)
          Determines whether this Voice has all the features defined in the require object.
 String toString()
          Returns a String representation of this Voice.
 
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

GENDER_DONT_CARE

public static final int GENDER_DONT_CARE
Ignore gender when performing a match of Voices. Synthesizers never provide a Voice with GENDER_DONT_CARE.

See Also:
match, getGender(), Constant Field Values

GENDER_FEMALE

public static final int GENDER_FEMALE
Female Voice.

See Also:
getGender, Constant Field Values

GENDER_MALE

public static final int GENDER_MALE
Male Voice.

See Also:
getGender, Constant Field Values

GENDER_NEUTRAL

public static final int GENDER_NEUTRAL
Neutral Voice that is neither male or female. Examples include artificial voices and robotic voices.

See Also:
getGender, Constant Field Values

AGE_DONT_CARE

public static final int AGE_DONT_CARE
Constant that will match with any age. Synthesizers never return a Voice with AGE_DONT_CARE.

See Also:
match, getAge, Constant Field Values

AGE_CHILD

public static final int AGE_CHILD
Constant representing the Voice of a child.

This value will match ages in the range of 0-12.

See Also:
match, getAge(), Constant Field Values

AGE_TEENAGER

public static final int AGE_TEENAGER
Constant representing the Voice of a teenager.

This value will match ages in the range of 13-19.

See Also:
match, getAge(), Constant Field Values

AGE_YOUNGER_ADULT

public static final int AGE_YOUNGER_ADULT
Constant representing the Voice of a younger adult.

This value will match ages in the range of 20-39.

See Also:
match, getAge(), Constant Field Values

AGE_MIDDLE_ADULT

public static final int AGE_MIDDLE_ADULT
Constant representing the Voice of a middle-aged adult.

This value will match ages in the range of 40-59.

See Also:
match, getAge(), Constant Field Values

AGE_OLDER_ADULT

public static final int AGE_OLDER_ADULT
Constant representing the Voice of an older adult.

This value will match ages starting from 60.

See Also:
match, getAge(), Constant Field Values

AGE_SPECIFIC

public static final int AGE_SPECIFIC
Constant flag to limit an age value to a single value.

An age value without this flag indicates a preferred age.

See Also:
match, getAge(), Constant Field Values

VARIANT_DONT_CARE

public static final int VARIANT_DONT_CARE
Ignore the variant when performing a match of Voices.

Synthesizers never provide a Voice with VARIANT_DONT_CARE. Variants returned from a Synthesizer begin with VARIANT_DEFAULT.

See Also:
match, getVariant, VARIANT_DEFAULT, Constant Field Values

VARIANT_DEFAULT

public static final int VARIANT_DEFAULT
The default variant for a Voice. Variants returned from a Synthesizer begin with VARIANT_DEFAULT.

See Also:
getVariant, Constant Field Values
Constructor Detail

Voice

public Voice()
Constructs a Voice with locale, name, gender, age, and variant set to "don't care" values.

See Also:
Voice(SpeechLocale, String, int, int, int)

Voice

public Voice(SpeechLocale locale,
             String name,
             int gender,
             int age,
             int variant)
      throws IllegalArgumentException
Constructs a Voice with locale, name, gender, age, and variant.

The getGender method describes valid gender values. The getAge method describes valid age values. The variant must be a positive integer or VARIANT_DONT_CARE.

Parameters:
locale - SpeechLocale of the Voice
name - name of the Voice
gender - gender of the Voice
age - age of the Voice
variant - variant of the Voice
Throws:
IllegalArgumentException - if an invalid parameter value is supplied
See Also:
getSpeechLocale, getName, getGender, getAge, getVariant, Voice()
Method Detail

equals

public boolean equals(Object obj)
Returns true if and only if the parameter is not null and is a Voice with equal values.

Overrides:
equals in class Object
Parameters:
obj - a Voice object to compare
Returns:
true if the Voice objects compare

getAge

public int getAge()
Gets the Voice age.

A Voice from a Synthesizer instance returns one of the age range constants or an age value limited to a specific value with the AGE_SPECIFIC flag.

A Voice created programmatically may return one of the following:

In all cases, an age value is a non-negative integer representing an age in years. The maximum value of age is Short.MAX_VALUE. An age value may not be combined with age range constants, but may be combined with the AGE_SPECIFIC flag.

Returns:
the preferred age, a specific age, or age ranges of the Voice
See Also:
match, AGE_DONT_CARE, AGE_CHILD, AGE_TEENAGER, AGE_YOUNGER_ADULT, AGE_MIDDLE_ADULT, AGE_OLDER_ADULT, AGE_SPECIFIC

getGender

public int getGender()
Gets the Voice gender.

Gender values may be OR'ed to select or match a Voice.

A Voice from a Synthesizer instance returns a specific gender constant.

Returns:
the gender of this voice
See Also:
match, GENDER_DONT_CARE, GENDER_MALE, GENDER_FEMALE, GENDER_NEUTRAL

getVariant

public int getVariant()
Gets the Voice variant. This can indicate a variation between otherwise identical Voice characteristics. For example, if there are two male child voices then the variant can be used to select the second one.

If the variant does not matter during Voice selection, use VARIANT_DONT_CARE. This value will match any other variant value.

A Voice from a Synthesizer instance returns a specific positive integer. Variant values begin with VARIANT_DEFAULT.

Returns:
the Voice variant
See Also:
match, VARIANT_DEFAULT, VARIANT_DONT_CARE

getName

public String getName()
Gets the Voice name. May return null.

A null or "" String in Voice match means don't care.

Returns:
the name of this voice
See Also:
match

hashCode

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

Overrides:
hashCode in class Object
Returns:
a hash code value for the object

getSpeechLocale

public SpeechLocale getSpeechLocale()
Gets the Voice SpeechLocale. The SpeechLocale includes the language, country, and variant (for the language).

May return null. A null for Voice match means don't care.

Returns:
the SpeechLocale for this Voice
See Also:
match

match

public boolean match(Voice require)
Determines whether this Voice has all the features defined in the require object. Strings in require which are null are ignored. All String comparisons are exact matches (case-sensitive). A null SpeechLocale in the require object is ignored. Otherwise, all non-null Strings in the require SpeechLocale must match.

GENDER_DONT_CARE, AGE_DONT_CARE, and VARIANT_DONT_CARE values in the require object are ignored.

Gender constant values may be OR'ed in the require object to match. The getGender method lists the gender constants.

The age value of the require object may be

The getAge method lists the age range constants.

Variant values in the require object other than VARIANT_DONT_CARE must be equal to match.

The following example shows how to test for a male and/or neutral Voice:

 Voice aVoice = ...;
 Voice maleishVoice =
     new Voice(null, null, Voice.GENDER_MALE | Voice.GENDER_NEUTRAL,
               Voice.AGE_DONT_CARE, Voice.VARIANT_DONT_CARE);
 if (aVoice.match(maleishVoice)) ...
 

Parameters:
require - the required features to match this Voice
Returns:
true if all the required features match
See Also:
GENDER_DONT_CARE, AGE_DONT_CARE, AGE_SPECIFIC, VARIANT_DONT_CARE, getGender, getAge, getVariant

toString

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

Overrides:
toString in class Object
Returns:
a String representation of this Voice

JSAPI 2.0

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

Free Web Hosting