edu.cmu.sphinx.frontend.util
Class Microphone

java.lang.Object
  extended byedu.cmu.sphinx.frontend.BaseDataProcessor
      extended byedu.cmu.sphinx.frontend.util.Microphone
All Implemented Interfaces:
Configurable, DataProcessor

public class Microphone
extends BaseDataProcessor

A Microphone captures audio data from the system's underlying audio input systems. Converts these audio data into Data objects. When the method startRecording() is called, a new thread will be created and used to capture audio, and will stop when stopRecording() is called. Calling getData() returns the captured audio data as Data objects.

This Microphone will attempt to obtain an audio device with the format specified in the configuration. If such a device with that format cannot be obtained, it will try to obtain a device with an audio format that has a higher sample rate than the configured sample rate, while the other parameters of the format (i.e., sample size, endianness, sign, and channel) remain the same. If, again, no such device can be obtained, it flags an error, and a call startRecording returns false.


Field Summary
static java.lang.String PROP_BIG_ENDIAN
          Property specify the endianness of the data.
static boolean PROP_BIG_ENDIAN_DEFAULT
          Default value for PROP_BIG_ENDIAN.
static java.lang.String PROP_BITS_PER_SAMPLE
          SphinxProperty for the number of bits per value.
static int PROP_BITS_PER_SAMPLE_DEFAULT
          Default value for PROP_BITS_PER_SAMPLE.
static java.lang.String PROP_CHANNELS
          Property specifying the number of channels.
static int PROP_CHANNELS_DEFAULT
          Default value for PROP_CHANNELS.
static java.lang.String PROP_CLOSE_BETWEEN_UTTERANCES
          Sphinx property that specifies whether or not the microphone will release the audio between utterances.
static boolean PROP_CLOSE_BETWEEN_UTTERANCES_DEFAULT
          Default value for PROP_CLOSE_BETWEEN_UTTERANCES.
static java.lang.String PROP_KEEP_LAST_AUDIO
          The Sphinx property that specifies whether to keep the audio data of an utterance around until the next utterance is recorded.
static boolean PROP_KEEP_LAST_AUDIO_DEFAULT
          The default value of PROP_KEEP_AUDIO.
static java.lang.String PROP_MSEC_PER_READ
          The Sphinx property that specifies the number of milliseconds of audio data to read each time from the underlying Java Sound audio device.
static int PROP_MSEC_PER_READ_DEFAULT
          The default value of PROP_MSEC_PER_READ.
static java.lang.String PROP_SAMPLE_RATE
          SphinxProperty for the sample rate of the data.
static int PROP_SAMPLE_RATE_DEFAULT
          Default value for PROP_SAMPLE_RATE.
static java.lang.String PROP_SELECT_CHANNEL
          The Sphinx property that specifies the channel to use if the audio is stereo
static int PROP_SELECT_CHANNEL_DEFAULT
          The default value of PROP_SELECT_CHANNEL.
static java.lang.String PROP_SELECT_MIXER
          The Sphinx property that specifies the mixer to use.
static java.lang.String PROP_SELECT_MIXER_DEFAULT
          The default value of PROP_SELECT_MIXER.
static java.lang.String PROP_SIGNED
          Property specify whether the data is signed.
static boolean PROP_SIGNED_DEFAULT
          Default value for PROP_SIGNED.
static java.lang.String PROP_STEREO_TO_MONO
          The Sphinx property that specifies how to convert stereo audio to mono.
static java.lang.String PROP_STEREO_TO_MONO_DEFAULT
          The default value of PROP_STEREO_TO_MONO.
 
Constructor Summary
Microphone()
           
 
Method Summary
 void clear()
          Clears all cached audio data.
 javax.sound.sampled.AudioFormat getAudioFormat()
          Returns the format of the audio recorded by this Microphone.
 Data getData()
          Reads and returns the next Data object from this Microphone, return null if there is no more audio data.
 Utterance getUtterance()
          Returns the current Utterance.
 boolean hasMoreData()
          Returns true if there is more data in the Microphone.
 void initialize()
          Constructs a Microphone with the given InputStream.
 boolean isRecording()
          Returns true if this Microphone is recording.
 void newProperties(PropertySheet ps)
          This method is called when this configurable component has new data.
 void register(java.lang.String name, Registry registry)
          Register my properties.
 boolean startRecording()
          Starts recording audio.
 void stopRecording()
          Stops recording audio.
 
Methods inherited from class edu.cmu.sphinx.frontend.BaseDataProcessor
getName, getPredecessor, getTimer, setPredecessor, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_SAMPLE_RATE

public static final java.lang.String PROP_SAMPLE_RATE
SphinxProperty for the sample rate of the data.

See Also:
Constant Field Values

PROP_SAMPLE_RATE_DEFAULT

public static final int PROP_SAMPLE_RATE_DEFAULT
Default value for PROP_SAMPLE_RATE.

See Also:
Constant Field Values

PROP_CLOSE_BETWEEN_UTTERANCES

public static final java.lang.String PROP_CLOSE_BETWEEN_UTTERANCES
Sphinx property that specifies whether or not the microphone will release the audio between utterances. On certain systems (linux for one), closing and reopening the audio does not work too well. The default is false for Linux systems, true for others.

See Also:
Constant Field Values

PROP_CLOSE_BETWEEN_UTTERANCES_DEFAULT

public static final boolean PROP_CLOSE_BETWEEN_UTTERANCES_DEFAULT
Default value for PROP_CLOSE_BETWEEN_UTTERANCES.

See Also:
Constant Field Values

PROP_MSEC_PER_READ

public static final java.lang.String PROP_MSEC_PER_READ
The Sphinx property that specifies the number of milliseconds of audio data to read each time from the underlying Java Sound audio device.

See Also:
Constant Field Values

PROP_MSEC_PER_READ_DEFAULT

public static final int PROP_MSEC_PER_READ_DEFAULT
The default value of PROP_MSEC_PER_READ.

See Also:
Constant Field Values

PROP_BITS_PER_SAMPLE

public static final java.lang.String PROP_BITS_PER_SAMPLE
SphinxProperty for the number of bits per value.

See Also:
Constant Field Values

PROP_BITS_PER_SAMPLE_DEFAULT

public static final int PROP_BITS_PER_SAMPLE_DEFAULT
Default value for PROP_BITS_PER_SAMPLE.

See Also:
Constant Field Values

PROP_CHANNELS

public static final java.lang.String PROP_CHANNELS
Property specifying the number of channels.

See Also:
Constant Field Values

PROP_CHANNELS_DEFAULT

public static final int PROP_CHANNELS_DEFAULT
Default value for PROP_CHANNELS.

See Also:
Constant Field Values

PROP_BIG_ENDIAN

public static final java.lang.String PROP_BIG_ENDIAN
Property specify the endianness of the data.

See Also:
Constant Field Values

PROP_BIG_ENDIAN_DEFAULT

public static final boolean PROP_BIG_ENDIAN_DEFAULT
Default value for PROP_BIG_ENDIAN.

See Also:
Constant Field Values

PROP_SIGNED

public static final java.lang.String PROP_SIGNED
Property specify whether the data is signed.

See Also:
Constant Field Values

PROP_SIGNED_DEFAULT

public static final boolean PROP_SIGNED_DEFAULT
Default value for PROP_SIGNED.

See Also:
Constant Field Values

PROP_KEEP_LAST_AUDIO

public static final java.lang.String PROP_KEEP_LAST_AUDIO
The Sphinx property that specifies whether to keep the audio data of an utterance around until the next utterance is recorded.

See Also:
Constant Field Values

PROP_KEEP_LAST_AUDIO_DEFAULT

public static final boolean PROP_KEEP_LAST_AUDIO_DEFAULT
The default value of PROP_KEEP_AUDIO.

See Also:
Constant Field Values

PROP_STEREO_TO_MONO

public static final java.lang.String PROP_STEREO_TO_MONO
The Sphinx property that specifies how to convert stereo audio to mono. Currently, the possible values are "average", which averages the samples from at each channel, or "selectChannel", which chooses audio only from that channel. If you choose "selectChannel", you should also specify which channel to use with the "selectChannel" property.

See Also:
Constant Field Values

PROP_STEREO_TO_MONO_DEFAULT

public static final java.lang.String PROP_STEREO_TO_MONO_DEFAULT
The default value of PROP_STEREO_TO_MONO.

See Also:
Constant Field Values

PROP_SELECT_CHANNEL

public static final java.lang.String PROP_SELECT_CHANNEL
The Sphinx property that specifies the channel to use if the audio is stereo

See Also:
Constant Field Values

PROP_SELECT_CHANNEL_DEFAULT

public static final int PROP_SELECT_CHANNEL_DEFAULT
The default value of PROP_SELECT_CHANNEL.

See Also:
Constant Field Values

PROP_SELECT_MIXER

public static final java.lang.String PROP_SELECT_MIXER
The Sphinx property that specifies the mixer to use. The value can be "default," (which means let the AudioSystem decide), "last," (which means select the last Mixer supported by the AudioSystem), which appears to be what is often used for USB headsets, or an integer value which represents the index of the Mixer.Info that is returned by AudioSystem.getMixerInfo(). To get the list of Mixer.Info objects, run the AudioTool application with a command line argument of "-dumpMixers".

See Also:
AudioTool, Constant Field Values

PROP_SELECT_MIXER_DEFAULT

public static final java.lang.String PROP_SELECT_MIXER_DEFAULT
The default value of PROP_SELECT_MIXER. This means that a specific Mixer will not be used. Instead, the AudioSystem will be used to choose the audio line to use.

See Also:
Constant Field Values
Constructor Detail

Microphone

public Microphone()
Method Detail

register

public void register(java.lang.String name,
                     Registry registry)
              throws PropertyException
Description copied from interface: Configurable
Register my properties. This method is called once early in the time of the component, shortly after the component is constructed. This component should register any configuration properties that it needs to register. If this configurable extends another configurable, super.register should also be called

Specified by:
register in interface Configurable
Overrides:
register in class BaseDataProcessor
Throws:
PropertyException

newProperties

public void newProperties(PropertySheet ps)
                   throws PropertyException
Description copied from interface: Configurable
This method is called when this configurable component has new data. The component should first validate the data. If it is bad the component should return false. If the data is good, the component should record the the data internally and return true.

Specified by:
newProperties in interface Configurable
Overrides:
newProperties in class BaseDataProcessor
Throws:
PropertyException

initialize

public void initialize()
Constructs a Microphone with the given InputStream.

Specified by:
initialize in interface DataProcessor
Overrides:
initialize in class BaseDataProcessor
Throws:
java.io.IOException - if an I/O error occurs

getAudioFormat

public javax.sound.sampled.AudioFormat getAudioFormat()
Returns the format of the audio recorded by this Microphone. Note that this might be different from the configured format.

Returns:
the current AudioFormat

getUtterance

public Utterance getUtterance()
Returns the current Utterance.

Returns:
the current Utterance

isRecording

public boolean isRecording()
Returns true if this Microphone is recording.

Returns:
true if this Microphone is recording, false otherwise

startRecording

public boolean startRecording()
Starts recording audio. This method will return only when a START event is received, meaning that this Microphone has started capturing audio.

Returns:
true if the recording started successfully; false otherwise

stopRecording

public void stopRecording()
Stops recording audio. This method does not return until recording has been stopped and all data has been read from the audio line.


clear

public void clear()
Clears all cached audio data.


getData

public Data getData()
             throws DataProcessingException
Reads and returns the next Data object from this Microphone, return null if there is no more audio data. All audio data captured in-between startRecording() and stopRecording() is cached in an Utterance object. Calling this method basically returns the next chunk of audio data cached in this Utterance.

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

hasMoreData

public boolean hasMoreData()
Returns true if there is more data in the Microphone. This happens either if getRecording() return true, or if the buffer in the Microphone has a size larger than zero.

Returns:
true if there is more data in the Microphone