iOS Background audio recording
Asked Answered
I

3

13

I know that if I start an audio recording session in foreground, with Audio, Airplay, and Picture in Picture activated in Capabilities -> Background Modes; I am able to continue to record even in background, but only if I start the recording session in foreground and then I go in background.

My problem is that I want to start the voice recording session from background, which might seem shaddy and not what Apple wants, but the use case is like this:

I have a Bluetooth LE device with buttons and an iOS app. Those two are paired (Bluetooth LE device and the iPhone which runs the iOS app) and the iOS app is listening for events on the Bluetooth LE device, events like a hit of a button.

Now, when the user hits a button on the Bluetooth LE device, the iOS app captures the event and I am able to run code even if the app is in background, but I am not able to start a voice recording.

My question is: is that even possible? To start a voice recording from background? Even if we have user interaction here, not on the iOS app but on the Bluetooth LE, so it's not like the voice recording starts in background and the user is not aware of it, he pressed the button on the Bluetooth LE device, he knows what he's doing.

Any help, documentation, tweet of an Apple engineer, anything would be much appreciated. Thanks.

UPDATE: MFI is not required. https://mfi.apple.com/MFiWeb/getFAQ.action#1-2.

If you look into the section:

"What types of accessories and technologies are NOT part of the MFi Program?"

You will see that:

"Accessories that use only Bluetooth Low Energy (BTLE) (note: BTLE-enabled HomeKit accessories and BTLE-enabled MFi Hearing Aids are part of the MFi Program)"

Is mentioned, which means MFI in this case is not required.

Institutive answered 3/2, 2017 at 8:45 Comment(9)
You can do this (I did it for a now defunct startup, hope your idea is better)! The essential ingredients are: background audio&bluetooth modes and recording using a software codec (non hardware).Hepato
Do you know any app on the AppStore that currently does this?Barriebarrientos
No, but I'm sure there are some. Dictation software comes to mind?Hepato
I am not sure you understand what am I looking for. About dictations software, well, why a dictation software would have to start a voice recording while in background?Barriebarrientos
To be ever ready to record your voice at the press of a BTLE button regardless of the phone's lock screen state for example? I'm guessing here. In any case I am not aware of any currently available app on the store that does this. That doesn't mean one doesn't exist. Feel free to use itunes' search feature.Hepato
@RhythmicFistman The work you done at a startup involved starting recording when the app is woken up in the background due to a BLE accessory action or a significant location change?Landahl
in response to a BLE accessory eventHepato
@MihaiErős, have you ever been able to make this work (start an audio recording from a BLE device, while the app is in background) ? Thanks is advanceFerne
@MihaiErős Did you find any way to start audio recording while application running in background ? Thanks in Advance.Natal
C
6

From Apple Documentation

An app that plays or records audio continuously (even while the app is running in the background) can register to perform those tasks in the background. You enable audio support from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the audio value in your app’s Info.plist file.) Apps that play audio content in the background must play audible content and not silence.

Typical examples of background audio apps include:

Music player apps Audio recording apps Apps that support audio or video playback over AirPlay VoIP apps

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

  • Apps that record audio content while in the background

EDIT:

Also regarding your "Bluetooth device":

Check out the documentation for ExternalAccessory .

Be aware that you need to apply and get approved for a special developer program in order to be able to create external accessories.

Corrientes answered 3/2, 2017 at 8:51 Comment(13)
Thanks, this might be helpful, I thought that if my bluetooth device gets certified by Apple, or something like this, I might be able to do what I want. Any idea how can I apply for that special developer program?Barriebarrientos
@MihaiErős np, check here: developer.apple.com/programs/mfi , please mark as answered if it answers your question. GLCorrientes
Thanks but MFI is not required since I use Bluetooth LE. So this doesn't help me..Barriebarrientos
"So this doesn't help me" , then please edit your post and rephrase what your question is, so far your question reads: My question is: is that even possible? To start a voice recording from background? And the answer is : Yes! which is clearly written here and also citated from the documentation. And if you don't need the MFI program, then good for you, that makes things easier don't they?Corrientes
Before you go ahead and give a piece of advice, you should know what MFI stands for, when it's required and when not. I specified that I am using Bluetooth LE, you jumped ahead and gave an answer without verifying it. See the FAQ on the Apple's MFI page. Thank you again, don't start a war, be nice.Barriebarrientos
Where do you see in the documentation that Apple says you can start a voice recording FROM background? Please point me to that paragraph. That would really be helpful.Barriebarrientos
"Don't start a war" . Please avoid your low-level comments on SO. I clearly said this answer answers your question which I bolded out for you above. If you have any other questions feel free to edit your question or create a new question. Thanks for clearing out what MFI stands for, now develop an app with an Bluetooth LE device that calls the iOS Bluetooth API and acts as a controller for recording audio, and get it approved by Apple without an MFI developer program. Please update this post when you do, I will personally buy your product and make sure all my friends buy it too. Good luck!Corrientes
We actually did that, we have an app on the AppStore that works, but we do have issues with starting a voice recording while app is in background. Here is the link:mfi.apple.com/MFiWeb/getFAQ.action#1-2. If you look into the section "What types of accessories and technologies are NOT part of the MFi Program?", you will see that: Accessories that use only Bluetooth Low Energy (BTLE) (note: BTLE-enabled HomeKit accessories and BTLE-enabled MFi Hearing Aids are part of the MFi Program) is mentioned, which means MFI in this case is not required.Barriebarrientos
@MihaiErős I don't think you understood me correctly. Running a custom control bluetooth device that triggers recording audio from the background. I don't know how Apple will react to that. However, you should look into #19932590 and , developer.apple.com/library/content/documentation/… awaking the App with the bluetooth connectionCorrientes
@MihaiErős BTW You need to take into account that awaking the app automatically from the background and running a task by bluetooth notification event is not the same as recording audio in background. While you may have your app up and running , starting record, and pushing it to background, is not the same as iOS starting the app for you and executing the audio recording in background using system resources without the users "input" and merely from the bluetooth notification only. I have not tried out the limitations or went into further details on this however. GL.Corrientes
That's exactly the problem, I can catch the BLE event when the app is in background, and I try to start a voice recording, but nothing happens. I can clearly see that this is some kind of limitation, but I am looking for a concrete reason or maybe a solution to the problem. Right now, I totally agree with you, that using system resources in background without the users input/user interaction and merely from the BLE notification/event/response seems to be a violation of Apple's privacy policy, at least.Barriebarrientos
@MihaiErős Yeah, that's why I strongly think that you would need an MFI for this, but I am not 100% sure , what you can do however, without an MFI, is to check out the ExternalAccessory framework in my answer, and see if that somehow allows a easier method to fire off anything, if it does, then I think you will need an MFI to use that framework, not sure since I havent tested it myself tho. However, I have not tested the frameworks and the differences between them compared to the Bluetooth framework etc. GL.Corrientes
The documentation link now redirects to something else, do you know where to find the current version ? (I especially cannot find if "Apps that record audio content while in the background" is still a valid reason to get the audio background permission)Ciscaucasia
T
1

Helpful tips::

It turns out that Apple's SpeakHere sample code with some modifications will start recording audio in the background if you just add the audio multitasking flag to information. You might look https://github.com/benvium/SpeakHere for an updated version of SpeakHere since Apple hasn't updated it in awhile.

Talkington answered 3/2, 2017 at 8:53 Comment(2)
Not to be "that guy" but that sample code seems to be over 6 years old? :P have you tested it?Corrientes
I actually tried SpeakHere, with some modifications I was able to run that project on iOS 10. But I can't start a voice recording in background, if I start it in foreground and then I switch to background it works, but that's not helpful.Barriebarrientos
C
0

I bang my head for weeks on this topic. Apple do not want to you listen to people when the app is in the background. I ended up activating the microphone immediately when the app moves to background.

The idea is to activate the microphone with empty code - meaning not wasting battery until you need to listen and then you replace the microphone callback with the real listener.

Here is an example I built in react native Not that the function below - backgroundMicEmptyListener() creates an empty listener with no CPU usage except the call to the function and return.

const handleAppStateChange = (nextAppState) => {
  console.log("handleAppStateChange(): ", nextAppState);
  
  if (nextAppState === 'background') {
      console.log("nextAppState === 'background'");
      BackgroundJob.start(backgroundMicEmptyListener, backgroundOptions)
      .then(() => {
          console.log('Background job started successfully');
      })
      .catch((err) => {
          console.error('Error starting background job:', err);
      });
  }
 

I know it is not the best solution however the only one I found.

I am using it for VAD and Wake Words detection and it worked great.

Callous answered 15/8 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.