Added in API level 3

AudioRecord


open class AudioRecord : AudioRecordingMonitor, AudioRouting, MicrophoneDirection
kotlin.Any
   ↳ android.media.AudioRecord

The AudioRecord class manages the audio resources for Java applications to record audio from the audio input hardware of the platform. This is achieved by "pulling" (reading) the data from the AudioRecord object. The application is responsible for polling the AudioRecord object in time using one of the following three methods: read(byte[],int,int), read(short[],int,int) or read(ByteBuffer,int). The choice of which method to use will be based on the audio data storage format that is the most convenient for the user of AudioRecord.

Upon creation, an AudioRecord object initializes its associated audio buffer that it will fill with the new audio data. The size of this buffer, specified during the construction, determines how long an AudioRecord can record before "over-running" data that has not been read yet. Data should be read from the audio hardware in chunks of sizes inferior to the total recording buffer size.

Applications creating an AudioRecord instance need android.Manifest.permission#RECORD_AUDIO or the Builder will throw java.lang.UnsupportedOperationException on build(), and the constructor will return an instance in state STATE_UNINITIALIZED.

Summary

Nested classes
open

Builder class for AudioRecord objects.

abstract

Interface definition for a callback to be invoked when an AudioRecord has reached a notification marker set by AudioRecord.setNotificationMarkerPosition(int) or for periodic updates on the progress of the record head, as set by AudioRecord.setPositionNotificationPeriod(int).

abstract

Defines the interface by which applications can receive notifications of routing changes for the associated AudioRecord.

Constants
static Int

Denotes a generic operation failure.

static Int

Denotes a failure due to the use of an invalid value.

static Int

An error code indicating that the object reporting it is no longer valid and needs to be recreated.

static Int

Denotes a failure due to the improper use of a method.

static Int

The read mode indicating the read operation will block until all data requested has been read.

static Int

The read mode indicating the read operation will return immediately after reading as much audio data as possible without blocking.

static Int

indicates AudioRecord recording state is recording

static Int

indicates AudioRecord recording state is not recording

static Int

indicates AudioRecord state is ready to be used

static Int

indicates AudioRecord state is not successfully initialized.

static Int

Denotes a successful operation.

Inherited constants
Public constructors
AudioRecord(audioSource: Int, sampleRateInHz: Int, channelConfig: Int, audioFormat: Int, bufferSizeInBytes: Int)

Class constructor.

Public methods
open Unit

Adds an OnRoutingChangedListener to receive notifications of routing changes on this AudioRecord.

open Unit

Adds an AudioRouting.OnRoutingChangedListener to receive notifications of routing changes on this AudioRecord.

open MutableList<MicrophoneInfo!>!

Returns a lists of MicrophoneInfo representing the active microphones.

open AudioRecordingConfiguration?

Returns the current active audio recording for this audio recorder.

open Int

Returns the configured audio data encoding.

open Int

Returns the audio session ID.

open Int

Returns the audio recording source.

open Int

Returns the frame count of the native AudioRecord buffer.

open Int

Returns the configured channel position mask.

open Int

Returns the configured number of channels.

open AudioFormat

Returns the configured AudioRecord format.

open LogSessionId

Returns the LogSessionId.

open PersistableBundle!

Return Metrics data about the current AudioTrack instance.

open static Int
getMinBufferSize(sampleRateInHz: Int, channelConfig: Int, audioFormat: Int)

Returns the minimum buffer size required for the successful creation of an AudioRecord object, in byte units.

open Int

Returns the notification marker position expressed in frames.

open Int

Returns the notification update period expressed in frames.

open AudioDeviceInfo!

Returns the selected input specified by setPreferredDevice.

open Int

Returns the recording state of the AudioRecord instance.

open AudioDeviceInfo!

Returns an AudioDeviceInfo identifying the current routing of this AudioRecord.

open MutableList<AudioDeviceInfo!>

Returns a List of AudioDeviceInfo identifying the current routing of this AudioRecord.

open Int

Returns the configured audio sink sample rate in Hz.

open Int

Returns the state of the AudioRecord instance.

open Int
getTimestamp(outTimestamp: AudioTimestamp, timebase: Int)

Poll for an AudioTimestamp on demand.

open Boolean

Returns whether this AudioRecord is marked as privacy sensitive or not.

open Int
read(audioData: ByteArray, offsetInBytes: Int, sizeInBytes: Int)

Reads audio data from the audio hardware for recording into a byte array.

open Int
read(audioData: ByteArray, offsetInBytes: Int, sizeInBytes: Int, readMode: Int)

Reads audio data from the audio hardware for recording into a byte array.

open Int
read(audioData: FloatArray, offsetInFloats: Int, sizeInFloats: Int, readMode: Int)

Reads audio data from the audio hardware for recording into a float array.

open Int
read(audioBuffer: ByteBuffer, sizeInBytes: Int)

Reads audio data from the audio hardware for recording into a direct buffer.

open Int
read(audioBuffer: ByteBuffer, sizeInBytes: Int, readMode: Int)

Reads audio data from the audio hardware for recording into a direct buffer.

open Int
read(audioData: ShortArray, offsetInShorts: Int, sizeInShorts: Int)

Reads audio data from the audio hardware for recording into a short array.

open Int
read(audioData: ShortArray, offsetInShorts: Int, sizeInShorts: Int, readMode: Int)

Reads audio data from the audio hardware for recording into a short array.

open Unit

Register a callback to be notified of audio capture changes via a AudioManager.AudioRecordingCallback.

open Unit

Releases the native AudioRecord resources.

open Unit

Removes an OnRoutingChangedListener which has been previously added to receive rerouting notifications.

open Unit

Removes an AudioRouting.OnRoutingChangedListener which has been previously added to receive rerouting notifications.

open Unit

Sets a LogSessionId instance to this AudioRecord for metrics collection.

open Int

Sets the marker position at which the listener is called, if set with setRecordPositionUpdateListener(OnRecordPositionUpdateListener) or setRecordPositionUpdateListener(OnRecordPositionUpdateListener,Handler).

open Int

Sets the period at which the listener is called, if set with setRecordPositionUpdateListener(OnRecordPositionUpdateListener) or setRecordPositionUpdateListener(OnRecordPositionUpdateListener,Handler).

open Boolean

Specifies an audio device (via an AudioDeviceInfo object) to route the input to this AudioRecord.

open Boolean