A wrapper for Unity's Microphone class. Proving easy APIs for mic input and management.
Scripting API page and more documentation coming soon.
Mic.Init()
to initialize UniMic
Mic.AvailableDevices
to get a list of available Mic.Device
objects
The following API is available in Mic.Device
:
DEFAULT_FRAME_DURATION_MS
the default length of the frame in milliseconds.OnStartRecording
event fired when the device starts recordingOnFrameCollected
event fired when the device has gathered PCM data for one frame of user defined duration. Parameters:int, float[]
the channel count and PCM float array of the frame
OnStopRecording
event fired when the device stops recordingName
gets the name of the deviceMaxFrequency
is the highest sampling frequency supported by the deviceMinFrequency
is the lowest sampling frequency supported by the deviceVolumeMultiplier
increases/decreases volume by multiplying PCM samplesSupportsAnyFrequency
is true if the recording device supports any sampling frequenySamplingFrequency
is the user defined frequency at which is device will recordFrameDurationMS
is the audio duration of a single PCM frame that this device will report in theOnFrameCollected
eventFrameLength
is the length of the float PCM array this device will report in theOnFrameCollected
eventStartRecoring()
starts the device recording at the highest supported sampling frequency and the default frame duration defined byDEFAULT_FRAME_DURATION_MS
StartRecording(int frameDurationMS)
starts the device recording at the highest supported sampling frequency and the user defined frame durationStartRecording(int samplingFrequency, int frameDurationMS)
starts the device recording at the user defined sampling frequency and frame durationStopRecording()
stops the device recordingIsRecording
returns if the device is currently recording audio
MicAudioSource
component is available for playing back microphone feed. This class is also a good reference for writing your own code for incoming audio data. This class includes:
autoStart
configurable in the editor. Whether the component should automatically start playing back audio from the first device detectedDevice
is a reference to the device this object it currently playingbufferDurationMS
is the length in milliseconds of the internal audio buffer that the object uses. The value defined here is also the time it would take for playback to start and the latency between audio capture and playbackSetDeviceByName(string deviceName, bool autoStart = false)
changes the device this instance is playing. IfautoStart
is true, it automatically starts playing the audio being captured by the new device.SetDevice(Mic.Device device, bool autoStart = false)
similar toSetDeviceByName
except it takes aMic.Device
object as the first parameter. This is recommended overSetDeviceByName
StartRecording
starts/resumes the recording. A device MUST be registered usingSetDevice
orSetDeviceByName
method before calling this.StopRecording
stops the recording.
View Basic MicAudioSource Sample
for single mic sample
View Multiple Mic UI Sample
for a more complicated sample that shows all the available mics on a UI and allows you to mute/unmute them.
Some Xiaomi phones may prevent side loaded APKs from functioning.
There is no AEC (Acoustic Echo Cancelletion). If you're trying the samples be sure to use headphones to avoid creating a feedback loop.