Microphone.GetPosition Always == 0

I have used the Microphone Start and End functions to record successfully just a few weeks back. I would use Microphone.GetPosition to get the samples recorded to trim the audio clip and then saved it to a file. Now when I run the script Microphone.GetPosition(recordingDevice) always returns 0. Clicking on the supposedly recorded clip gives me a clip of 60 seconds length as set in Microphone.Start(recordingDevice, false, 60, 44100). It will not play in the Preview Window. I am on 2017.1 on Windows 10, using both the Rift mic and the headset mic plugged into the PC…both give me no joy. Any clues anybody?

On Unity 2020.1.12f1
I experienced the same, mine was happening when I recorded once and then tried to record another time.
The second time Microphone.GetPosition would be 0.
The flow of the code went
Try 1 (Alll ok) Microphone.Start → Microphone.GetPosition + MicroPhone.End
Try 2 (GetPosition = 0) Microphone.Start → Microphone.GetPosition + MicroPhone.End

What fixed this issue is to make the end function a coroutine and wait for end of frame before Microphone.GetPosition

yield return new WaitForEndOfFrame();

int stopPosition = Microphone.GetPosition(null);
Microphone.End(null); //Stop the audio recording

2 Likes

i was just recently having this issue. this solved it! thanks :slight_smile: