Recorded audio plays faster than original and has glitches

I created a custom reporter to record audio for N seconds:

But the captured audio does not sound identical to the audio. It has glitches and playback speed seems faster a tad bit faster - even though I have considered microphone sampling rate into account.

Ideally, the built-in microphone block would accept the duration as an argument. Since we don't have that, how do I go about capturing audio from users for longer duration than 512 samples?

The microphone samples cannot (yet) be used to actually record sound, because it returns the contents of the hardware audio buffer without making sure that it's not skipping any samples (which is why capturing and recording those samples directly from the buffer later sounds faster and "funnier" when playing them back again).

If you would like (your students) to record short snippets of sound the best way to do it is to use the UI:

record GUI

Alternatively there's also a record reporter in the AudioComp library which accesses the same recording dialog: