Microphone

class Microphone : System.Object

Provides microphones capture features.

string Name

Returns the friendly name of the microphone.

System.TimeSpan BufferDuration

Gets or sets the capture buffer duration. This value must be greater than 100 milliseconds, lower than 1000 milliseconds, and must be 10 milliseconds aligned (BufferDuration % 10 == 10).

readonly bool IsHeadset

Determines if the microphone is a wired headset. Note: XNA could know if a headset microphone was plugged in an Xbox 360 controller but MonoGame can’t. Hence, this is always true on mobile platforms, and always false otherwise.

readonly int SampleRate

Returns the sample rate of the captured audio. Note: default value is 44100hz

readonly MicrophoneState State

Returns the state of the Microphone.

readonly System.Collections.ObjectModel.ReadOnlyCollection<Microphone> All

Returns all compatible microphones.

readonly Microphone Default

Returns the default microphone.

public System.TimeSpan GetSampleDuration(int sizeInBytes)

Returns the duration based on the size of the buffer (assuming 16-bit PCM data).

Parameters:
  • sizeInBytes (int) – Size, in bytes
Returns:

TimeSpan of the duration.

public int GetSampleSizeInBytes(System.TimeSpan duration)

Returns the size, in bytes, of the array required to hold the specified duration of 16-bit PCM data.

Parameters:
  • duration (System.TimeSpan) – TimeSpan of the duration of the sample.
Returns:

Size, in bytes, of the buffer.

public void Start()

Starts microphone capture.

public void Stop()

Stops microphone capture.

public int GetData(System.Byte[] buffer)

Gets the latest available data from the microphone.

Parameters:
  • buffer (System.Byte[]) – Buffer, in bytes, of the captured data (16-bit PCM).
Returns:

The buffer size, in bytes, of the captured data.

public int GetData(System.Byte[] buffer, int offset, int count)

Gets the latest available data from the microphone.

Parameters:
  • buffer (System.Byte[]) – Buffer, in bytes, of the captured data (16-bit PCM).
  • offset (int) – Byte offset.
  • count (int) – Amount, in bytes.
Returns:

The buffer size, in bytes, of the captured data.

public void add_BufferReady(System.EventHandler<EventArgs> value)
Parameters:
  • value (System.EventHandler<EventArgs>) –
public void remove_BufferReady(System.EventHandler<EventArgs> value)
Parameters:
  • value (System.EventHandler<EventArgs>) –
void UpdateMicrophones()
void StopMicrophones()
void PlatformStart()
void PlatformStop()
void Update()
int PlatformGetData(System.Byte[] buffer, int offset, int count)
Parameters:
  • buffer (System.Byte[]) –
  • offset (int) –
  • count (int) –