Hello Joegre,
Thanks a lot for your answer.
Our issue is not that the Microphone still picks up audio when the HMD is in sleep mode. Our issue is that when we go to sleep mode and then come back, the Microphone doesn’t pickup audio anymore.
Our use case is quite simple, we want to have access to what the user says throughout the entire experience. Therefore, when the user launches the app, we trigger Microphone.Start()
and we never stop it.
The issue that we’re facing is that some users manage to break our app by going to sleep mode and then coming back and boom, the application doesn’t recognize their voice.
I have tried it with an empty Unity Scene and a new fresh scene. And this script:
public AudioClip _clipRecord;
public int _sampleWindow = 128;
public float loudness;
public bool _isInitialized;
public string micName;
//mic initialization
void InitMic(){
if (micName == null || micName == "") micName = Microphone.devices[0];
//Debug.Log (micName);
_clipRecord = Microphone.Start(micName, true, 2, 44100);
//Debug.Log("started mic");
_isInitialized = true;
// threshold = mean + 2 * (Mathf.Sqrt(sd));
}
//get data from microphone into audioclip
float LevelMax()
{
float levelMax = 0;
float[] waveData = new float[_sampleWindow];
int micPosition = Microphone.GetPosition(micName)-(_sampleWindow+1); // null means the first microphone
//Debug.Log(micPosition + " " + Microphone.GetPosition(micName) + " " + (_sampleWindow + 1));
if (micPosition < 0) return 0;
_clipRecord.GetData(waveData, micPosition);
// Getting a peak on the last 128 samples
for (int i = 0; i < _sampleWindow; i++) {
float wavePeak = waveData[i] * waveData[i];
if (levelMax < wavePeak) {
levelMax = wavePeak;
}
}
return levelMax;
}
void Update()
{
if (!_isInitialized)
{
InitMic();
}
loudness = LevelMax ();
}
If you display the loudness picked up by the Mic, the expected behavior is that when I speak, the loudness goes up.
But what happens once I go to sleep mode & come back is that the loudness stays at the minimum but the Microphone is still marked as recording. So the mic is actually not giving any audio data anymore.
But, the very important thing: this bug ONLY happens if we setup a passcode on the Meta Headset or if we have multiple accounts. Because, when going to sleep mode and coming back, we won’t go back directly to our app, we will first have to enter the passcode & then we’ll come to our app. (Note that this bug happens only when staying 10/15 sec in sleep mode)
So I am pretty sure that when in sleep mode with a passcode the Unity experience is not only paused but loses priority/access from the headset somehow.
Let me know if something isn’t clear, because we have a very clear way to reproduce it.
Best,
Alexis