Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Microphone input
Stay organized with collections
Save and categorize content based on your preferences.
When capturing audio, the Audio HAL receives an openInputStream
call that
includes an AudioSource
argument to indicate how microphone input should be
processed.
The VOICE_RECOGNITION
source expects a stereo microphone stream that has an
echo cancellation effect (if available) but no other processing applied to it.
To capture audio from a device with more than two channels (stereo), use a
channel index mask instead of positional index mask (such as CHANNEL_IN_LEFT
).
For example:
final AudioFormat audioFormat = new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(44100)
.setChannelIndexMask(0xf /* 4 channels, 0..3 */)
.build();
final AudioRecord audioRecord = new AudioRecord.Builder()
.setAudioFormat(audioFormat)
.build();
audioRecord.setPreferredDevice(someAudioDeviceInfo);
When both setChannelMask
and setChannelIndexMask
are set, AudioRecord
uses
only the value set by setChannelMask
(maximum of two channels).
Concurrent capture
As of Android 10, the Android framework supports
Concurrent capture of inputs, but with
restrictions to protect the user’s privacy. As part of these restrictions,
virtual sources such as AUDIO_SOURCE_FM_TUNER
are ignored, and are allowed to
be captured concurrently along with a regular input (such as the microphone).
HwAudioSource
is not considered part of the concurrent capture restrictions.
Apps designed to work with AUDIO_DEVICE_IN_BUS
devices or with secondary
AUDIO_DEVICE_IN_FM_TUNER
devices must rely on explicitly identifying those
devices and using AudioRecord.setPreferredDevice()
to bypass the Android
default source selection logic.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-29 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Microphone input\n\nWhen capturing audio, the Audio HAL receives an `openInputStream` call that\nincludes an `AudioSource` argument to indicate how microphone input should be\nprocessed.\n\nThe `VOICE_RECOGNITION` source expects a stereo microphone stream that has an\necho cancellation effect (if available) but no other processing applied to it.\n\nMulti-channel microphone input\n------------------------------\n\nTo capture audio from a device with more than two channels (stereo), use a\nchannel index mask instead of positional index mask (such as `CHANNEL_IN_LEFT`).\nFor example: \n\n final AudioFormat audioFormat = new AudioFormat.Builder()\n .setEncoding(AudioFormat.ENCODING_PCM_16BIT)\n .setSampleRate(44100)\n .setChannelIndexMask(0xf /* 4 channels, 0..3 */)\n .build();\n final AudioRecord audioRecord = new AudioRecord.Builder()\n .setAudioFormat(audioFormat)\n .build();\n audioRecord.setPreferredDevice(someAudioDeviceInfo);\n\nWhen both `setChannelMask` and `setChannelIndexMask` are set, `AudioRecord` uses\nonly the value set by `setChannelMask` (maximum of two channels).\n\nConcurrent capture\n------------------\n\nAs of Android 10, the Android framework supports\n[Concurrent capture](/docs/core/audio/concurrent) of inputs, but with\nrestrictions to protect the user's privacy. As part of these restrictions,\nvirtual sources such as `AUDIO_SOURCE_FM_TUNER` are ignored, and are allowed to\nbe captured concurrently along with a regular input (such as the microphone).\n`HwAudioSource` is not considered part of the concurrent capture restrictions.\n\nApps designed to work with `AUDIO_DEVICE_IN_BUS` devices or with secondary\n`AUDIO_DEVICE_IN_FM_TUNER` devices must rely on explicitly identifying those\ndevices and using `AudioRecord.setPreferredDevice()` to bypass the Android\ndefault source selection logic."]]