Select the microphone

Dragon Copilot SDK for JavaScript provides information on connected microphones and enables you to set the preferred microphone for recording. You can also manage the microphone audio stream lifecycle independently of recording.

  • Use DragonCopilotSDK.dragon.microphone.events.addEventListener and DragonCopilotSDK.dragon.microphone.events.removeEventListener to add/remove listeners for microphone events. The microphoneListChanged event provides your integration with a list of available microphones.

  • Pass the preferred microphone to the initialization options, or use setPreferredMicrophone to pass the preferred microphone to the Dragon Copilot SDK after initialization.

  • Use manageMicrophoneStream to explicitly acquire or release the microphone audio stream.

  • For information on supported microphones, see: Microphones for dictation and Microphones for ambient recording.

Event Description
microphoneListChanged Dispatched when the list of available microphones has changed.

Get available microphones

To receive updates on available microphones, attach an event listener to the microphoneListChanged event.

The Dragon Copilot SDK raises a microphoneListChanged event in the following scenarios:

  • You initialize the SDK.

  • A device is connected or disconnected.

  • The current device changes.

Create this event listener before you initialize the Dragon Copilot SDK, so that you get the initial list of devices.

The event contains the full list of available microphones and a changeType string, which describes what change has occurred. For information on the microphone list, see MicrophoneListChangedDetail in the API reference documentation. Each microphone is listed with label, displayName, isCurrentDevice and isButtonDevice properties.

  • Use the isCurrentMic property to show which device is currently selected. Button events only work for the current device.

  • Use the displayName to show the microphone to the user; use label when setting the preferred microphone. The label is provided by the browser's MediaDevices API.

changeType can be one of the following values:

changeType value Description
"preferredMicConnectedNotRecording" While not recording, the preferred microphone is plugged in. The preferred microphone is used when recording starts.
"preferredMicConnectedWhileRecording" While recording, the preferred microphone is plugged in.
"preferredMicChangedWhileRecording" While recording, the preferred microphone is changed. This stops the recording. The new preferred microphone is used when recording starts.
"currentMicDisconnectedNotRecording" While not recording, the current microphone is unplugged. The preferred microphone or default microphone is used when recording starts.
"currentMicDisconnectedWhileRecording" While recording, the current microphone is unplugged. This stops the recording. The preferred microphone or default microphone is used when recording starts.
"other" Any change not covered by the other values.

Set the preferred microphone on initialization

Use the preferredMicrophone initialization option.

If you don't provide a preferred microphone during initialization, the user's preferred microphone from their Dragon Copilot settings is used automatically.

Set the preferred microphone after initialization

To set the preferred microphone after the Dragon Copilot SDK is initialized, use DragonCopilotSDK.dragon.microphone.setPreferredMicrophone.

If recording is active when this method is called and the preferred microphone changes, recording stops. The next time recording starts, the most recently set preferred microphone will be used.

The Dragon Copilot SDK falls back between microphones in this order:

  1. Preferred microphone (if specified)

  2. System default microphone (if supported by the browser)

  3. First available microphone

If persistence is needed, your integration is responsible for saving the selected microphone and setting it again when the Dragon Copilot SDK is next initialized.

Handle microphone permissions

Use the Permissions API to handle microphone permissions.

Manage the microphone stream

Use DragonCopilotSDK.dragon.microphone.manageMicrophoneStream to control the microphone audio stream lifecycle. This method explicitly releases and acquires the microphone independently of recording.

The method accepts an action parameter:

  • "release": Stops all audio tracks and clears the internal cache, so other apps or workflows can use the microphone. Use this, for example, when the user navigates away or during idle periods.
  • "acquire": Acquires a new audio stream with default constraints if one isn't already cached and active.

The Dragon Copilot SDK automatically re-acquires the microphone when the next recording session starts and releases the microphone when recording stops.

import { microphone } from "dragon-speech-sdk";

// Release the microphone when the user navigates away or during idle periods
await microphone.manageMicrophoneStream("release");

// Acquire the microphone before starting a recording session
await microphone.manageMicrophoneStream("acquire");

See also

API reference