org.jvoicexml.implementation.jsapi10
Class AudioOutput

java.lang.Object
  extended by org.jvoicexml.implementation.jsapi10.AudioOutput
All Implemented Interfaces:
ExternalResource, ObservableSystemOutput, RemoteConnectable, SystemOutput

public final class AudioOutput
extends Object
implements SystemOutput, ObservableSystemOutput

Audio output that uses the JSAPI 1.0 to address the TTS engine.

Handle all JSAPI calls to the TTS engine to make JSAPI transparent to the interpreter.

Version:
$Revision: 223 $

Copyright © 2005-2007 JVoiceXML group - http://jvoicexml.sourceforge.net/

Author:
Dirk Schnelle

Constructor Summary
AudioOutput(SynthesizerModeDesc defaultDescriptor)
          Constructs a new audio output.
 
Method Summary
 void activate()
          Activates this resource, when it is retrieved from the pool.
 void cancelOutput()
          Cancels the current output from the TTS engine and queued audio for all entries in the queue that allow bargein.
 void close()
          Closes and releases the acquired resources.
 void connect(RemoteClient client)
          Establishes a connection from the given RemoteClient to this object.
 String getType()
          Retrieves a unique identifier for this external resource.
 void open()
          Initializes and and acquires the needed resources.
 void passivate()
          Passivates this resource, when it is returned to the pool.
 void queueAudio(AudioInputStream audio)
          The audio, delivered by the audio stream is queued after the last element in the speaking queue.
 void queuePlaintext(String text)
          Speaks a plain text string.
 void queuePlaintextMessage(String text)
          Speaks a plain text string.
 void queueSpeakable(SpeakableText speakable, boolean bargein, DocumentServer documentServer)
          The Speakable object is added to the end of the speaking queue and will be spoken once it reaches the top of the queue. Checks the type of the given speakable and forwards it either as for SSML output or for plain text output.
 void reachedMark(String mark)
          A mark in an SSML output has been reached.
 void setSystemOutputListener(SystemOutputListener outputListener)
          Sets the listener for system output events.
 void setVoice(String name)
          Use the given voice for the synthesizer.
 void waitEngineState(long state)
          Blocks the calling thread until the Engine is in a specified state.
 void waitQueueEmpty()
          Convenient method to wait until all output is being played.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioOutput

public AudioOutput(SynthesizerModeDesc defaultDescriptor)
Constructs a new audio output.

Parameters:
defaultDescriptor - the default synthesizer mode descriptor.
Method Detail

open

public void open()
          throws NoresourceError
Initializes and and acquires the needed resources.

Specified by:
open in interface ExternalResource
Throws:
NoresourceError - The resource could not be opened.

close

public void close()
Closes and releases the acquired resources.

Specified by:
close in interface ExternalResource

setSystemOutputListener

public void setSystemOutputListener(SystemOutputListener outputListener)
Sets the listener for system output events.

The implementation of this interface must notify the listener about all events.

Specified by:
setSystemOutputListener in interface ObservableSystemOutput
Parameters:
outputListener - The listener.

queueSpeakable

public void queueSpeakable(SpeakableText speakable,
                           boolean bargein,
                           DocumentServer documentServer)
                    throws NoresourceError,
                           BadFetchError
The Speakable object is added to the end of the speaking queue and will be spoken once it reaches the top of the queue. Checks the type of the given speakable and forwards it either as for SSML output or for plain text output.

Specified by:
queueSpeakable in interface SystemOutput
Parameters:
speakable - Text to be spoken.
bargein - true if the output can be cancelled.
documentServer - The document server to use.
Throws:
NoresourceError - The output resource is not available.
BadFetchError - A URI within the speakable could not be obtained or a parsing error occured.

queuePlaintextMessage

public void queuePlaintextMessage(String text)
                           throws NoresourceError,
                                  BadFetchError
Speaks a plain text string. The text is not interpreted as containing the Java Speech Markup Language so JSML elements are ignored. The text is placed at the end of the speaking queue and will be spoken once it reaches the top of the queue and the synthesizer is in the RESUMED state. In other respects it is similar to the speak method that accepts a Speakable object.

The source of a SpeakableEvent issued to the SpeakableListener is the String object.

The speak methods operate as defined only when a Synthesizer is in the ALLOCATED state. The call blocks if the Synthesizer in the ALLOCATING_RESOURCES state and completes when the engine reaches the ALLOCATED state. An error is thrown for synthesizers in the DEALLOCATED or DEALLOCATING_RESOURCES states.

Parameters:
text - String contains plaing text to be spoken.
Throws:
NoresourceError - No recognizer allocated.
BadFetchError - Recognizer in wrong state.
Since:
0.6

queuePlaintext

public void queuePlaintext(String text)
                    throws NoresourceError,
                           BadFetchError
Speaks a plain text string.

Parameters:
text - String contains plain text to be spoken.
Throws:
NoresourceError - No recognizer allocated.
BadFetchError - Recognizer in wrong state.

queueAudio

public void queueAudio(AudioInputStream audio)
                throws NoresourceError,
                       BadFetchError
The audio, delivered by the audio stream is queued after the last element in the speaking queue.

If bargein can be used while queuing the audio depends on the surrounding <prompt>.

Specified by:
queueAudio in interface SystemOutput
Parameters:
audio - Stream with audio data.
Throws:
NoresourceError - The output resource is not available.
BadFetchError - Error reading from the AudioStream.

cancelOutput

public void cancelOutput()
                  throws NoresourceError
Cancels the current output from the TTS engine and queued audio for all entries in the queue that allow bargein.

The implementation has to maintain a list of cancellable outputs dependingon the bargein flag.

Specified by:
cancelOutput in interface SystemOutput
Throws:
NoresourceError - The output resource is not available.

waitEngineState

public void waitEngineState(long state)
                     throws InterruptedException
Blocks the calling thread until the Engine is in a specified state.

All state bits specified in the state parameter must be set in order for the method to return, as defined for the testEngineState method. If the state parameter defines an unreachable state (e.g. PAUSED | RESUMED) an exception is thrown.

The waitEngineState method can be called successfully in any Engine state.

Parameters:
state - State to wait for.
Throws:
InterruptedException - If another thread has interrupted this thread.

waitQueueEmpty

public void waitQueueEmpty()
Convenient method to wait until all output is being played.


setVoice

public void setVoice(String name)
              throws PropertyVetoException
Use the given voice for the synthesizer.

Parameters:
name - Name of the voice to use
Throws:
PropertyVetoException - Error in assigning the voice.

reachedMark

public void reachedMark(String mark)
A mark in an SSML output has been reached.

Parameters:
mark - Name of the mark.

activate

public void activate()
Activates this resource, when it is retrieved from the pool.

Specified by:
activate in interface ExternalResource
Specified by:
activate in interface SystemOutput

passivate

public void passivate()
Passivates this resource, when it is returned to the pool.

Specified by:
passivate in interface ExternalResource
Specified by:
passivate in interface SystemOutput

connect

public void connect(RemoteClient client)
             throws IOException
Establishes a connection from the given RemoteClient to this object.

Specified by:
connect in interface RemoteConnectable
Parameters:
client - data container with connection relevant data.
Throws:
IOException - error establishing the connection.
Stuff to complete
implement this method.

getType

public String getType()
Retrieves a unique identifier for this external resource.

Specified by:
getType in interface ExternalResource
Returns:
unique identifier.


Copyright © 2005-2007 JVoiceXML group.