Will work on the build / install, then fail on every subsequent run and/or app update. Once uninstalled and reinstalled, permissions have to be given again, then it works once. Any further re-runs or app updates fail with the following generic error:
AURemoteIO.cpp:1702 AUIOClient_StartIO failed (561145187)
Starting microphone failed: "An error occured trying to initialize the recording device. " (70)
MicTest:Start()
This error type usually occurs when an app starts a mixable recording from the background and it isn’t configured as an Inter-App Audio app.
Maybe you’re trying to start the microphone too early, when the app is still starting up? Have you tried starting the microphone a frame later?
The reason why it works once could be related to the permission prompt, which delays the actual start of the recording session. Only when the permission is already granted is the session started immediately.
ah, good catch, thank you! I found that definition but didn’t have that intuition. Throwing a 2 second delay at it solves it most of the time, albeit not fully, which is interesting. I’ll keep debugging, but I think you nailed the root cause. Thank you!
UPDATE: I found a fix! In UnityAppController.mm, the audio category was set to ambient. I changed it to AVAudioSessionCategoryPlayAndRecord. I also took out if statement, so from line 133, it looks like this:
Thanks oliran for the suggestion. That makes it work after a fresh install now but not in subsequent runs Did you also find a way to “persist” the modified mm-file?
I’ve had this problem and noticed that the time that I need to wait for the microphone to be safe-to-initialize is very unpredictable.
I ended up resorting to creating a coroutine that opens the microphone and looks for non-zero samples in the recorded audioclip. Sometimes it takes only a frame or two, sometimes it takes 10 seconds or more! But it does eventually initialize every time.
hi @oliran , according to the processing you described, the recording still cannot be recorded, and there will be the following warning:
AVAudioSession_iOS.mm:2223 Server returned an error from destroySession:. Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service with pid 39 named com.apple.audio.AudioSession was invalidated from this process." UserInfo={NSDebugDescription=The connection to service with pid 39 named com.apple.audio.AudioSession was invalidated from this process.}
But after playing an audio video, it can be recorded normally. What is the reason for this?
I know a bit about AVAudioSession, but I’m not very familiar with it. Can you explain it in detail?
Thank you.
Reviving this thread: This seems to be an issue specific to immersive spaces, and we’ve reported it to Apple with a non-Unity repro project. In addition to needing to delay enabling the microphone on startup, you may find that you also need to disable it when your immersive space loses focus (and then reenable it after a delay on regaining focus). There’s some sample code in a more recent related thread here.
The mic start problem definitely persists with visionos xr plugin 1.3.1 on VisionOS 2.0.1, where immersive mode is now “Metal” mode. Using Unity 2022.3.47.
Has there been any update from Apple on this? Would updating the visionos xr plugin to 1.3.9 help here?
We were already delaying microphone start for upwards of 10+seconds from app launch due to splash screen and other account login type things that happen before allowing user interaction. We’ll try some of the other suggestions such as coroutine monitoring for sample data.