com.sun.speech.freetts
Class Utterance

java.lang.Object
  extended bycom.sun.speech.freetts.Utterance
All Implemented Interfaces:
Dumpable, FeatureSet, java.io.Serializable

public class Utterance
extends java.lang.Object
implements FeatureSet, java.io.Serializable

Holds all the data for an utterance to be spoken. It is incrementally modified by various UtteranceProcessor implementations. An utterance contains a set of Features (essential a set of properties) and a set of Relations. A Relation is an ordered set of Item graphs. The utterance contains a set of features and implements FeatureSet so that applications can set/get features directly from the utterance. If a feature query is not found in the utterance feature set, the query is forwarded to the FeatureSet of the voice associated with the utterance.

See Also:
Serialized Form

Constructor Summary
Utterance(Voice voice)
          Creates a new, empty utterance.
Utterance(Voice voice, java.util.List tokenList)
          Creates an utterance with the given set of tokenized text.
 
Method Summary
 Relation createRelation(java.lang.String name)
          Creates a new relation with the given name and adds it to this utterance.
 void dump(java.io.PrintWriter output, int pad, java.lang.String title)
          Dumps this utterance in textual form.
 void dump(java.io.PrintWriter output, int pad, java.lang.String title, boolean justRelations)
          Dumps this utterance in textual form.
 void dump(java.io.PrintWriter output, java.lang.String title)
          Dumps this utterance in textual form.
 void dump(java.lang.String title)
          Dumps this utterance in textual form.
 void dumpRelations(java.lang.String title)
          Dumps the utterance in textual form
 float getDuration()
          Returns the duration of this Utterance in seconds.
 float getFloat(java.lang.String name)
          Convenience method that returns the named feature as a float.
 int getInt(java.lang.String name)
          Convenience method that returns the named feature as a int.
 Item getItem(java.lang.String relation, float time)
          Returns the Item in the given Relation associated with the given time.
 java.lang.Object getObject(java.lang.String name)
          Returns the named feature as an object.
 Relation getRelation(java.lang.String name)
          Retrieves a relation from this utterance.
 FreeTTSSpeakable getSpeakable()
          Returns the queueitem associated with this utterance.
 java.lang.String getString(java.lang.String name)
          Convenience method that returns the named feature as a string.
 Voice getVoice()
          Retrieves the Voice associated with this Utterance.
 boolean hasRelation(java.lang.String name)
          Determines if this utterance contains a relation with the given name.
 boolean isFirst()
          Returns true if this utterance is the first is a series of utterances.
 boolean isLast()
          Returns true if this utterance is the last is a series of utterances.
 boolean isPresent(java.lang.String name)
          Determines if the given feature is present.
 void remove(java.lang.String name)
          Removes the named feature from this set of features.
 void setFirst(boolean first)
          Sets this utterance as the first in a series.
 void setFloat(java.lang.String name, float value)
          Convenience method that sets the named feature as a float.
 void setInt(java.lang.String name, int value)
          Convenience method that sets the named feature as an int.
 void setLast(boolean last)
          Sets this utterance as the last in a series.
 void setObject(java.lang.String name, java.lang.Object value)
          Sets the named feature.
 void setSpeakable(FreeTTSSpeakable speakable)
          Sets the speakable item for this utterance.
 void setString(java.lang.String name, java.lang.String value)
          Convenience method that sets the named feature as a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utterance

public Utterance(Voice voice)
Creates a new, empty utterance.

Parameters:
voice - the voice associated with the utterance

Utterance

public Utterance(Voice voice,
                 java.util.List tokenList)
Creates an utterance with the given set of tokenized text.

Parameters:
voice - the voice associated with the utterance
tokenList - the list of tokens for this utterance
Method Detail

setSpeakable

public void setSpeakable(FreeTTSSpeakable speakable)
Sets the speakable item for this utterance.

Parameters:
speakable - the speakable item for this utterance

getSpeakable

public FreeTTSSpeakable getSpeakable()
Returns the queueitem associated with this utterance.

Returns:
the queue item

createRelation

public Relation createRelation(java.lang.String name)
Creates a new relation with the given name and adds it to this utterance.

Parameters:
name - the name of the new relation
Returns:
the newly created relation

getRelation

public Relation getRelation(java.lang.String name)
Retrieves a relation from this utterance.

Parameters:
name - the name of the Relation
Returns:
the relation or null if the relation is not found

hasRelation

public boolean hasRelation(java.lang.String name)
Determines if this utterance contains a relation with the given name.

Parameters:
name - the name of the relation of interest.

getVoice

public Voice getVoice()
Retrieves the Voice associated with this Utterance.

Returns:
the voice associated with this utterance.

dump

public void dump(java.io.PrintWriter output,
                 int pad,
                 java.lang.String title,
                 boolean justRelations)
Dumps this utterance in textual form.

Parameters:
output - where to send the formatted output
pad - the initial padding
title - the title to print when dumping out the utterance
justRelations - if true don't print voice features

dump

public void dump(java.io.PrintWriter output,
                 int pad,
                 java.lang.String title)
Dumps this utterance in textual form.

Specified by:
dump in interface FeatureSet
Parameters:
output - where to send the formatted output
pad - the initial padding
title - the title to print when dumping out the utterance

dump

public void dump(java.io.PrintWriter output,
                 java.lang.String title)
Dumps this utterance in textual form.

Parameters:
output - where to send the formatted output
title - the title to print when dumping out the utterance

dump

public void dump(java.lang.String title)
Dumps this utterance in textual form.

Parameters:
title - the title to print when dumping out the utterance

dumpRelations

public void dumpRelations(java.lang.String title)
Dumps the utterance in textual form

Parameters:
title - the title to print when dumping out the utterance

isPresent

public boolean isPresent(java.lang.String name)
Determines if the given feature is present. If the feature is not present in the utterance, the feature set of the voice is checked.

Specified by:
isPresent in interface FeatureSet
Parameters:
name - the name of the feature of interest
Returns:
true if the named feature is present

remove

public void remove(java.lang.String name)
Removes the named feature from this set of features.

Specified by:
remove in interface FeatureSet
Parameters:
name - the name of the feature of interest

getString

public java.lang.String getString(java.lang.String name)
Convenience method that returns the named feature as a string. If the named feature is not present in the utterance, then this attempts to retrieve it from the voice.

Specified by:
getString in interface FeatureSet
Parameters:
name - the name of the feature
Returns:
the value associated with the name or null if the value is not found
Throws:
java.lang.ClassCastException - if theassociated value is not a String

getInt

public int getInt(java.lang.String name)
Convenience method that returns the named feature as a int. If the named feature is not present in the utterance, then this attempts to retrieve it from the voice.

Specified by:
getInt in interface FeatureSet
Parameters:
name - the name of the feature
Returns:
the value associated with the name or null if the value is not found
Throws:
java.lang.ClassCastException - if the associated value is not an int

getFloat

public float getFloat(java.lang.String name)
Convenience method that returns the named feature as a float. If the named feature is not present in the utterance, then this attempts to retrieve it from the voice.

Specified by:
getFloat in interface FeatureSet
Parameters:
name - the name of the feature
Returns:
the value associated with the name or null if the value is not found
Throws:
java.lang.ClassCastException - if the associated value is not a float

getObject

public java.lang.Object getObject(java.lang.String name)
Returns the named feature as an object. If the named feature is not present in the utterance, then this attempts to retrieve it from the voice.

Specified by:
getObject in interface FeatureSet
Parameters:
name - the name of the feature
Returns:
the value associated with the name or null if the value is not found

setInt

public void setInt(java.lang.String name,
                   int value)
Convenience method that sets the named feature as an int.

Specified by:
setInt in interface FeatureSet
Parameters:
name - the name of the feature
value - the value of the feature

setFloat

public void setFloat(java.lang.String name,
                     float value)
Convenience method that sets the named feature as a float.

Specified by:
setFloat in interface FeatureSet
Parameters:
name - the name of the feature
value - the value of the feature

setString

public void setString(java.lang.String name,
                      java.lang.String value)
Convenience method that sets the named feature as a String.

Specified by:
setString in interface FeatureSet
Parameters:
name - the name of the feature
value - the value of the feature

setObject

public void setObject(java.lang.String name,
                      java.lang.Object value)
Sets the named feature.

Specified by:
setObject in interface FeatureSet
Parameters:
name - the name of the feature
value - the value of the feature

getItem

public Item getItem(java.lang.String relation,
                    float time)
Returns the Item in the given Relation associated with the given time.

Parameters:
relation - the name of the relation
time - the time
Throws:
java.lang.IllegalStateException - if the Segment durations have not been calculated in the Utterance or if the given relation is not present in the Utterance

getDuration

public float getDuration()
Returns the duration of this Utterance in seconds. It does this by looking at last Item in the following Relations, in this order: Segment, Target. If none of these Relations exist, or if these Relations contain no Items, an IllegalStateException will be thrown.

Returns:
the duration of this Utterance in seconds

isFirst

public boolean isFirst()
Returns true if this utterance is the first is a series of utterances.

Returns:
true if this is the first utterance in a series of connected utterances.

setFirst

public void setFirst(boolean first)
Sets this utterance as the first in a series.

Parameters:
first - if true, the item is the first in a series

isLast

public boolean isLast()
Returns true if this utterance is the last is a series of utterances.

Returns:
true if this is the last utterance in a series of connected utterances.

setLast

public void setLast(boolean last)
Sets this utterance as the last in a series.

Parameters:
last - if true, the item is the last in a series