edu.cmu.sphinx.frontend.util
Class WavWriter

java.lang.Object
  extended by edu.cmu.sphinx.frontend.BaseDataProcessor
      extended by edu.cmu.sphinx.frontend.util.WavWriter
All Implemented Interfaces:
DataProcessor, Configurable

public class WavWriter
extends BaseDataProcessor

Stores audio data into numbered (MS-)wav files.

Author:
Holger Brandl

Field Summary
static java.lang.String PROP_BIG_ENDIAN_DATA
          The SphinxProperty specifying whether the input data is big-endian.
static java.lang.String PROP_BITS_PER_SAMPLE
          SphinxProperty for the number of bits per value.
static java.lang.String PROP_CAPTURE_UTTERANCES
          The SphinxProperty specifying whether the input data is signed.
static java.lang.String PROP_IS_COMPLETE_PATH
           
static java.lang.String PROP_OUT_FILE_NAME_PATTERN
          The pathname which must obey the pattern: pattern + i + .wav.
static java.lang.String PROP_SIGNED_DATA
          The SphinxProperty specifying whether the input data is signed.
 
Constructor Summary
WavWriter()
           
 
Method Summary
static javax.sound.sampled.AudioInputStream convertDoublesToAudioStream(double[] values, int sampleRate)
           
 Data getData()
          Returns the processed Data output.
 void initialize()
          Initializes this DataProcessor.
 void newProperties(PropertySheet ps)
          This method is called when this configurable component needs to be reconfigured.
static byte[] valuesToBytes(double[] values, int bytesPerValue, boolean signedData)
          Converts a big-endian byte array into an array of doubles.
static void writeWavFile(double[] signal, int sampleRate, java.io.File targetFile)
          Writes a given double array into a wav file (given the sample rate of the signal).
 
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_OUT_FILE_NAME_PATTERN

@S4String
public static final java.lang.String PROP_OUT_FILE_NAME_PATTERN
The pathname which must obey the pattern: pattern + i + .wav. Only the pattern is required here (e.g. wavdump/file). After each DataEndSignal the smalles unused 'i' is determined.

See Also:
Constant Field Values

PROP_IS_COMPLETE_PATH

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

PROP_BITS_PER_SAMPLE

@S4Integer(defaultValue=16)
public static final java.lang.String PROP_BITS_PER_SAMPLE
SphinxProperty for the number of bits per value.

See Also:
Constant Field Values

PROP_BIG_ENDIAN_DATA

@S4Boolean(defaultValue=true)
public static final java.lang.String PROP_BIG_ENDIAN_DATA
The SphinxProperty specifying whether the input data is big-endian.

See Also:
Constant Field Values

PROP_SIGNED_DATA

@S4Boolean(defaultValue=true)
public static final java.lang.String PROP_SIGNED_DATA
The SphinxProperty specifying whether the input data is signed.

See Also:
Constant Field Values

PROP_CAPTURE_UTTERANCES

@S4Boolean(defaultValue=false)
public static final java.lang.String PROP_CAPTURE_UTTERANCES
The SphinxProperty specifying whether the input data is signed.

See Also:
Constant Field Values
Constructor Detail

WavWriter

public WavWriter()
Method Detail

getData

public Data getData()
             throws DataProcessingException
Description copied from class: BaseDataProcessor
Returns the processed Data output.

Specified by:
getData in interface DataProcessor
Specified by:
getData in class BaseDataProcessor
Returns:
an Data object that has been processed by this DataProcessor
Throws:
DataProcessingException - if a data processor error occurs

initialize

public void initialize()
Initializes this DataProcessor. This is typically called after the DataProcessor has been configured.

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

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.

valuesToBytes

public static byte[] valuesToBytes(double[] values,
                                   int bytesPerValue,
                                   boolean signedData)
                            throws java.lang.ArrayIndexOutOfBoundsException
Converts a big-endian byte array into an array of doubles. Each consecutive bytes in the byte array are converted into a double, and becomes the next element in the double array. The size of the returned array is (length/bytesPerValue). Currently, only 1 byte (8-bit) or 2 bytes (16-bit) samples are supported.

Parameters:
bytesPerValue - the number of bytes per value
signedData - whether the data is signed
Returns:
a double array, or null if byteArray is of zero length
Throws:
java.lang.ArrayIndexOutOfBoundsException

convertDoublesToAudioStream

public static javax.sound.sampled.AudioInputStream convertDoublesToAudioStream(double[] values,
                                                                               int sampleRate)

writeWavFile

public static void writeWavFile(double[] signal,
                                int sampleRate,
                                java.io.File targetFile)
Writes a given double array into a wav file (given the sample rate of the signal).