public class AudioDispatcherFactory
extends java.lang.Object
AudioDispatcher
objects from various sources: the
configured default microphone, PCM wav files or PCM samples piped from a
sub-process. It depends on the javax.sound.* packages and does not work on Android.AudioDispatcher
Constructor and Description |
---|
AudioDispatcherFactory() |
Modifier and Type | Method and Description |
---|---|
static AudioDispatcher |
fromByteArray(byte[] byteArray,
javax.sound.sampled.AudioFormat audioFormat,
int audioBufferSize,
int bufferOverlap)
Create a stream from an array of bytes and use that to create a new
AudioDispatcher.
|
static AudioDispatcher |
fromDefaultMicrophone(int audioBufferSize,
int bufferOverlap)
Create a new AudioDispatcher connected to the default microphone.
|
static AudioDispatcher |
fromDefaultMicrophone(int sampleRate,
int audioBufferSize,
int bufferOverlap)
Create a new AudioDispatcher connected to the default microphone.
|
static AudioDispatcher |
fromFile(java.io.File audioFile,
int audioBufferSize,
int bufferOverlap)
Create a stream from a file and use that to create a new AudioDispatcher
|
static AudioDispatcher |
fromFloatArray(float[] floatArray,
int sampleRate,
int audioBufferSize,
int bufferOverlap)
Create a stream from an array of floats and use that to create a new
AudioDispatcher.
|
static AudioDispatcher |
fromPipe(java.lang.String source,
int targetSampleRate,
int audioBufferSize,
int bufferOverlap)
Create a stream from a piped sub process and use that to create a new
AudioDispatcher The sub-process writes a WAV-header and
PCM-samples to standard out. |
static AudioDispatcher |
fromPipe(java.lang.String source,
int targetSampleRate,
int audioBufferSize,
int bufferOverlap,
double startTimeOffset)
Create a stream from a piped sub process and use that to create a new
AudioDispatcher The sub-process writes a WAV-header and
PCM-samples to standard out. |
static AudioDispatcher |
fromPipe(java.lang.String source,
int targetSampleRate,
int audioBufferSize,
int bufferOverlap,
double startTimeOffset,
double numberOfSeconds)
Create a stream from a piped sub process and use that to create a new
AudioDispatcher The sub-process writes a WAV-header and
PCM-samples to standard out. |
static AudioDispatcher |
fromURL(java.net.URL audioURL,
int audioBufferSize,
int bufferOverlap)
Create a stream from an URL and use that to create a new AudioDispatcher
|
public static AudioDispatcher fromDefaultMicrophone(int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.LineUnavailableException
AudioSystem.getTargetDataLine(format). The microphone must support the format: 44100Hz sample rate, 16bits mono, signed big endian.
audioBufferSize
- The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap
- How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common.javax.sound.sampled.LineUnavailableException
public static AudioDispatcher fromDefaultMicrophone(int sampleRate, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.LineUnavailableException
AudioSystem.getTargetDataLine(format). The microphone must support the format of the requested sample rate, 16bits mono, signed big endian.
sampleRate
- The requested sample rate must be supported by the capture device. Nonstandard sample
rates can be problematic!audioBufferSize
- The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap
- How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common.javax.sound.sampled.LineUnavailableException
public static AudioDispatcher fromByteArray(byte[] byteArray, javax.sound.sampled.AudioFormat audioFormat, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileException
byteArray
- An array of bytes, containing audio information.audioFormat
- The format of the audio represented using the bytes.audioBufferSize
- The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap
- How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common.javax.sound.sampled.UnsupportedAudioFileException
- If the audio format is not supported.public static AudioDispatcher fromURL(java.net.URL audioURL, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileException, java.io.IOException
audioURL
- The URL describing the stream..audioBufferSize
- The number of samples used in the buffer.bufferOverlap
- javax.sound.sampled.UnsupportedAudioFileException
- If the audio file is not supported.java.io.IOException
- When an error occurs reading the file.public static AudioDispatcher fromPipe(java.lang.String source, int targetSampleRate, int audioBufferSize, int bufferOverlap)
AudioDispatcher
The sub-process writes a WAV-header and
PCM-samples to standard out. The header is ignored and the PCM samples
are are captured and interpreted. Examples of executables that can
convert audio in any format and write to stdout are ffmpeg and avconv.source
- The file or stream to capture.targetSampleRate
- The target sample rate.audioBufferSize
- The number of samples used in the buffer.bufferOverlap
- public static AudioDispatcher fromPipe(java.lang.String source, int targetSampleRate, int audioBufferSize, int bufferOverlap, double startTimeOffset)
AudioDispatcher
The sub-process writes a WAV-header and
PCM-samples to standard out. The header is ignored and the PCM samples
are are captured and interpreted. Examples of executables that can
convert audio in any format and write to stdout are ffmpeg and avconv.source
- The file or stream to capture.targetSampleRate
- The target sample rate.audioBufferSize
- The number of samples used in the buffer.bufferOverlap
- startTimeOffset
- Number of seconds to skippublic static AudioDispatcher fromPipe(java.lang.String source, int targetSampleRate, int audioBufferSize, int bufferOverlap, double startTimeOffset, double numberOfSeconds)
AudioDispatcher
The sub-process writes a WAV-header and
PCM-samples to standard out. The header is ignored and the PCM samples
are are captured and interpreted. Examples of executables that can
convert audio in any format and write to stdout are ffmpeg and avconv.source
- The file or stream to capture.targetSampleRate
- The target sample rate.audioBufferSize
- The number of samples used in the buffer.bufferOverlap
- startTimeOffset
- Number of seconds to skipnumberOfSeconds
- Number of seconds to pipepublic static AudioDispatcher fromFile(java.io.File audioFile, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileException, java.io.IOException
audioFile
- The file.audioBufferSize
- The number of samples used in the buffer.bufferOverlap
- javax.sound.sampled.UnsupportedAudioFileException
- If the audio file is not supported.java.io.IOException
- When an error occurs reading the file.public static AudioDispatcher fromFloatArray(float[] floatArray, int sampleRate, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileException
floatArray
- An array of floats, containing audio information.sampleRate
- The sample rate of the audio information contained in the buffer.audioBufferSize
- The size of the buffer defines how much samples are processed
in one step. Common values are 1024,2048.bufferOverlap
- How much consecutive buffers overlap (in samples). Half of the
AudioBufferSize is common.javax.sound.sampled.UnsupportedAudioFileException
- If the audio format is not supported.