public class AudioHelper extends VertxHelperBase
VertxHelperBase.AccessorVerticle
HelperBase.DATA_TYPE
_verticle, _vertx
_actor, _currentObj
Constructor and Description |
---|
AudioHelper(java.lang.Object actor,
jdk.nashorn.api.scripting.ScriptObjectMirror currentObj)
Create an audio helper.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
byteFormats()
Return an array of supported byte formats for audio.
|
void |
putBytes(byte[] audioData,
java.lang.Runnable callback)
Play an array of audio samples given as a byte array.
|
void |
putSamples(double[][] samplesArray,
java.lang.Runnable callback)
Play an array of audio samples.
|
void |
setCaptureParameters(java.util.Map<java.lang.String,java.lang.Integer> captureOptions,
int captureTime,
java.lang.String outputFormat)
Set the capture parameters for audio.
|
void |
setPlaybackParameters(java.util.Map<java.lang.String,java.lang.Integer> playbackOptions,
java.lang.String playbackFormat)
Set the playback parameters for audio.
|
void |
startCapture()
Start audio capture if it is not already active.
|
void |
startPlayback()
Start audio playback if it is not already active.
|
void |
stopCapture()
Stop audio capture if it is active.
|
void |
stopPlayback()
Stop audio playback if it is active.
|
_issueOrDeferResponse, _processPendingJob, _setBusy, closeVertx, getHelper, getImageTypes, reset, submit, supportedReceiveTypes, supportedSendTypes, undeploy
_appendNumericToBuffer, _appendToBuffer, _error, _error, _error, _error, _extractFromBuffer, _issueResponse, _removeDuplicates, _sizeOfType, _toJavaBytes, _toJSArray, getHelping
public AudioHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror currentObj)
actor
- The actor associated with this helper.currentObj
- The JavaScript object that this is helping.public static java.lang.String[] byteFormats()
public void putSamples(double[][] samplesArray, java.lang.Runnable callback) throws java.lang.IllegalStateException, java.io.IOException
The samples should be in the range (-1, 1). Samples that are outside this range will be hard-clipped so that they fall within this range.
The first index of the specified array represents the channel number (0 for first channel, 1 for second channel, etc.). The number of channels is set by the setChannels() method. The second index represents the sample index within a channel. For example, putSamplesArray[n][m] contains the (m+1)th sample of the (n+1)th channel.
samplesArray
- A two dimensional array containing
the samples to play.callback
- A callback function to invoke when the samples
have been queued into the audio system.java.io.IOException
- If the calling program does not have permission
to access the audio playback resources.java.lang.IllegalStateException
- If audio playback is currently
inactive. That is, If startPlayback() has not yet been called
or if stopPlayback() has already been called.public void putBytes(byte[] audioData, java.lang.Runnable callback) throws java.lang.IllegalStateException, java.io.IOException, javax.sound.sampled.UnsupportedAudioFileException
audioData
- Byte array to play.callback
- A callback function to invoke when the samples
have been queued into the audio system.java.io.IOException
- If the calling program does not have permission
to access the audio playback resources.java.lang.IllegalStateException
- If audio playback is currently
inactive. That is, If startPlayback() has not yet been called
or if stopPlayback() has already been called.javax.sound.sampled.UnsupportedAudioFileException
- If the audioData provided is
not in a supported format.public void setCaptureParameters(java.util.Map<java.lang.String,java.lang.Integer> captureOptions, int captureTime, java.lang.String outputFormat) throws java.io.IOException, javax.sound.sampled.LineUnavailableException
captureOptions
- The parameters for capture.captureTime
- The amount of time (in ms) per capture.outputFormat
- The requested output format.java.io.IOException
- If the specified sample rate is
not supported by the audio hardware or by Java.javax.sound.sampled.LineUnavailableException
- If the audio line is not
available.public void setPlaybackParameters(java.util.Map<java.lang.String,java.lang.Integer> playbackOptions, java.lang.String playbackFormat) throws java.io.IOException, javax.sound.sampled.LineUnavailableException
playbackOptions
- The parameters for playback.playbackFormat
- The expected format of the input data.java.io.IOException
- If the specified sample rate is
not supported by the audio hardware or by Java.javax.sound.sampled.LineUnavailableException
- If the audio line is not
available.public void startCapture() throws java.io.IOException
java.io.IOException
- If the audio target line cannot be acquired.public void startPlayback() throws java.io.IOException
java.io.IOException
- If the audio target line cannot be acquired.public void stopCapture()
public void stopPlayback()