Using Microphones
Feature Rich User Audio
NatDevice provides access to hardware microphones on all platforms it supports. These microphones will stream audio directly to the client on a dedicated audio thread. The audio data can then be processed by the user.
When building for iOS, you must enable the Prepare iOS for Recording
setting in Player Settings.
Finding a Microphone
We begin by finding a microphone with a device query:
Streaming Audio
Audio devices work by streaming audio buffers to a user-provided delegate function:
The provided delegate is invoked with AudioBuffer
instances as they are streamed from the audio device:
The audio buffers always contain linear PCM samples interleaved by channel.
The provided delegate is not guaranteed to be invoked on the Unity main thread, so refrain from using Unity APIs within this method.
Specifying the Audio Format
Audio devices allow for specifying the format of the audio from the microphone. The audio format is defined by the sampleRate
and channelCount
:
Stopping Streaming
When you are done with the microphone, you must stop it:
Last updated