llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
243 stars 203 forks source link

[Android] Low microphone quality through Bluetooth audio #431

Open Zazo032 opened 2 weeks ago

Zazo032 commented 2 weeks ago

Package version

5.2.0 and 5.1.2

Environment

Describe the bug

When performing an audio recording with a Galaxy device (I couldn't test other brands but this is reproducible in different Galaxy models) with a Bluetooth headset connected (I used AirPods Pro for testing but we have reports of other standard Bluetooth devices), the audio quality of the recordings is bad. The audio seems to be recorded through Bluetooth SCO and there's no way to do it through A2DP, so all audio recorded through Bluetooth devices has a low audio quality. I tried setting manageBluetooth to false but then the audio is recorded through the device microphone and not through the Bluetooth one. Setting numChannels to 1, useLegacy to true or modifying the audioSource also doesn't seem to have any effect in the recording quality.

Record configuration

const RecordConfig()

Steps to reproduce

Steps to reproduce the behavior:

  1. Run example project on an Android device (only tested it in Galaxy devices)
  2. Connect a Bluetooth headset that supports "Calls" audio profile/channel (screenshot attached)
  3. Record and play some audio through the Bluetooth device (input and output).
Bluetooth device settings ![Screenshot_20241106_154228_Settings](https://github.com/user-attachments/assets/d91b4342-dd40-4936-9325-cea926a37e46)

Expected behavior

Audio gets recorded with the same or similar audio quality to the native recorder app.

Actual behavior

Audio gets recorded with a significantly worse quality than expected when recording through a Bluetooth microphone.

Additional context

Disabling the "Calls" option in the Bluetooth device settings is a workaround to get the expected audio recording quality.

llfbandit commented 2 weeks ago

Thanks for the report. What if you try to set the device? There's no automatic selection of the device but with manageBluetooth SCO flag.

Zazo032 commented 2 weeks ago

Thanks for the report. What if you try to set the device? There's no automatic selection of the device but with manageBluetooth SCO flag.

Do you mean through RecordConfig.device? There doesn't seem to be a way to retrieve an InputDevice from Android to pass it to that parameter

llfbandit commented 2 weeks ago

listInputDevices()

Zazo032 commented 2 weeks ago

listInputDevices() is documented as returning an empty list in Android: https://pub.dev/documentation/record/latest/record/AudioRecorder/listInputDevices.html

I know the id and label from the device I'm using through a different plugin (mic_info), I tried with the following configuration but the recorded audio quality is still the same:

const RecordConfig(
  device: InputDevice(id: '309', label: 'AirPods Pro de Cristian'),
  androidConfig: AndroidRecordConfig(
    manageBluetooth: false,
  ),
),
Zazo032 commented 2 weeks ago

I just tried with listInputDevices() by hardcoding the object from the list that corresponds to the Bluetooth device with manageBluetooth: false, but the issue still persists