NatCorder Tutorial: Audio Workflows

Hi all! In this tutorial, I will be discussing NatCorder’s audio API and different workflows for working with audio when recording video. First, I will go over NatCorder’s audio API, then I will discuss how to use it for recording game audio.

The Audio API

NatCorder offers a very simple API for recording PCM audio with video. There are two things that NatCorder will need from you:

  • A description of the audio. NatCorder needs to know some things ahead of time. How many audio channels are there, and how often will you be providing samples (sample rate)?
  • Actual audio! As you record, you will need to provide NatCorder the actual audio to be recorded as an array of single-precision floating point PCM samples (a.k.a, float[]).

To provide this information, the client (you) is expected to use an AudioFormat. Let’s look at the definition:

Recording Unity Audio

Unity provides access to PCM audio samples through the OnAudioFilterRead method:

This is incredibly convenient for use with NatCorder. What this means is that when we want to record audio from the scene (using an AudioListener ) or from a particular game object (using an AudioSource), we simply need to attach the script to the source/listener and in OnAudioFilterRead , call NatCorder.CommitSamples :

There is one last step. When we actually start recording, we need to provide NatCorder with an AudioFormat so that it knows what audio data to expect during recording, if any. To do this, we can construct an AudioFormat and pass it in to StartRecording :

And that’s it! Just make sure to destroy the AudioRecorder when you stop recording. In the next tutorial, I will go over advanced recording using the NatCorder API. Till next time!

— Lanre Olokoba.


NatCorder is a cross-platform video recording API for Unity Engine. Get NatCorder here.

Note: This tutorial has been updated to reflect NatCorder 1.3’s newer API.