Class: Microphone

Microphone

Microphone class is used for representing microphones plugged in to the computer (each instance represents a single microphone). The list of all available microphones can be got with getMicrophones method of MindSDK class. Microphone class implements MediaStreamAudioSupplier interface, so it can be used as a source of audio for local MediaStream.

let microphone = MindSDK.getMicrophones()[0];
if (microphone) {
    let myStream = MindSDK.createMediaStream(microphone, null);
    me.setMediaStream(myStream);
    microphone.acquire().catch(function(error) {
        alert("Microphone can't be acquired: " + error);
    });
} else {
    alert("Microphone isn't plugged in");
}

Classes

Microphone

Methods

acquire() → {Promise}

Starts microphone recording. This is an asynchronous operation which assumes acquiring the underlying microphone device and distributing microphone's audio among all consumers. This method returns a Promise that resolves with no value (if the microphone recording starts successfully) or rejects with an Error (if there is no permission to access the microphone or if the microphone was unplugged). If the microphone recording has been already started, this method returns resolved Promise.

Returns:

The promise that either resolves with no value or rejects with an Error.

Type
Promise

getId() → {String}

Returns the ID of the microphone. The ID is unique among all microphones and never changes.

Returns:

The ID of the microphone.

Type
String

getLabel() → {String}

Returns the label of the microphone.

Returns:

The label of the microphone.

Type
String

isOperational()

Deprecated:
  • To check if the microphone is operational or not, look at the list of the available microphone — if the microphone is there, then it is operational, otherwise it isn't.

release()

Stops microphone recording. This is a synchronous operation which assumes revoking the previously distributed microphone's audio and releasing the underlying microphone device. The stopping is idempotent: the method does nothing if the microphone is not acquired.

setListener(listener)

Sets the listener which should be notified of all events related to the microphone.

Parameters:
Name Type Description
listener MicrophoneListener

The listener which should be notified of all events related to the microphone.