Package be.tarsos.dsp.io.jvm
Class AudioDispatcherFactory
java.lang.Object
be.tarsos.dsp.io.jvm.AudioDispatcherFactory
public class AudioDispatcherFactory
extends java.lang.Object
The Factory creates
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.- Author:
- Joren Six
- See Also:
AudioDispatcher
-
Constructor Summary
Constructors Constructor Description AudioDispatcherFactory()
-
Method Summary
Modifier and Type Method 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 AudioDispatcherstatic 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 newAudioDispatcher
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 newAudioDispatcher
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 newAudioDispatcher
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
-
Constructor Details
-
AudioDispatcherFactory
public AudioDispatcherFactory()
-
-
Method Details
-
fromDefaultMicrophone
public static AudioDispatcher fromDefaultMicrophone(int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.LineUnavailableExceptionCreate a new AudioDispatcher connected to the default microphone. The default is defined by the Java runtime by callingAudioSystem.getTargetDataLine(format)
. The microphone must support the format: 44100Hz sample rate, 16bits mono, signed big endian.- Parameters:
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.- Returns:
- An audio dispatcher connected to the default microphone.
- Throws:
javax.sound.sampled.LineUnavailableException
-
fromDefaultMicrophone
public static AudioDispatcher fromDefaultMicrophone(int sampleRate, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.LineUnavailableExceptionCreate a new AudioDispatcher connected to the default microphone. The default is defined by the Java runtime by callingAudioSystem.getTargetDataLine(format)
. The microphone must support the format of the requested sample rate, 16bits mono, signed big endian.- Parameters:
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.- Returns:
- An audio dispatcher connected to the default microphone.
- Throws:
javax.sound.sampled.LineUnavailableException
-
fromByteArray
public static AudioDispatcher fromByteArray(byte[] byteArray, javax.sound.sampled.AudioFormat audioFormat, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileExceptionCreate a stream from an array of bytes and use that to create a new AudioDispatcher.- Parameters:
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.- Returns:
- A new AudioDispatcher.
- Throws:
javax.sound.sampled.UnsupportedAudioFileException
- If the audio format is not supported.
-
fromURL
public static AudioDispatcher fromURL(java.net.URL audioURL, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileException, java.io.IOExceptionCreate a stream from an URL and use that to create a new AudioDispatcher- Parameters:
audioURL
- The URL describing the stream..audioBufferSize
- The number of samples used in the buffer.bufferOverlap
-- Returns:
- A new audio processor.
- Throws:
javax.sound.sampled.UnsupportedAudioFileException
- If the audio file is not supported.java.io.IOException
- When an error occurs reading the file.
-
fromPipe
public 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 newAudioDispatcher
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.- Parameters:
source
- The file or stream to capture.targetSampleRate
- The target sample rate.audioBufferSize
- The number of samples used in the buffer.bufferOverlap
-- Returns:
- A new audioprocessor.
-
fromPipe
public 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 newAudioDispatcher
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.- Parameters:
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 skip- Returns:
- A new audioprocessor.
-
fromPipe
public 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 newAudioDispatcher
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.- Parameters:
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 pipe- Returns:
- A new audioprocessor.
-
fromFile
public static AudioDispatcher fromFile(java.io.File audioFile, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileException, java.io.IOExceptionCreate a stream from a file and use that to create a new AudioDispatcher- Parameters:
audioFile
- The file.audioBufferSize
- The number of samples used in the buffer.bufferOverlap
-- Returns:
- A new audioprocessor.
- Throws:
javax.sound.sampled.UnsupportedAudioFileException
- If the audio file is not supported.java.io.IOException
- When an error occurs reading the file.
-
fromFloatArray
public static AudioDispatcher fromFloatArray(float[] floatArray, int sampleRate, int audioBufferSize, int bufferOverlap) throws javax.sound.sampled.UnsupportedAudioFileExceptionCreate a stream from an array of floats and use that to create a new AudioDispatcher.- Parameters:
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.- Returns:
- A new AudioDispatcher.
- Throws:
javax.sound.sampled.UnsupportedAudioFileException
- If the audio format is not supported.
-