Lag on iOS when calling Microphone.Start()

I’m developing a loop station kind of app which the user could tap on a slot to record his/her voice and tap again to replay their voice.

However, whenever I tap on the slot to record, there’s a 0.5 sec lag… (It works fine on Unity Editor, but there’s always a 0.5 sec lag on my iOS build)

below is my code:

public void OnPointerDown()
{  
    if (recordMode) {
        StartCoroutine(RecordCoroutine());
    } else {
        GetComponent<AudioSource>().Play();
    }
}

IEnumerator RecordCoroutine()
{
    //change the color to show that it's currently recording
    GetComponent<Image>().color = Color.red;

     //start recording
    GetComponent<AudioSource>().clip = Microphone.Start(null, false, 1, 44100);

    yield return new WaitForSeconds(1f);
   
    //stop the mic
    Microphone.End(null);

    //recover button color
    GetComponent<Image>().color = Color.white;
}

Is there a way to get rid of the lag… I’ve been searching for a solution for an entire week but in vain…

P.S. I’ve already changed the DSP Buffer Size to Best latency to minimize the lag to play the audio clip.

I think i’ve been seeing something similar. Sometimes Unity microphone seems to add a 0.5-1s latency for no apparent reason. The worst is that it’s not consistent. Sometimes there is no extra latency. I’ve been debugging this and haven’t really found anything aside from that it seems to occur inside Unity and none of my attempts to change the microphone configuration and initialization seems to eliminate the problem.

no one have yet solved the problem?

IMO this is a classic Unity problem. I’ve worked on this several times and still haven’t found a solution. I don’t get it, my only thought is that Unity just doesn’t take live audio seriously.

1 Like

If the lag you are referring to is caused by Microphone.Start(), I hit that problem too, on iOS, with a noticeable .5ish second lag before Unity starts recording. I was able to fix by setting the “Prepare iOS for Recording” Player setting to true. This was in Unity 2210.3.24f1