|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.cloudgarden.speech.CGAudioManager
In addition to the functions offered by the javax.speech.AudioManager class, this class provides several methods for redirecting audio input/output. It allows the input to a Recognizer to come from an AudioSource, and Synthesizer output to be sent to an AudioSink.
The setSource method ensures that input to the recognizer comes always from a single well-defined source at any time. Likewise, the setSink method defines a single AudioSink to receive output from a Synthesizer.
The getDataSource and getDataSink methods provide JMF DataSource and DataSink objects.
| Fields inherited from interface com.cloudgarden.audio.AudioObject |
END_OF_DATA |
| Method Summary | |
void |
addAudioListener(AudioListener listener)
|
void |
addTransferListener(TransferListener listener)
Adds a TransferListener to receive notification when data is passed to or from this AudioObject |
void |
bytesTransferred(byte[] data,
int offset,
int numBytes,
int direction)
|
boolean |
canSetAudioFormat()
Used to test whether the AudioFormat of the Synthesizer or Recognizer can be set using the setAudioFormat method. |
void |
closeInput()
Closes the input stream - and allows the CGAudioManager.drain() method (as well as the drain method of any sinks/sources connected to it) to exit. |
void |
closeOutput()
Closes the output stream - causes the read method to return END_OF_DATA when the current synthesized speech has finished. |
void |
closeOutputFile()
Closes the wave audio file opened in a preceding setOutputFile call. |
void |
drain()
Blocks until END_OF_DATA is written to or read from this AudioObject. |
javax.sound.sampled.AudioFormat |
getAudioFormat()
Used to obtain the AudioFormat of the Synthesizer or Recognizer from which this CGAudioManager was obtained. |
java.lang.String |
getContentType()
|
javax.media.DataSink |
getDataSink()
Returns a javax.media.DataSink object which allows audio data to be sent to a Recognizer using the JMF. |
javax.media.protocol.DataSource |
getDataSource()
Returns a javax.media.protocol.DataSource object which allows audio data from a Synthesizer to be manipulated using the JMF. |
AudioSink |
getSink()
Returns the AudioSink set using setSink |
AudioSource |
getSource()
Returns the AudioSource set by setSource |
boolean |
isAudioDeviceValid()
|
boolean |
isPaused()
|
boolean |
isSending()
Returns true if the thread started by the startSending method is still writing data to the AudioSink. |
boolean |
isWaiting()
Returns true if no data has yet been written or read from this AudioObject |
int |
read(byte[] data,
int len)
Convenience method - should call read(data, 0, len) |
int |
read(byte[] data,
int offset,
int len)
Used to read data from this source - called by the AudioSink which this source is connected to (if its startGetting method is used) so need not be called explicitly by an application. |
void |
removeAudioListener(AudioListener listener)
|
void |
removeTransferListener(TransferListener listener)
|
void |
setAudioFormat(javax.sound.sampled.AudioFormat format)
Sets the AudioFormat for this AudioObject. |
void |
setBufferSize(int size)
|
void |
setContentType(java.lang.String contentType)
Does nothing, since the content type is fixed at RAW |
void |
setDefaultInput()
Sets the input to a Recognizer to come from the default input device (usually the microphone on the local machine). |
void |
setDefaultOutput()
Redirects output to the default output. |
void |
setInputFile(java.lang.String fileName)
Deprecated. Use either the setSource or getDataSink method |
void |
setOutputFile(java.lang.String fileName,
int freq,
int bits)
Deprecated. Use either the setSink or getDataSource method |
void |
setPaused(boolean paused)
If paused is true, writing or reading data to or from this AudioObject will block until setPaused(false) is called. |
void |
setSink(AudioSink sink)
Sets the sink for this source - this method should also call the setSource method on the sink object (making sure to avaoid an endless loop) to ensure that source and sink are connected to each other (and not to different sinks/sources). |
void |
setSource(AudioSource source)
Sets the source for this sink - this method should also call the setSink method on the source object (while avoiding an endless loop) to ensure that sink and source are connected to each other (and not to different sinks/sources). |
void |
startSending()
This method should start a thread which repeatedly writes data to the AudioSink object which this object is connected to, until it writes data with length END_OF_DATA, or until the stopSending method is called. |
void |
stopSending()
|
int |
write(byte[] data,
int len)
Convenience method - should call write(data, 0, len) |
int |
write(byte[] data,
int offset,
int len)
Used to write data to this sink - called by the AudioSource which this sink is connected to (if its startSending method is used) so need not be called explicitly by an application. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public void addAudioListener(AudioListener listener)
addAudioListener in interface AudioManagerpublic void removeAudioListener(AudioListener listener)
removeAudioListener in interface AudioManagerpublic void addTransferListener(TransferListener listener)
AudioObjectaddTransferListener in interface AudioObjectpublic void removeTransferListener(TransferListener listener)
removeTransferListener in interface AudioObjectcom.cloudgarden.audio.AudioObjectaddTransferListener
public void bytesTransferred(byte[] data,
int offset,
int numBytes,
int direction)
public javax.sound.sampled.AudioFormat getAudioFormat()
getAudioFormat in interface AudioObjectpublic boolean canSetAudioFormat()
canSetAudioFormat in interface AudioObject
public void setAudioFormat(javax.sound.sampled.AudioFormat format)
throws java.io.IOException
AudioObjectThis ensures that the AudioFormat is uniform along a set of connected AudioObjects until the format is changed by an AudioConverter.
setAudioFormat in interface AudioObjectcom.cloudgarden.audio.AudioObjectjava.io.IOException - if unable to set the AudioFormat for any reason
(eg. if canSetAudioFormat returns false and setAudioFormat is used
to try to change the AudioFormat).AudioObject.getAudioFormat()public boolean isAudioDeviceValid()
public void setPaused(boolean paused)
AudioObjectsetPaused in interface AudioObject
public void setInputFile(java.lang.String fileName)
throws AudioException,
EngineException,
EngineStateError,
java.io.IOException
public void setDefaultInput()
public void closeInput()
public void setOutputFile(java.lang.String fileName,
int freq,
int bits)
throws AudioException,
EngineException,
EngineStateError,
java.io.IOException
Allows the Synthesizer's output to be saved directly to a wave audio file. This method can be called at any time after the Synthesizer has been allocated. The closeOutputFile method should be called after the speech has finished. In this way speech may be piped to one file then another. The file name must end in .wav or .wave, the "bits" parameter must equal 8 or 16 and the "frequency" must equal 11 or 22 (kHz).
Note: Setting output to a file using this method changes the behaviour of the Synthesizer's "speak" methods from the "normal" case when speech is output asynchronously to an audio device.
After output has been set to a file using this method, the "speek" methods will write speech synchronously to the file, and no SpeechEvents will be sent during or after writing speech to the file. Restoring output to the audio device will cause the "speek" methods to execute asynchronously again.
To reset audio output to the default audio device (usually the speakers), this method should be called with a null fileName parameter.
This method operates as defined only when a Synthesizer is in the ALLOCATED state. The call blocks if the Synthesizer in the ALLOCATING_RESOURCES state and completes when the engine reaches the ALLOCATED state. An error is thrown for synthesizers in the DEALLOCATED or DEALLOCATING_RESOURCES states.
fileName - file name to save audio to - must end in ".wav" or ".wave"bits - audio resolution - 8 or 16 bitsfrequency - audio frequency in kHz - must be 11 or 22AudioException - if either bits or frequency or fileName is invalid.EngineException - if not called on a Synthesizer objectEngineStateError - if called for a synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES statesjava.io.IOException - if the operation failed in any way when trying to open the output file.closeOutputFile()
public void closeOutputFile()
throws EngineException,
java.io.IOException
EngineException - if not called on a Synthesizer objectEngineStateError - if called for a synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES statesjava.io.IOException - if the operation failed in any way when trying to close the output file.setOutputFile(String, int, int)
public void setDefaultOutput()
throws AudioException,
EngineException,
EngineStateError,
java.io.IOException
public void closeOutput()
public javax.media.DataSink getDataSink()
throws EngineException,
java.io.IOException
The Recognizer can use only a single AudioSource or a single DataSink at any one time, and so a call to the getDataSink method overrides any previous call to the getDataSink or setSource methods.
This method should only be called after a Recognizer has been allocated but before the Recognizer.requestFocus method is called - see the examples.recognition.DictationFromMPEGFile sample code.
Once the DataSink is finished being used, closeInput() should be called.
EngineException - if not called on a Recognizer object
public javax.media.protocol.DataSource getDataSource()
throws EngineException,
java.io.IOException
The Synthesizer can use only a single AudioSink or a single DataSource at any one time, and so a call to the getDataSource method overrides any previous call to the getDataSource or setSink methods.
Once the DataSource is finished being used, closeOutput() should be called.
EngineException - if not called on a Synthesizer object
public void setSink(AudioSink sink)
throws java.io.IOException
AudioSourceIf the sink's AudioFormat is null or the sink's format differs from this AudioSource's format, then the sink's format is set equal to that of this AudioSource.
If the sink's AudioFormat is not null and this AudioSource's format is null then this AudioSource's format is set equal to the sink's.
The same is done for the ContentType as described above for the AudioFormat.
Note: if the sink is an AudioConverter then the get/setIncomingAudioFormat method is called instead of get/setAudioFormat.
setSink in interface AudioSourcecom.cloudgarden.audio.AudioSourceAudioSource.getSink()public boolean isSending()
AudioSourceisSending in interface AudioSourcecom.cloudgarden.audio.AudioSourceAudioSource.startSending()
public void setSource(AudioSource source)
throws java.io.IOException
AudioSinkIf the source's AudioFormat is null or the source's format differs from this AudioSink's format, then the source's format is set equal to that of this AudioSink.
If the source's AudioFormat is not null and this AudioSink's format is null then this AudioSink's format is set equal to the source's.
The same is done for the ContentType as described above for the AudioFormat.
setSource in interface AudioSinkcom.cloudgarden.audio.AudioSinkAudioSink.getSource()
public int read(byte[] data,
int len)
throws java.io.IOException
AudioSourceread in interface AudioSource
public int read(byte[] data,
int offset,
int len)
throws java.io.IOException
AudioSourceread in interface AudioSourcecom.cloudgarden.audio.AudioSourceAudioSource.setSink(com.cloudgarden.audio.AudioSink),
AudioSink#startGetting,
AudioObject.setPaused(boolean)
public int write(byte[] data,
int len)
throws java.io.IOException
AudioSinkwrite in interface AudioSink
public int write(byte[] data,
int offset,
int len)
throws java.io.IOException
AudioSinkwrite in interface AudioSinkcom.cloudgarden.audio.AudioSinkAudioSink.setSource(com.cloudgarden.audio.AudioSource),
AudioSource.startSending(),
AudioObject.setPaused(boolean)public void setBufferSize(int size)
public void startSending()
throws java.io.IOException
AudioSourcestartSending in interface AudioSourcecom.cloudgarden.audio.AudioSourcean - IOException if the source is unable to start sending data - for example,
if an audio file is unable to be opened to supply the data to be sent.AudioSource.setSink(com.cloudgarden.audio.AudioSink),
AudioObject.drain()public void stopSending()
stopSending in interface AudioSourcecom.cloudgarden.audio.AudioSourceAudioSource.startSending()
public void drain()
throws java.io.IOException
AudioObjectdrain in interface AudioObjectpublic boolean isWaiting()
AudioObjectisWaiting in interface AudioObjectpublic AudioSource getSource()
AudioSinkgetSource in interface AudioSinkcom.cloudgarden.audio.AudioSinkAudioSink.setSource(com.cloudgarden.audio.AudioSource)public AudioSink getSink()
AudioSourcegetSink in interface AudioSourcecom.cloudgarden.audio.AudioSourceAudioSource.setSink(com.cloudgarden.audio.AudioSink)public boolean isPaused()
isPaused in interface AudioObjectpublic java.lang.String getContentType()
getContentType in interface AudioObjectcom.cloudgarden.audio.AudioObjectsetContentTypepublic void setContentType(java.lang.String contentType)
setContentType in interface AudioObject
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||