1e41f4b71Sopenharmony_ci# Managing Global Audio Input Devices 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciIf a device is connected to multiple audio input devices, you can use **AudioRoutingManager** to specify an audio input device to record audio. For details about the API reference, see [AudioRoutingManager](../../reference/apis-audio-kit/js-apis-audio.md#audioroutingmanager9). 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## Creating an AudioRoutingManager Instance 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciBefore using **AudioRoutingManager** to manage audio devices, import the audio module and create an **AudioManager** instance. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci```ts 10e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit'; // Import the audio module. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_cilet audioManager = audio.getAudioManager(); // Create an AudioManager instance. 13e41f4b71Sopenharmony_cilet audioRoutingManager = audioManager.getRoutingManager(); // Call an API of AudioManager to create an AudioRoutingManager instance. 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## Supported Audio Input Device Types 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciThe table below lists the supported audio input devices. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci| Name| Value| Description| 21e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 22e41f4b71Sopenharmony_ci| WIRED_HEADSET | 3 | Wired headset with a microphone.| 23e41f4b71Sopenharmony_ci| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links.| 24e41f4b71Sopenharmony_ci| MIC | 15 | Microphone.| 25e41f4b71Sopenharmony_ci| USB_HEADSET | 22 | USB Type-C headset.| 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## Obtaining Input Device Information 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciUse **getDevices()** to obtain information about all the input devices. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci```ts 32e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit'; 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciaudioRoutingManager.getDevices(audio.DeviceFlag.INPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => { 35e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that the device list is obtained.'); 36e41f4b71Sopenharmony_ci}); 37e41f4b71Sopenharmony_ci``` 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci## Listening for Device Connection State Changes 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciSet a listener to listen for changes of the device connection state. When a device is connected or disconnected, a callback is triggered. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci```ts 44e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit'; 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci// Listen for connection state changes of audio devices. 47e41f4b71Sopenharmony_ciaudioRoutingManager.on('deviceChange', audio.DeviceFlag.INPUT_DEVICES_FLAG, (deviceChanged: audio.DeviceChangeAction) => { 48e41f4b71Sopenharmony_ci console.info('device change type: ' + deviceChanged.type); // Device connection state change. The value 0 means that the device is connected and 1 means that the device is disconnected. 49e41f4b71Sopenharmony_ci console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length); 50e41f4b71Sopenharmony_ci console.info('device change descriptor: ' + deviceChanged.deviceDescriptors[0].deviceRole); // Device role. 51e41f4b71Sopenharmony_ci console.info('device change descriptor: ' + deviceChanged.deviceDescriptors[0].deviceType); // Device type. 52e41f4b71Sopenharmony_ci}); 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci// Cancel the listener for the connection state changes of audio devices. 55e41f4b71Sopenharmony_ciaudioRoutingManager.off('deviceChange', (deviceChanged: audio.DeviceChangeAction) => { 56e41f4b71Sopenharmony_ci console.info('Should be no callback.'); 57e41f4b71Sopenharmony_ci}); 58e41f4b71Sopenharmony_ci``` 59e41f4b71Sopenharmony_ci<!--Del--> 60e41f4b71Sopenharmony_ci## Selecting an Audio Input Device (for System Applications only) 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciCurrently, only one input device can be selected, and the device ID is used as the unique identifier. For details about audio device descriptors, see [AudioDeviceDescriptors](../../reference/apis-audio-kit/js-apis-audio.md#audiodevicedescriptors). 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci> **NOTE** 65e41f4b71Sopenharmony_ci> 66e41f4b71Sopenharmony_ci> The user can connect to a group of audio devices (for example, a pair of Bluetooth headsets), but the system treats them as one device (a group of devices that share the same device ID). 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci```ts 69e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit'; 70e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_cilet inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{ 73e41f4b71Sopenharmony_ci deviceRole : audio.DeviceRole.INPUT_DEVICE, 74e41f4b71Sopenharmony_ci deviceType : audio.DeviceType.EARPIECE, 75e41f4b71Sopenharmony_ci id : 1, 76e41f4b71Sopenharmony_ci name : "", 77e41f4b71Sopenharmony_ci address : "", 78e41f4b71Sopenharmony_ci sampleRates : [44100], 79e41f4b71Sopenharmony_ci channelCounts : [2], 80e41f4b71Sopenharmony_ci channelMasks : [0], 81e41f4b71Sopenharmony_ci networkId : audio.LOCAL_NETWORK_ID, 82e41f4b71Sopenharmony_ci interruptGroupId : 1, 83e41f4b71Sopenharmony_ci volumeGroupId : 1, 84e41f4b71Sopenharmony_ci displayName : "" 85e41f4b71Sopenharmony_ci}]; 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ciasync function getRoutingManager() { 88e41f4b71Sopenharmony_ci audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => { 89e41f4b71Sopenharmony_ci console.info('Invoke selectInputDevice succeeded.'); 90e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 91e41f4b71Sopenharmony_ci console.error(`Invoke selectInputDevice failed, code is ${err.code}, message is ${err.message}`); 92e41f4b71Sopenharmony_ci }); 93e41f4b71Sopenharmony_ci} 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci``` 96e41f4b71Sopenharmony_ci<!--DelEnd--> 97