Class Utterance

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

public class Utterance extends Object implements FeatureSet, 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:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new, empty utterance.
    Utterance(Voice voice, List tokenList)
    Creates an utterance with the given set of tokenized text.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new relation with the given name and adds it to this utterance.
    void
    dump(PrintWriter output, int pad, String title)
    Dumps this utterance in textual form.
    void
    dump(PrintWriter output, int pad, String title, boolean justRelations)
    Dumps this utterance in textual form.
    void
    dump(PrintWriter output, String title)
    Dumps this utterance in textual form.
    void
    dump(String title)
    Dumps this utterance in textual form.
    void
    Dumps the utterance in textual form
    float
    Returns the duration of this Utterance in seconds.
    float
    Convenience method that returns the named feature as a float.
    int
    getInt(String name)
    Convenience method that returns the named feature as a int.
    getItem(String relation, float time)
    Returns the Item in the given Relation associated with the given time.
    Returns the named feature as an object.
    Retrieves a relation from this utterance.
    Returns the queueitem associated with this utterance.
    Convenience method that returns the named feature as a string.
    Retrieves the Voice associated with this Utterance.
    boolean
    Determines if this utterance contains a relation with the given name.
    boolean
    Returns true if this utterance is the first is a series of utterances.
    boolean
    Returns true if this utterance is the last is a series of utterances.
    boolean
    Determines if the given feature is present.
    void
    remove(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(String name, float value)
    Convenience method that sets the named feature as a float.
    void
    setInt(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(String name, Object value)
    Sets the named feature.
    void
    Sets the speakable item for this utterance.
    void
    setString(String name, 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 Details

    • Utterance

      public Utterance(Voice voice)
      Creates a new, empty utterance.
      Parameters:
      voice - the voice associated with the utterance
    • Utterance

      public Utterance(Voice voice, 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 Details

    • 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(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(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(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(PrintWriter output, int pad, 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(PrintWriter output, int pad, String title)
      Dumps this utterance in textual form.
      Specified by:
      dump in interface Dumpable
      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(PrintWriter output, 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(String title)
      Dumps this utterance in textual form.
      Parameters:
      title - the title to print when dumping out the utterance
    • dumpRelations

      public void dumpRelations(String title)
      Dumps the utterance in textual form
      Parameters:
      title - the title to print when dumping out the utterance
    • isPresent

      public boolean isPresent(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(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 String getString(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:
      ClassCastException - if the associated value is not a String
    • getInt

      public int getInt(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:
      ClassCastException - if the associated value is not an int
    • getFloat

      public float getFloat(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:
      ClassCastException - if the associated value is not a float
    • getObject

      public Object getObject(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(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(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(String name, 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(String name, 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(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:
      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