How can I use microphone to record and access to buffer in real time?

What I need actually is quite simple, looks simple at least:
Using microphone to record and saving the recorded voice into a file, such as wav. All this must be done in real time, which means it cannot be capturing all voice and storing in memory then write to hard disk at once. I need it to write while capturing.

The problem I met is that although Unity let me access to the buffer by using AudioClip.GetData(), it doesn’t provide a way to let me know how many samples have been captured by microphone. In this case I won’t be able to determine how many samples I should read from the buffer and write to a wav file.
For example,

I create a clip of 20 seconds to store the recording:

goAudioSource.clip = Microphone.Start(null, true, 20, maxFreq);

If I stop the recording in 10 seconds, and copy the buffer out:

clip.GetData(samples, 0);

I will get 20 seconds buffer not 10 seconds, and the rest part in samples will be zero. I tried to use a timer to track the recording, but I must say it is not the best way. Can someone please help me? It is quite urgent.

Thank you very much!!

Maybe this could help?