NatMic API: Microphone That Works

Lanre Olokoba
Aug 22, 2018 · 2 min read

Hi all! Today, I’m pretty excited to introduce a new API that solves a problem that the Unity ecosystem has struggled with for years now. For some background, I developed the NatCorder video recording API for Unity Engine and one thing that a lot of developers have had need for is a reliable way to record the user’s voice with gameplay. We have always pointed them to the Microphone API provided by Unity, but they’ve expressed their frustration with its shortcomings.

Unity’s Microphone API often lags and stutters. This has become a huge problem for us, because it means that developers who want to do something as simple as recording replays with voice-overs have no way of doing so. We finally decided to fix it ourselves by building a native microphone API from the ground up.

Say Hello to NatMic API

NatMic is a minimal cross-platform microphone API for realtime recording. NatMic 1.0 will have native support for iOS, Android, macOS, and Windows. The API is built on a simple paradigm: There are IAudioDevice instances which provide clean abstractions for hardware- and software-based audio input devices. These IAudioDevice instances can be told to start and stop recording:

Once recording is started, the IAudioProcessor instance is provided with sample buffers from the microphone. Each sample buffer contains audio samples recorded by the microphone over short intervals of time:

Recording Audio

NatMic comes with IAudioRecorders which are lightweight classes for recording audio data to a persistent format, like audio files. We expect this to be one of the more common use cases of NatMic, so NatMic 1.0 will feature a WAVRecorder for recording Waveform audio files.

Here is an example demonstrating recording the microphone to a WAV file:

What the Future Holds

NatMic is now live on the Asset Store. Grab it from there, and make sure to post comments or questions on the NatMic thread on Unity forums.

In later releases, we expect to add support for spectral analysis of the audio data (specifically, the Fast Fourier Transform). We are also looking into adding support for VoIP applications, so that you can make your own Skype ;). Finally, we are considering adding support for WebGL and Windows RT. Till then, happy recording!

— Lanre Olokoba.

NatSuite

Cross-platform media tools for developing interactive software.

Lanre Olokoba

Written by

Trying to better understand life through philosophy, mathematics, and computer science. Proprietor @ NatSuite. Founding member @ Homedeck.

NatSuite

NatSuite

Cross-platform media tools for developing interactive software.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade