birdofpreyru / react-native-audio

React Native: access to the audio input stream, and audio sample player
https://dr.pogodin.studio/docs/react-native-audio
Other
21 stars 4 forks source link

[iOS] Input / output device selection #5

Closed birdofpreyru closed 1 year ago

birdofpreyru commented 2 years ago

Right now, when sound recording is activated on iOS, in the following codeblock, we do nothing to select audio device: https://github.com/birdofpreyru/react-native-audio/blob/0966070a502db1fe5dbbe6f0065bba20451fe74b/ios/RNAInputAudioStream.m#L121-L128

It turns out, when external (e.g. bluetooth microphone / headphone) audio device is connected to iOS device, even if initially the sound from the app is output to that device, entering into Tuning (or interactive training mode), and activating sound recording, currently switches both audio input and output to the default (on-board of device) iOS speaker / mic. This happens inside this call.

Now, the problem is after a brief investigation I am not able to find how to select the audio input / output device (can't see such config in the docs of the methods we use in the codeblock linked above). It seems it might not possible to use input and output from different devices on iOS (not without user re-configuration of audio settings inside device configs), but we at least should instruct the app to keep using bluetooth mic/speaker, if they are connected and used before activating sound recording.

It requires further investigation, how to achieve it.

birdofpreyru commented 2 years ago

AudioQueueSetProperty kAudioQueueProperty_CurrentDevice AudioQueueGetProperty

See also: https://stackoverflow.com/questions/20051529/audioqueue-change-audio-device-while-audioqueue-is-running

birdofpreyru commented 2 years ago

Probably, this should be used: https://developer.apple.com/documentation/avfaudio/avaudiosession

birdofpreyru commented 2 years ago