AudioSource value for Android USB Microphone

Application for capturing sound on the root MK809 / Android 4.1.1. There is no internal microphone, so I'm trying to use a USB drive that is correctly recognized as a "USB audio device" in the settings / Sound / Sound Devices Manager / Sound Input Devices when connected.

What is the value of the AudioSource device to pass to the AudioRecord constructor (first argument). I tried everything in MediaRecorder.AudioSource, no one worked. I'm only interested in reading the capture buffer, not saving to a file.

+7
source share
2 answers

Answering my question. The following values ​​were met: DEFAULT, MIC, CAMCORDER, possibly others, as this is the only input device.

I tried to use a sampling rate of 48000 (works on Windows), and the creation of AudioRecord completed with:

ERROR / AudioRecord (1615): Failed to get audio input for recording source 1 ERROR / AudioRecord-JNI (1615): Error creating AudioRecord instance: initialization check failed. ERROR / AudioRecord-Java (1615): [android.media.AudioRecord] Error code -20 when initializing its own AudioRecord object.

To some extent misleading information, given that calling getMinBufferSize () with the same set of agruments does not return an error, as expected. I assumed that this is the actual sample rate for the device. Fixed the problem with setting to 44100 (guranteed).

USB audio input devices work on Android, Bean jelly at least. Hope this helps someone.

+5
source

FWIW is a specific implementation (it may vary between different platform providers and OEMs).

On the devices I worked on, a USB accessory microphone is selected if AudioSource DEFAULT , MIC or VOICE_RECOGNITION , and only the sampling frequencies supported in the HAL audio for recording USB sound, were 8, 16 and 48 kHz (although AudioFlinger is capable of reprogramming other speeds in a certain range).

+5
source

All Articles