AudioDevice
class NatML.Devices.AudioDevice : IMediaDevice<AudioBuffer>
This class provides an abstraction for hardware microphones.
Audio devices can be identified either with a unique ID or with a device name.
/// <summary>
/// Device unique ID.
/// </summary>
string uniqueID { get; }
/// <summary>
/// Display friendly device name.
/// </summary>
string name { get; }
/// <summary>
/// Device location.
/// </summary>
DeviceLocation location { get; }
/// <summary>
/// Device is the default device for its media type.
/// </summary>
bool defaultForMediaType { get; }
/// <summary>
/// Enable or disable Adaptive Echo Cancellation (AEC)
/// </summary>
bool echoCancellation { get; set; }
Some audio devices support adaptive echo cancellation, which removes sound that originates from the device itself. This is useful for voice call applications for removing any audio feedback from the speakers.
Echo cancellation usually attenuates the volume, so the audio might be quieter than when AEC is disabled.
Audio devices also report whether they support echo cancellation:
/// <summary>
/// Is echo cancellation supported?
/// </summary>
bool echoCancellationSupported { get; }
Audio devices allow for inspecting the audio format that will be used to stream audio data. This format is defined by the sample rate and channel count.
/// <summary>
/// Audio sample rate.
/// </summary>
int sampleRate { get; set; }
The device sample rate is specified in Hertz (Hz).
Audio devices do not support arbitrary sample rates. It is recommended to use one of 8000Hz, 16000Hz, 22050Hz, 24000Hz, 44100Hz, or 48000Hz.
/// <summary>
/// Audio channel count.
/// </summary>
int channelCount { get; set; }
The audio channel count. This will always be a non-negative number, typically 1 (mono) or 2 (stereo).
Audio devices are always guaranteed to support mono audio. No other channel count is guaranteed.
/// <summary>
/// Is the device running?
/// </summary>
bool running { get; }
/// <summary>
/// Start running.
/// </summary>
/// <param name="handler">Delegate to receive audio buffers.</param>
void StartRunning (Action<AudioBuffer> handler);
Audio devices stream sample buffers to the specified delegate as they are reported by the hardware microphone. The audio buffers will always contain single-precision floating-point (
float
) linear PCM data, interleaved by channel (when channelCount
is greater than 1).The provided
handler
is always invoked on a dedicated audio recording thread, separate from the Unity main thread./// <summary>
/// Stop running.
/// </summary>
void StopRunning ();
/// <summary>
/// Event raised when the device is disconnected.
/// </summary>
event Action onDisconnected { add; remove; }
Refer to the Handling Device Disconnection section of the
IMediaDevice
interface for more information.This event is not guaranteed to be raised on the Unity main thread.
Last modified 10mo ago