Class BaseSynthesizer

java.lang.Object
com.sun.speech.engine.BaseEngine
com.sun.speech.engine.synthesis.BaseSynthesizer
All Implemented Interfaces:
SpeechEventDispatcher
Direct Known Subclasses:
FreeTTSSynthesizer, TextSynthesizer

public abstract class BaseSynthesizer extends BaseEngine implements SpeechEventDispatcher
Supports the JSAPI 1.0 Synthesizer interface that performs the core non-engine-specific functions.

An actual JSAPI synthesizer implementation needs to extend or modify this implementation.

  • Field Details

    • speakableListeners

      protected Collection speakableListeners
      Set of speakable listeners belonging to the Synthesizer. Each item on queue may have an individual listener too.
      See Also:
      • invalid reference
        SpeakableListener
    • voiceList

      protected VoiceList voiceList
      The set of voices available in this Synthesizer. The list can be created in the constructor methods.
  • Constructor Details

    • BaseSynthesizer

      public BaseSynthesizer(SynthesizerModeDesc mode)
      Creates a new Synthesizer in the DEALLOCATED state.
      Parameters:
      mode - the operating mode of this Synthesizer
  • Method Details

    • speak

      public void speak(Speakable jsmlText, SpeakableListener listener) throws JSMLException, EngineStateError
      Speaks JSML text provided as a Speakable object.
      Parameters:
      jsmlText - the JSML text to speak
      listener - the listener to be notified as the jsmlText is processed
    • speak

      public void speak(URL jsmlURL, SpeakableListener listener) throws JSMLException, MalformedURLException, IOException, EngineStateError
      Speaks JSML text provided as a URL.
      Parameters:
      jsmlURL - the URL containing JSML text
      listener - the listener to be notified as the JSML text is processed
    • speak

      public void speak(String jsmlText, SpeakableListener listener) throws JSMLException, EngineStateError
      Speaks JSML text provided as a String.
      Parameters:
      jsmlText - a String containing JSML.
      listener - the listener to be notified as the JSML text is processed
    • speakPlainText

      public void speakPlainText(String text, SpeakableListener listener) throws EngineStateError
      Speaks a plain text String. No JSML parsing is performed.
      Parameters:
      text - a String containing plain text.
      listener - the listener to be notified as the text is processed
    • stateToString

      protected String stateToString(long state)
      Returns a String of the names of all the states implied in the given bit pattern.
      Overrides:
      stateToString in class BaseEngine
      Parameters:
      state - the bit pattern of states
      Returns:
      a String of the names of all the states implied in the given bit pattern.
    • appendQueue

      protected abstract void appendQueue(BaseSynthesizerQueueItem item)
      Puts an item on the speaking queue and sends a queue updated event.
      Parameters:
      item - the item to add to the queue
    • phoneme

      public String phoneme(String text) throws EngineStateError
      Optional method that converts a text string to a phoneme string.
      Parameters:
      text - plain text to be converted to phonemes
      Returns:
      IPA phonemic representation of text or null
    • enumerateQueue

      public abstract Enumeration enumerateQueue() throws EngineStateError
      Returns an enumeration of the queue.
      Returns:
      an Enumeration of the speech output queue or null.
    • cancel

      public abstract void cancel() throws EngineStateError
      Cancels the item at the top of the queue.
    • cancel

      public abstract void cancel(Object source) throws IllegalArgumentException, EngineStateError
      Cancels a specific object on the queue.
      Parameters:
      source - object to be removed from the speech output queue
    • cancelAll

      public abstract void cancelAll() throws EngineStateError
      Cancels all items on the output queue.
    • getSynthesizerProperties

      public SynthesizerProperties getSynthesizerProperties()
      Returns the SynthesizerProperties object (a JavaBean). The method returns exactly the same object as the getEngineProperties method in the Engine interface. However, with the getSynthesizerProperties method, an application does not need to cast the return value.
      Returns:
      the SynthesizerProperties object for this Synthesizer
    • addSpeakableListener

      public void addSpeakableListener(SpeakableListener listener)
      Adds a SpeakableListener to this Synthesizer.
      Parameters:
      listener - the listener to add
      See Also:
    • removeSpeakableListener

      public void removeSpeakableListener(SpeakableListener listener)
      Removes a SpeakableListener from this Synthesizer.
      Parameters:
      listener - the listener to remove
      See Also:
    • createEngineProperties

      protected BaseEngineProperties createEngineProperties()
      Factory constructor for EngineProperties object. Gets the default speaking voice from the SynthesizerModeDesc. Takes the default prosody values (pitch, range, volume, rate) from the default voice. Override to set engine-specific defaults.
      Specified by:
      createEngineProperties in class BaseEngine
      Returns:
      a BaseEngineProperties object specific to a subclass.
    • createQueueItem

      protected BaseSynthesizerQueueItem createQueueItem()
      Factory method that creates a BaseSynthesizerQueueItem. Override if the synthesizer specializes the BaseSynthesizerQueueItem class.
    • getVoiceList

      protected VoiceList getVoiceList()
      Returns the list of voices for this Synthesizer.
      Returns:
      the list of voices for this Synthesizer.
    • postQueueUpdated

      public void postQueueUpdated(boolean topOfQueueChanged, long oldState, long newState)
      Utility function that generates QUEUE_UPDATED event and posts it to the event queue. Eventually fireQueueUpdated will be called by dispatchSpeechEvent as a result of this action.
      Parameters:
      topOfQueueChanged - true if the top of the queue has changed
      oldState - the old state of this Synthesizer
      newState - the new state of this Synthesizer
      See Also:
    • fireQueueUpdated

      public void fireQueueUpdated(SynthesizerEvent event)
      Utility function that sends a QUEUE_UPDATED event to all SynthesizerListeners.
      Parameters:
      event - the QUEUE_UPDATED event
      See Also:
    • postQueueEmptied

      public void postQueueEmptied(long oldState, long newState)
      Utility function that generates QUEUE_EMPTIED event and posts it to the event queue. Eventually fireQueueEmptied will be called by dispatchSpeechEvent as a result of this action.
      Parameters:
      oldState - the old state of this Synthesizer
      newState - the new state of this Synthesizer
      See Also:
    • fireQueueEmptied

      public void fireQueueEmptied(SynthesizerEvent event)
      Utility function that sends a QUEUE_EMPTIED event to all SynthesizerListeners.
      Parameters:
      event - the QUEUE_EMPTIED event
      See Also:
    • dispatchSpeechEvent

      public void dispatchSpeechEvent(SpeechEvent event)
      Dispatches a SpeechEvent. The dispatcher should notify all SynthesizerListeners from this method. The SpeechEvent was added via the various post methods of this class.
      Specified by:
      dispatchSpeechEvent in interface SpeechEventDispatcher
      Overrides:
      dispatchSpeechEvent in class BaseEngine
      Parameters:
      event - the SpeechEvent to dispatch
      See Also: