org.jvoicexml.implementation.jsapi10
Class Jsapi10SynthesizedOutput

java.lang.Object
  extended by org.jvoicexml.implementation.jsapi10.Jsapi10SynthesizedOutput
All Implemented Interfaces:
EventListener, SpeakableListener, ExternalResource, StreamableSynthesizedOutput, ObservableSynthesizedOutput, OutputDevice, SynthesizedOutput, RemoteConnectable

public final class Jsapi10SynthesizedOutput
extends Object
implements SynthesizedOutput, ObservableSynthesizedOutput, SpeakableListener, StreamableSynthesizedOutput

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.

The queued SpeakableTexts are maintained in a list. Once a speakable has ended (this is detected via the speakableEnded(SpeakableEvent) method) this implementation processes the next SpeakableText from the queue.

SSML is supported via SSMLSpeakStrategys.

This implementation offers 2 ways to overcome the lack in JSAPI 1.0 not to be able to stream audio data.

  1. use custom streaming via SpokenInputConnectionHandler and
  2. direct streaming via StreamableSynthesizedOutput.

Note that these ways are not fully tested and might be changed towards the JSAPI 2 way.

Version:
$Revision: 2830 $
Author:
Dirk Schnelle-Walka

Constructor Summary
Jsapi10SynthesizedOutput(SynthesizerModeDesc defaultDescriptor)
          Constructs a new audio output.
 
Method Summary
 void activate()
          
 void addListener(SynthesizedOutputListener outputListener)
          
 void addSynthesizerStream(InputStream input)
          Reads from the given output stream and adds the result to the list of streams.
 void cancelOutput()
          
 void close()
          
 void connect(ConnectionInformation connectionInformation)
          
 void disconnect(ConnectionInformation connectionInformation)
          
 DocumentServer getDocumentServer()
          Retrieves the document server.
 String getSessionid()
          Retrieves the Id of the current session.
 Synthesizer getSynthesizer()
          Retrieves the encapsulated synthesizer.
 String getType()
          
 URI getUriForNextSynthesisizedOutput()
          
 boolean isBusy()
          
 boolean isOutputCanceled()
          Checks if there was a request to cancel the current output.
 void markerReached(SpeakableEvent event)
          
 void open()
          
 void passivate()
          
 void queueSpeakable(SpeakableText speakable, String id, DocumentServer server)
           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.
 int readSynthesizerStream(byte[] buffer, int offset, int length)
          Reads up to length bytes of data from the synthesizer stream into the given buffer.
 void removeListener(SynthesizedOutputListener outputListener)
          
 void setSynthesizedOutputConnectionHandler(SynthesizedOutputConnectionHandler connectionHandler)
          Sets a custom connection handler.
 void setType(String resourceType)
          Sets the type of this resource.
 void speakableCancelled(SpeakableEvent event)
          
 void speakableEnded(SpeakableEvent event)
          
 void speakablePaused(SpeakableEvent event)
          
 void speakableResumed(SpeakableEvent event)
          
 void speakableStarted(SpeakableEvent event)
          
 void speakPlaintext(String text)
          Speaks a plain text string.
 boolean supportsBargeIn()
          
 void topOfQueue(SpeakableEvent event)
          
 void waitEngineState(long state)
          Blocks the calling thread until the Engine is in a specified state.
 void waitNonBargeInPlayed()
          
 void waitQueueEmpty()
          
 void wordStarted(SpeakableEvent event)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jsapi10SynthesizedOutput

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

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

open

public void open()
          throws NoresourceError

Specified by:
open in interface ExternalResource
Throws:
NoresourceError

close

public void close()

Specified by:
close in interface ExternalResource

getSynthesizer

public Synthesizer getSynthesizer()
Retrieves the encapsulated synthesizer.

Returns:
the encapsulated synthesizer.
Since:
0.6

getDocumentServer

public DocumentServer getDocumentServer()
Retrieves the document server.

Returns:
the document server
Since:
0.7.5

getSessionid

public String getSessionid()
Retrieves the Id of the current session.

Returns:
the Id of the current session
Since:
0.7.5

addListener

public void addListener(SynthesizedOutputListener outputListener)

Specified by:
addListener in interface ObservableSynthesizedOutput

removeListener

public void removeListener(SynthesizedOutputListener outputListener)

Specified by:
removeListener in interface ObservableSynthesizedOutput

queueSpeakable

public void queueSpeakable(SpeakableText speakable,
                           String id,
                           DocumentServer server)
                    throws NoresourceError,
                           BadFetchError
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 SynthesizedOutput
Throws:
NoresourceError
BadFetchError

speakPlaintext

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

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

supportsBargeIn

public boolean supportsBargeIn()

Specified by:
supportsBargeIn in interface OutputDevice

cancelOutput

public void cancelOutput()
                  throws NoresourceError

Specified by:
cancelOutput in interface OutputDevice
Throws:
NoresourceError

isOutputCanceled

public boolean isOutputCanceled()
Checks if there was a request to cancel the current output.

Returns:
true if there was a request to cancel the current output.
Since:
0.7.3

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.

waitNonBargeInPlayed

public void waitNonBargeInPlayed()

Specified by:
waitNonBargeInPlayed in interface SynthesizedOutput

waitQueueEmpty

public void waitQueueEmpty()

Specified by:
waitQueueEmpty in interface SynthesizedOutput

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()

Specified by:
activate in interface ExternalResource

passivate

public void passivate()

Specified by:
passivate in interface ExternalResource

connect

public void connect(ConnectionInformation connectionInformation)
             throws IOException

Specified by:
connect in interface RemoteConnectable
Throws:
IOException

disconnect

public void disconnect(ConnectionInformation connectionInformation)

Specified by:
disconnect in interface RemoteConnectable

getType

public String getType()

Specified by:
getType in interface ExternalResource

setType

public void setType(String resourceType)
Sets the type of this resource.

Parameters:
resourceType - type of the resource

setSynthesizedOutputConnectionHandler

public void setSynthesizedOutputConnectionHandler(SynthesizedOutputConnectionHandler connectionHandler)
Sets a custom connection handler.

Parameters:
connectionHandler - the connection handler.

getUriForNextSynthesisizedOutput

public URI getUriForNextSynthesisizedOutput()
                                     throws NoresourceError

Specified by:
getUriForNextSynthesisizedOutput in interface SynthesizedOutput
Throws:
NoresourceError

markerReached

public void markerReached(SpeakableEvent event)

Specified by:
markerReached in interface SpeakableListener

speakableCancelled

public void speakableCancelled(SpeakableEvent event)

Specified by:
speakableCancelled in interface SpeakableListener

speakableEnded

public void speakableEnded(SpeakableEvent event)

Specified by:
speakableEnded in interface SpeakableListener

speakablePaused

public void speakablePaused(SpeakableEvent event)

Specified by:
speakablePaused in interface SpeakableListener

speakableResumed

public void speakableResumed(SpeakableEvent event)

Specified by:
speakableResumed in interface SpeakableListener

speakableStarted

public void speakableStarted(SpeakableEvent event)

Specified by:
speakableStarted in interface SpeakableListener

topOfQueue

public void topOfQueue(SpeakableEvent event)

Specified by:
topOfQueue in interface SpeakableListener

wordStarted

public void wordStarted(SpeakableEvent event)

Specified by:
wordStarted in interface SpeakableListener

isBusy

public boolean isBusy()

Specified by:
isBusy in interface ExternalResource
Specified by:
isBusy in interface OutputDevice

readSynthesizerStream

public int readSynthesizerStream(byte[] buffer,
                                 int offset,
                                 int length)
                          throws IOException
Reads up to length bytes of data from the synthesizer stream into the given buffer.

Specified by:
readSynthesizerStream in interface StreamableSynthesizedOutput
Parameters:
buffer - the buffer into which the data is read.
offset - the start offset in array buffer at which the data is written.
length - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - Error reading from the stream..

addSynthesizerStream

public void addSynthesizerStream(InputStream input)
                          throws IOException
Reads from the given output stream and adds the result to the list of streams.

Parameters:
input - stream to read from.
Throws:
IOException - Error reading from the given stream.


Copyright © 2005-2009JVoiceXML group.