Record audio in apple watch using bluetooth headset - ios

I know how to record audio using watch speaker. But is there any api available to record using bluetooth headset? So that recording is possible without presenting the audio input controller

Currently there is no such API available to record using Bluetooth headset. If a call is established from watch which has a headset paired does not route voice output to headset rather it uses its default speaker and mic as output and input

Related

How to configure AVAudioSessionCategoryMultiRoute for playing different audios to built-in speaker and headphones (or bluetooth headphones)?

I found such info:
Important: The built-in speaker may be used only if no other eligible output ports (USB, HDMI, LineOut) are connected.
https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionBasics/AudioSessionBasics.html
But standard iOS Clock app can use built-in speaker when 3.5 jack headphones connected.
What about bluetooth headphones? Can I send different audio streams to
built-in speaker and bluetooth headphones at the same time using AVAudioSessionCategoryMultiRoute?

Record device audio output with AudioUnit

We need to record the device audio output from cable or bluetooth headset speakers. For example if user listens to some song when Music app runs in background we want to record this song. Is it possible to implement output recording with AudioUnit? We use PalayAndRecord category for shared audioSession with AVAudioSessionCategoryOptionMixWithOthers option.
No, in general you can not listen to the output from another app. There is inter app audio and audio unit technology that enables this, but the connection must be arranged by both apps. It is not possible to just eavesdrop on whatever the user outputs from the device.

How to record voice from a Bluetooth headset for iOS device?

I have an application that needs to record voice from Bluetooth headset. It needs work like Siri or Google Assistant. When I press button in App, it records voice from Bluetooth MIC rather than build in Mic. Is that possible?
My understanding is
1) either the Bluetooth is an Apple certificated External Accessory
2) or the Headset can implement a HFP like protocol to active a HFP link ?
Any hints?
If all you need is recording, it's quite straight if your bluetooth device is paired with iOS. All bluetooth headset with microphone will work well.
When you start to record, I think you have already changed your audio session category to play and record.
Then you can check all your available input route with
-[AVAudioSession availableInputs]
and iterate to find the bluetooth, then set it with
-[AVAudioSession setPreferredInput:error:]
Sometimes it will fail, you need to check the output parameter error to find if there is something wrong.

How can GarageBand record from built-in mic while playback on Bluetooth A2DP?

While using a Bluetooth device WITHOUT microphone to playback audio I want to record audio from the built-in microphone.
If the Bluetooth device HAS a microphone, it is not possible according to this Apple Developer Forum thread and this SO question.
However, I justed tried to do it with GarageBand and it allows me to record from the built-in microphone while playing back high quality audio (A2DP?) on the Bluetooth speaker (with no built-in microphone).
How does GarageBand do it?
I activate the my app's AVAudioSession with category AVAudioSessionCategoryPlayAndRecord and parameter AVAudioSessionCategoryOptionAllowBluetooth but I have not found a way to playback audio on the Bluetooth speaker. Only Bluetooth speakers that has a built-in microphone works.

How to detect active audio source of car bluetooth in iOS app

I am working to play some voice messages from iPhone to car bluetooth audio and are testing with Lexus RX350, which supports A2DP and HFP. In our case, A2DP is preferred. However, I can only hear the sound when car is using bluetooth as audio source. When listening to CD or radio, no sound from iPhone is actually played over car audio system.
So, what I want to do is:
Use A2DP when bluetooth is the active audio source
Otherwise use HFP
I use AVAudioPlayer to play audio with AVAudioSessionCategoryPlayback as audio session category. It will always succeed as long as the bluetooth connection is established, no matter whether the car audio is on radio, CD or bluetooth. There is no route change notification when switch between audio sources, therefore I don’t know when we shall switch to HFP. Any suggestions?
Btw, music players like Spotify, Pandora, will pause when switch away from bluetooth audio and resume when switch back, Google Maps will use A2DP when bluetooth audio is active and use HFP if not, so I think there should be a way to detect the change

Resources