public class AudioRecorder extends Object
Modifier and Type | Field and Description |
---|---|
static int |
RECORDSTATE_RECORDING
The state indicating that the recorder is recording
|
static int |
RECORDSTATE_STOPPED
The state indicating that the recorder is not recording
|
Constructor and Description |
---|
AudioRecorder()
Creates an AudioRecorder.
Call release() to release native resources after using the
recorder. |
Modifier and Type | Method and Description |
---|---|
int |
getRecordingState()
Returns the recording state.
|
int |
read(byte[] audioData,
int offset,
int size)
Reads up to
size bytes of audio data from the audio hardware
for recording into a buffer, blocks until at least one byte is read or no
more data because recorder has been stopped. |
void |
release()
Releases the native resources.
|
void |
setAudioBitRate(int audioBitRate)
Set bit rate.
|
void |
setAudioSampleRate(int sampleRateInHz)
Set audio sample rate in Hertz.
|
void |
setChannelConfig(int channelConfig)
Set the configuration of the audio channels.
|
void |
startRecording()
Start recording
|
void |
stop()
Stop recording
|
public static final int RECORDSTATE_STOPPED
public static final int RECORDSTATE_RECORDING
public AudioRecorder() throws IOException
release()
to release native resources after using the
recorder.IOException
- if failed to create recorderpublic void setAudioSampleRate(int sampleRateInHz) throws IllegalArgumentException
sampleRateInHz
- sample rate. Normally use 8000
,
16000
, 22050
, 44100
,
48000
. Default is 16000
.IllegalArgumentException
public void setChannelConfig(int channelConfig) throws IllegalArgumentException
channelConfig
- audio channel configuration. See
AudioFormat.CHANNEL_MONO
and
AudioFormat.CHANNEL_STEREO
. Default is
CHANNEL_MONO
IllegalArgumentException
public void setAudioBitRate(int audioBitRate) throws IllegalArgumentException
audioBitRate
- bit per sample. Normally use 8
,
16
. Default is 16
IllegalArgumentException
public int getRecordingState()
RECORDSTATE_STOPPED
,
RECORDSTATE_RECORDING
public int read(byte[] audioData, int offset, int size) throws IOException
size
bytes of audio data from the audio hardware
for recording into a buffer, blocks until at least one byte is read or no
more data because recorder has been stopped.audioData
- the array to which the recorded audio data is written.offset
- the start offset in array audioData
at which
the data is writtensize
- the maximum number of bytes to read-1
for endIOException
- if an I/O error occurspublic void startRecording() throws IOException
IOException
- if an I/O error occurspublic void stop() throws IOException
IOException
- if an I/O error occurspublic void release() throws IOException
IOException
- if an I/O error occurs