edu.cmu.sphinx.tools.audio
Class Utils

java.lang.Object
  extended byedu.cmu.sphinx.tools.audio.Utils

public class Utils
extends java.lang.Object


Method Summary
static short bytesToShort(javax.sound.sampled.AudioFormat format, byte[] byteArray)
          Convert the bytes starting at the given offset to a signed short based upon the AudioFormat.
static AudioData readAudioFile(java.lang.String filename)
          Attempts to read an audio file using the Java Sound APIs.
static AudioData readRawFile(java.lang.String filename)
          Reads the given stream in as 16kHz 16-bit signed PCM big endian audio data and returns an audio clip.
static short toShort(byte[] bytes, boolean bigEndian)
          Converts a byte array to a signed short value.
static short[] toSignedPCM(javax.sound.sampled.AudioInputStream ais)
          Turns the AudioInputStream into a 16bit, SIGNED_PCM, big endian audio stream that preserves the original sample rate of the AudioInputStream.
static int toUnsignedShort(byte[] bytes, boolean bigEndian)
          Converts a byte array into an unsigned short.
static void writeRawFile(AudioData audio, java.lang.String filename)
          Writes the given 16kHz 16-bit signed PCM audio clip to the given file as raw big endian data.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toShort

public static short toShort(byte[] bytes,
                            boolean bigEndian)
Converts a byte array to a signed short value.


toUnsignedShort

public static int toUnsignedShort(byte[] bytes,
                                  boolean bigEndian)
Converts a byte array into an unsigned short.


bytesToShort

public static short bytesToShort(javax.sound.sampled.AudioFormat format,
                                 byte[] byteArray)
Convert the bytes starting at the given offset to a signed short based upon the AudioFormat. If the frame size is 1, then the value is doubled to make it match a frame size of 2.

Parameters:
format - the audio format
byteArray - the byte array
Returns:
a short
Throws:
java.lang.ArrayIndexOutOfBoundsException

toSignedPCM

public static short[] toSignedPCM(javax.sound.sampled.AudioInputStream ais)
                           throws java.io.IOException
Turns the AudioInputStream into a 16bit, SIGNED_PCM, big endian audio stream that preserves the original sample rate of the AudioInputStream. NOTE: this assumes the frame size can be only 1 or 2 bytes. The AudioInputStream is left in a state of having all of its data being read.

Throws:
java.io.IOException

readAudioFile

public static AudioData readAudioFile(java.lang.String filename)
                               throws java.io.IOException
Attempts to read an audio file using the Java Sound APIs. If this file isn't a typical audio file, then this returns a null. Otherwise, it converts the data into a 16kHz 16-bit signed PCM big endian clip.

Parameters:
filename - the file containing audio data
Returns:
the audio data or null if the audio cannot be parsed
Throws:
java.io.IOException

readRawFile

public static AudioData readRawFile(java.lang.String filename)
                             throws java.io.IOException
Reads the given stream in as 16kHz 16-bit signed PCM big endian audio data and returns an audio clip.

Parameters:
filename - the file containing audio data
Returns:
the audio data or null if the audio cannot be parsed
Throws:
java.io.IOException

writeRawFile

public static void writeRawFile(AudioData audio,
                                java.lang.String filename)
                         throws java.io.IOException
Writes the given 16kHz 16-bit signed PCM audio clip to the given file as raw big endian data.

Throws:
java.io.IOException