Problem
I am unable to get Android's MediaRecorder to record audio from a connected Bluetooth microphone. Instead audio recordings use the device's inbuilt microphone
Question
Has anyone found a reliable way to get Android's MediaRecorder to record audio input from a connected Bluetooth microphone?
Research
Earlier answers suggest using the now deprecated startBluetoothSco(). Without startBluetoothSco() there appears to be no way to "encourage" Android to use a connected Bluetooth microphone over device microphone(s).
The following code successfully records audio, but only from the device microphone and never from the Bluetooth microphone
mediaRecorder = MediaRecorder(this).apply {
setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION) // or .MIC
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP) // or MPEG_4
setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
setAudioChannels(1) // Mono
setAudioSamplingRate(16000)
setOutputFile(audioOutputFile)
// use
prepare()
start()
Earlier experience
When startBluetoothSco() was depreciated in my Text-to-Speech app I simply replaced startBluetoothSco() with a suitable audio mode (AudioManager.STREAM_MUSIC) and Android routed audio to the speaker.
Below is the code I have used to try a similar trick. It lists connected Bluetooth devices and if they appear to be the desired microphone change the audio mode:
val bluetoothA2DPConnectedDevices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).filter { it.type == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP }
bluetoothA2DPConnectedDevices.forEach { bluetoothDevice ->
audioManager.mode = AudioManager.MODE_IN_CALL // if find a suitable Bluetooth device try changing audio mode
}
I have tried multiple AudioManager modes but none resulted in audio recordings using the external microphone
Can anyone suggest what else I could try ?