jsierles / react-native-audio

Audio recorder library for React Native
MIT License
1.16k stars 539 forks source link

How to record with headphone mic #364

Open 345ml opened 4 years ago

345ml commented 4 years ago

Tell us which versions you are using ( you can see the versions in your package.json ):

"react-native-audio": "^4.3.0",
"react-native-sound": "^0.11.0",
"react-native": "0.61.5",
"react": "16.9.0",

Expected behaviour :

For example, when you have an earphone mic on AirPods, you want to record audio from the headphone mic.

Actual behaviour

Even if wearing a headphone microphone, it seems to be recording audio from the device's microphone.

Steps to reproduce

Here's the code as I recorded it.

AudioRecorder.prepareRecordingAtPath(`${AudioUtils.DocumentDirectoryPath}/audio.aac`, {
  SampleRate: 16000,
  Channels: 1,
  AudioQuality: 'High',
  AudioEncoding: 'aac',
});
345ml commented 4 years ago

https://github.com/jsierles/react-native-audio/blob/f223414c6a965d24cea74179194613cf37e566ef/ios/AudioRecorderManager.m

I confirmed the code that works.

Around line 220. Before

[_recordSession setCategory:AVAudioSessionCategoryMultiRoute error:nil];

After

[_recordSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[_recordSession setMode:AVAudioSessionModeDefault error:nil];