Skip to main content
Skip table of contents

RapportMicrophone

Description

The RapportMicrophone class is a public implementation of the IRapportAudioInput interface. It provides a robust, reference-counted system for managing a microphone device, allowing multiple parts of an application to safely access the same microphone input without conflicts.

Namespace: SpeechGraphics.Rapport.Audio

Fields

Name

Type

Description

UserMute

bool

A flag that, when true, prevents the user's voice from being sent to the Rapport character. This allows for client-side control over the audio input.

Properties

Name

Type

Description

SystemMute

bool

A property that gets or sets the system-level mute state, as required by the IRapportAudioInput interface. When true, it indicates that the Rapport character is not in an interruptible state.

IsMuted

bool

A read-only property that returns true if either UserMute or SystemMute is true, effectively checking if the audio stream is currently silenced.

Frequency

int

The sample rate of the active microphone, in Hertz (Hz). This value is retrieved from the internal microphone instance.

MicrophoneReadLatency

double

The latency, in seconds, between when audio data is read from the physical microphone and when it is available to be sent to the server.

Methods

Name

Type

Description

SetDevice(string name)

void

Changes the active microphone device. This method first releases the reference to the currently active microphone and then acquires a new one for the specified name.

Parameters:

  • name (string): The name of the new microphone device to use.

Update()

void

This method is called internally by the system. It forwards the call to the internal microphone instance, allowing it to perform per-frame buffer updates.

OnAudioRead(int sampleOffset, float[] buffer)

void

Called internally from the audio thread to get samples from the microphone and populate the provided buffer. This method first checks the IsMuted state and, if muted, fills the buffer with silence (zeros) instead of microphone data.

Parameters:

  • sampleOffset (int): The offset in samples since the last call.

  • buffer (float[]): The buffer array to be populated with audio samples.

Lifecycle and Reference Counting

The RapportMicrophone class uses a static dictionary and reference counting to ensure that only a single instance of a microphone device is ever active at one time, even if multiple RapportMicrophone objects are created for the same device. The private static methods GetOrCreateInternal and ReleaseInternal handle this logic. The destructor (~RapportMicrophone()) automatically calls ReleaseInternal to decrement the reference count when an object is destroyed.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.