inpro.audio
Class DispatchStream

java.lang.Object
  extended by java.io.InputStream
      extended by inpro.audio.DispatchStream
All Implemented Interfaces:
edu.cmu.sphinx.util.props.Configurable, java.io.Closeable

public class DispatchStream
extends java.io.InputStream
implements edu.cmu.sphinx.util.props.Configurable

WARNING: there ARE threading issues with this class TODO: would it be nice to directly output SysInstallmentIUs? --> yes, indeed.

Author:
timo

Field Summary
private  boolean inShutdown
           
(package private)  boolean isInterrupted
          a flag to interrupt output; used by read() to determine whether it should send silence or data
private static org.apache.log4j.Logger logger
           
static java.lang.String PROP_SEND_SILENCE
           
static java.lang.String PROP_SPEECH_STATE_VISUALIZER
           
private  boolean sendSilence
           
(package private)  SpeechStateVisualizer ssv
           
(package private)  java.io.InputStream stream
           
(package private)  java.util.Queue<java.io.InputStream> streamQueue
           
private static java.util.Map<java.lang.String,java.lang.String> ttsCache
          A map of tts strings and corresponding audio files.
 
Constructor Summary
DispatchStream()
           
 
Method Summary
protected  void addStream(java.io.InputStream is)
           
 void clearStream()
           
 void continuePlayback()
           
 void initialize()
           
static void initializeTTSCache(java.lang.String utteranceMapFile, java.lang.String audioPath)
          Reads file names corresponding to utterances strings from a file and adds them to a local map if they can be found.
 boolean inShutdown()
          whether this dispatchStream has been requested to shut down
 void interruptPlayback()
           
 boolean isSpeaking()
           
 void newProperties(edu.cmu.sphinx.util.props.PropertySheet ps)
           
private  void nextStream()
           
 void playFile(java.lang.String filename, boolean skipQueue)
          play audio from file
 void playSilence(int ms, boolean skipQueue)
           
 void playStream(java.io.InputStream audioStream)
           
 void playStream(java.io.InputStream audioStream, boolean skipQueue)
           
 void playTTS(java.lang.String tts, boolean skipQueue)
           
 int read()
           
 int read(byte[] b, int off, int len)
           
 void sendSilence(boolean b)
          determines whether digital zeroes are sent during silence, or whether the stream just stalls
protected  void setIsSilent()
           
protected  void setIsTalking()
           
protected  void setStream(java.io.InputStream is)
           
 void shutdown()
          waits for the current stream to finish and shuts down the dispatcher
 void waitUntilDone()
           
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.log4j.Logger logger

PROP_SPEECH_STATE_VISUALIZER

@S4Component(type=SpeechStateVisualizer.class,
             mandatory=false)
public static final java.lang.String PROP_SPEECH_STATE_VISUALIZER
See Also:
Constant Field Values

ssv

SpeechStateVisualizer ssv

PROP_SEND_SILENCE

@S4Boolean(defaultValue=false)
public static final java.lang.String PROP_SEND_SILENCE
See Also:
Constant Field Values

sendSilence

private boolean sendSilence

ttsCache

private static java.util.Map<java.lang.String,java.lang.String> ttsCache
A map of tts strings and corresponding audio files.


stream

java.io.InputStream stream

streamQueue

java.util.Queue<java.io.InputStream> streamQueue

isInterrupted

boolean isInterrupted
a flag to interrupt output; used by read() to determine whether it should send silence or data


inShutdown

private boolean inShutdown
Constructor Detail

DispatchStream

public DispatchStream()
Method Detail

newProperties

public void newProperties(edu.cmu.sphinx.util.props.PropertySheet ps)
                   throws edu.cmu.sphinx.util.props.PropertyException
Specified by:
newProperties in interface edu.cmu.sphinx.util.props.Configurable
Throws:
edu.cmu.sphinx.util.props.PropertyException

initialize

public void initialize()

isSpeaking

public boolean isSpeaking()

initializeTTSCache

public static void initializeTTSCache(java.lang.String utteranceMapFile,
                                      java.lang.String audioPath)
Reads file names corresponding to utterances strings from a file and adds them to a local map if they can be found.


sendSilence

public void sendSilence(boolean b)
determines whether digital zeroes are sent during silence, or whether the stream just stalls


setIsTalking

protected void setIsTalking()

setIsSilent

protected void setIsSilent()

playFile

public void playFile(java.lang.String filename,
                     boolean skipQueue)
play audio from file

Parameters:
filename - path to the file to be played
skipQueue - determines whether the file should be played immediately (skipQueue==true) or be enqueued to be played after all other messages have been played

playTTS

public void playTTS(java.lang.String tts,
                    boolean skipQueue)

playSilence

public void playSilence(int ms,
                        boolean skipQueue)

playStream

public void playStream(java.io.InputStream audioStream)

playStream

public void playStream(java.io.InputStream audioStream,
                       boolean skipQueue)

addStream

protected void addStream(java.io.InputStream is)

clearStream

public void clearStream()

setStream

protected void setStream(java.io.InputStream is)

interruptPlayback

public void interruptPlayback()

continuePlayback

public void continuePlayback()

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

nextStream

private void nextStream()

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

inShutdown

public boolean inShutdown()
whether this dispatchStream has been requested to shut down


shutdown

public void shutdown()
waits for the current stream to finish and shuts down the dispatcher


waitUntilDone

public void waitUntilDone()