edu.cmu.sphinx.frontend.util
Class AudioFileDataSource

java.lang.Object
  extended by edu.cmu.sphinx.frontend.BaseDataProcessor
      extended by edu.cmu.sphinx.frontend.util.AudioFileDataSource
All Implemented Interfaces:
DataProcessor, Configurable
Direct Known Subclasses:
ConcatAudioFileDataSource

public class AudioFileDataSource
extends BaseDataProcessor

An AudioFileDataSource generates a stream of audio data from a given audion file. All required information concerning the audio format are read directly from the file . One would need to call setAudioFile(java.io.File,String) to set the input file, and call getData() to obtain the Data frames.

Using JavaSound as backend this class is able to handle all sound files supported by JavaSound. Beside the built-in support for .wav, .au and .aiff. Using plugins (cf. http://www.jsresources.org/ ) it can be extended to support .ogg, .mp3, .speex and others.

Author:
Holger Brandl

Field Summary
static java.lang.String AUDIO_FILE_LISTENERS
           
static java.lang.String PROP_BYTES_PER_READ
          SphinxProperty for the number of bytes to read from the InputStream each time.
static int PROP_BYTES_PER_READ_DEFAULT
          Default value for PROP_BYTES_PER_READ.
 
Constructor Summary
AudioFileDataSource()
           
 
Method Summary
 void addNewFileListener(AudioFileProcessListener l)
          Adds a new listener for new file events.
 Data getData()
          Reads and returns the next Data from the InputStream of StreamDataSource, return null if no data is read and end of file is reached.
 int getSampleRate()
           
 void initialize()
          Initializes this DataProcessor.
 boolean isBigEndian()
           
 void newProperties(PropertySheet ps)
          This method is called when this configurable component needs to be reconfigured.
 void removeNewFileListener(AudioFileProcessListener l)
          Removes a listener for new file events.
 void setAudioFile(java.io.File audioFile, java.lang.String streamName)
          Sets the audio file from which the data-stream will be generated of.
 void setAudioFile(java.net.URL audioFileURL, java.lang.String streamName)
          Sets the audio file from which the data-stream will be generated of.
 void setInputStream(javax.sound.sampled.AudioInputStream inputStream, java.lang.String streamName)
          Sets the InputStream from which this StreamDataSource reads.
 
Methods inherited from class edu.cmu.sphinx.frontend.BaseDataProcessor
getPredecessor, getTimer, setPredecessor, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_BYTES_PER_READ

@S4Integer(defaultValue=3200)
public static final java.lang.String PROP_BYTES_PER_READ
SphinxProperty for the number of bytes to read from the InputStream each time.

See Also:
Constant Field Values

PROP_BYTES_PER_READ_DEFAULT

public static final int PROP_BYTES_PER_READ_DEFAULT
Default value for PROP_BYTES_PER_READ.

See Also:
Constant Field Values

AUDIO_FILE_LISTENERS

@S4ComponentList(type=Configurable.class)
public static final java.lang.String AUDIO_FILE_LISTENERS
See Also:
Constant Field Values
Constructor Detail

AudioFileDataSource

public AudioFileDataSource()
Method Detail

newProperties

public void newProperties(PropertySheet ps)
                   throws PropertyException
Description copied from interface: Configurable
This method is called when this configurable component needs to be reconfigured.

Specified by:
newProperties in interface Configurable
Overrides:
newProperties in class BaseDataProcessor
Parameters:
ps - a property sheet holding the new data
Throws:
PropertyException - if there is a problem with the properties.

initialize

public void initialize()
Description copied from class: BaseDataProcessor
Initializes this DataProcessor. This is typically called after the DataProcessor has been configured.

Specified by:
initialize in interface DataProcessor
Overrides:
initialize in class BaseDataProcessor

setAudioFile

public void setAudioFile(java.io.File audioFile,
                         java.lang.String streamName)
Sets the audio file from which the data-stream will be generated of.

Parameters:
audioFile - The location of the audio file to use
streamName - The name of the InputStream. if null the complete path of the audio file will be uses as stream name.

setAudioFile

public void setAudioFile(java.net.URL audioFileURL,
                         java.lang.String streamName)
Sets the audio file from which the data-stream will be generated of.

Parameters:
audioFileURL - The location of the audio file to use
streamName - The name of the InputStream. if null the complete path of the audio file will be uses as stream name.

setInputStream

public void setInputStream(javax.sound.sampled.AudioInputStream inputStream,
                           java.lang.String streamName)
Sets the InputStream from which this StreamDataSource reads.

Parameters:
inputStream - the InputStream from which audio data comes
streamName - the name of the InputStream

getData

public Data getData()
             throws DataProcessingException
Reads and returns the next Data from the InputStream of StreamDataSource, return null if no data is read and end of file is reached.

Specified by:
getData in interface DataProcessor
Specified by:
getData in class BaseDataProcessor
Returns:
the next Data or null if none is available
Throws:
DataProcessingException - if there is a data processing error

getSampleRate

public int getSampleRate()

isBigEndian

public boolean isBigEndian()

addNewFileListener

public void addNewFileListener(AudioFileProcessListener l)
Adds a new listener for new file events.


removeNewFileListener

public void removeNewFileListener(AudioFileProcessListener l)
Removes a listener for new file events.