Unity 5 and using a microphone

Hey everyone, been losing my mind with this. What I’m trying to do is have the player hold the space button, and while its being held his voice is recorded. So as soon as the player lets go of space, that ends the recording, and the resulting audio clip is of the length that the player held the space button.
This clip will then be used to analyze the volume vs. a set value, but for now I simply cannot figure out how to get this recording to work.
The Microphone.Start function specifically wants an int value for length of recording.
Any help would be greatly appreciated, as information on this topic seems rather sparse.
Thanks in advance!

Unfortunately, the only way to do this with the current API is a huge pain since resizing AudioClips isn’t allowed:

  1. When space is pressed, call Microphone.Start(), passing some maximum length of time for a recording as the length. Start a real-time timer of some sort.
  2. When space is released, call Microphone.End(), and stop the timer.
  3. If the maximum length was reached, use it as is. Otherwise, continue on:
  4. Create a new array of size clip.frequencyclip.channelsrealTimedSeconds.
  5. Call GetData() on the clip with the array and an offset of 0.
  6. Create a new AudioClip using AudioClip.Create with the same sample rate and number of channels, and with number of samples equal to the length of the array.
  7. Call SetData() on the new clip with the array and an offset of 0.
  8. Destroy the old clip.
  9. Return the new clip.

Tested with 5.1.2f1.