146f34cbfSopenharmony_ci# Audio 246f34cbfSopenharmony_ci 346f34cbfSopenharmony_ci## Introduction 446f34cbfSopenharmony_ci 546f34cbfSopenharmony_ciThe audio framework is used to implement audio-related features, including audio playback, audio recording, volume management, and device management. 646f34cbfSopenharmony_ci 746f34cbfSopenharmony_ci**Figure 1** Architecture of the audio framework 846f34cbfSopenharmony_ci 946f34cbfSopenharmony_ci 1046f34cbfSopenharmony_ci 1146f34cbfSopenharmony_ci 1246f34cbfSopenharmony_ci### Basic Concepts 1346f34cbfSopenharmony_ci 1446f34cbfSopenharmony_ci- **Sampling** 1546f34cbfSopenharmony_ci 1646f34cbfSopenharmony_ci Sampling is a process to obtain discrete-time signals by extracting samples from analog signals in a continuous time domain at a specific interval. 1746f34cbfSopenharmony_ci 1846f34cbfSopenharmony_ci- **Sampling rate** 1946f34cbfSopenharmony_ci 2046f34cbfSopenharmony_ci Sampling rate is the number of samples extracted from a continuous signal per second to form a discrete signal. It is measured in Hz. Generally, the human hearing range is from 20 Hz to 20 kHz. Common audio sampling rates include 8 kHz, 11.025 kHz, 22.05 kHz, 16 kHz, 37.8 kHz, 44.1 kHz, 48 kHz, 96 kHz, and 192 kHz. 2146f34cbfSopenharmony_ci 2246f34cbfSopenharmony_ci- **Channel** 2346f34cbfSopenharmony_ci 2446f34cbfSopenharmony_ci Channels refer to different spatial positions where independent audio signals are recorded or played. The number of channels is the number of audio sources used during audio recording, or the number of speakers used for audio playback. 2546f34cbfSopenharmony_ci 2646f34cbfSopenharmony_ci- **Audio frame** 2746f34cbfSopenharmony_ci 2846f34cbfSopenharmony_ci Audio data is in stream form. For the convenience of audio algorithm processing and transmission, it is generally agreed that a data amount in a unit of 2.5 to 60 milliseconds is one audio frame. This unit is called sampling time, and its length is specific to codecs and the application requirements. 2946f34cbfSopenharmony_ci 3046f34cbfSopenharmony_ci- **PCM** 3146f34cbfSopenharmony_ci 3246f34cbfSopenharmony_ci Pulse code modulation (PCM) is a method used to digitally represent sampled analog signals. It converts continuous-time analog signals into discrete-time digital signal samples. 3346f34cbfSopenharmony_ci 3446f34cbfSopenharmony_ci## Directory Structure 3546f34cbfSopenharmony_ci 3646f34cbfSopenharmony_ciThe structure of the repository directory is as follows: 3746f34cbfSopenharmony_ci 3846f34cbfSopenharmony_ci``` 3946f34cbfSopenharmony_ci/foundation/multimedia/audio_standard # Service code of the audio framework 4046f34cbfSopenharmony_ci├── frameworks # Framework code 4146f34cbfSopenharmony_ci│ ├── native # Internal native API implementation 4246f34cbfSopenharmony_ci│ └── js # External JS API implementation 4346f34cbfSopenharmony_ci│ └── napi # External native API implementation 4446f34cbfSopenharmony_ci├── interfaces # API code 4546f34cbfSopenharmony_ci│ ├── inner_api # Internal APIs 4646f34cbfSopenharmony_ci│ └── kits # External APIs 4746f34cbfSopenharmony_ci├── sa_profile # Service configuration profile 4846f34cbfSopenharmony_ci├── services # Service code 4946f34cbfSopenharmony_ci├── LICENSE # License file 5046f34cbfSopenharmony_ci└── bundle.json # Build file 5146f34cbfSopenharmony_ci``` 5246f34cbfSopenharmony_ci 5346f34cbfSopenharmony_ci## Usage Guidelines 5446f34cbfSopenharmony_ci 5546f34cbfSopenharmony_ci### Audio Playback 5646f34cbfSopenharmony_ci 5746f34cbfSopenharmony_ciYou can use the APIs provided in the current repository to convert audio data into audible analog signals, play the audio signals using output devices, and manage playback tasks. The following describes how to use the **AudioRenderer** class to develop the audio playback feature: 5846f34cbfSopenharmony_ci 5946f34cbfSopenharmony_ci1. Call **Create()** with the required stream type to create an **AudioRenderer** instance. 6046f34cbfSopenharmony_ci 6146f34cbfSopenharmony_ci ``` 6246f34cbfSopenharmony_ci AudioStreamType streamType = STREAM_MUSIC; // Stream type example. 6346f34cbfSopenharmony_ci std::unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(streamType); 6446f34cbfSopenharmony_ci ``` 6546f34cbfSopenharmony_ci 6646f34cbfSopenharmony_ci2. (Optional) Call the static APIs **GetSupportedFormats()**, **GetSupportedChannels()**, **GetSupportedEncodingTypes()**, and **GetSupportedSamplingRates()** to obtain the supported values of parameters. 6746f34cbfSopenharmony_ci3. Prepare the device and call **SetParams()** to set parameters. 6846f34cbfSopenharmony_ci 6946f34cbfSopenharmony_ci ``` 7046f34cbfSopenharmony_ci AudioRendererParams rendererParams; 7146f34cbfSopenharmony_ci rendererParams.sampleFormat = SAMPLE_S16LE; 7246f34cbfSopenharmony_ci rendererParams.sampleRate = SAMPLE_RATE_44100; 7346f34cbfSopenharmony_ci rendererParams.channelCount = STEREO; 7446f34cbfSopenharmony_ci rendererParams.encodingType = ENCODING_PCM; 7546f34cbfSopenharmony_ci 7646f34cbfSopenharmony_ci audioRenderer->SetParams(rendererParams); 7746f34cbfSopenharmony_ci ``` 7846f34cbfSopenharmony_ci 7946f34cbfSopenharmony_ci4. (Optional) Call **GetParams(rendererParams)** to obtain the parameters set. 8046f34cbfSopenharmony_ci5. Call **Start()** to start an audio playback task. 8146f34cbfSopenharmony_ci6. Call **GetBufferSize()** to obtain the length of the buffer to be written. 8246f34cbfSopenharmony_ci 8346f34cbfSopenharmony_ci ``` 8446f34cbfSopenharmony_ci audioRenderer->GetBufferSize(bufferLen); 8546f34cbfSopenharmony_ci ``` 8646f34cbfSopenharmony_ci 8746f34cbfSopenharmony_ci7. Call **bytesToWrite()** to read the audio data from the source (such as an audio file) and pass it to a byte stream. You can repeatedly call this API to write rendering data. 8846f34cbfSopenharmony_ci 8946f34cbfSopenharmony_ci ``` 9046f34cbfSopenharmony_ci bytesToWrite = fread(buffer, 1, bufferLen, wavFile); 9146f34cbfSopenharmony_ci while ((bytesWritten < bytesToWrite) && ((bytesToWrite - bytesWritten) > minBytes)) { 9246f34cbfSopenharmony_ci bytesWritten += audioRenderer->Write(buffer + bytesWritten, bytesToWrite - bytesWritten); 9346f34cbfSopenharmony_ci if (bytesWritten < 0) 9446f34cbfSopenharmony_ci break; 9546f34cbfSopenharmony_ci } 9646f34cbfSopenharmony_ci ``` 9746f34cbfSopenharmony_ci 9846f34cbfSopenharmony_ci8. Call **Drain()** to clear the streams to be played. 9946f34cbfSopenharmony_ci9. Call **Stop()** to stop the output. 10046f34cbfSopenharmony_ci10. After the playback task is complete, call **Release()** to release resources. 10146f34cbfSopenharmony_ci 10246f34cbfSopenharmony_ciThe preceding steps describe the basic development scenario of audio playback. 10346f34cbfSopenharmony_ci 10446f34cbfSopenharmony_ci 10546f34cbfSopenharmony_ci11. Call **SetVolume(float)** and **GetVolume()** to set and obtain the audio stream volume, which ranges from 0.0 to 1.0. 10646f34cbfSopenharmony_ci 10746f34cbfSopenharmony_ciFor details, see [**audio_renderer.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiorenderer/include/audio_renderer.h) and [**audio_info.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiocommon/include/audio_info.h). 10846f34cbfSopenharmony_ci 10946f34cbfSopenharmony_ci### Audio Recording 11046f34cbfSopenharmony_ci 11146f34cbfSopenharmony_ciYou can use the APIs provided in the current repository to record audio via an input device, convert the audio into audio data, and manage recording tasks. The following describes how to use the **AudioCapturer** class to develop the audio recording feature: 11246f34cbfSopenharmony_ci 11346f34cbfSopenharmony_ci1. Call **Create()** with the required stream type to create an **AudioCapturer** instance. 11446f34cbfSopenharmony_ci 11546f34cbfSopenharmony_ci ``` 11646f34cbfSopenharmony_ci AudioStreamType streamType = STREAM_MUSIC; 11746f34cbfSopenharmony_ci std::unique_ptr<AudioCapturer> audioCapturer = AudioCapturer::Create(streamType); 11846f34cbfSopenharmony_ci ``` 11946f34cbfSopenharmony_ci 12046f34cbfSopenharmony_ci2. (Optional) Call the static APIs **GetSupportedFormats()**, **GetSupportedChannels()**, **GetSupportedEncodingTypes()**, and **GetSupportedSamplingRates()** to obtain the supported values of parameters. 12146f34cbfSopenharmony_ci3. Prepare the device and call **SetParams()** to set parameters. 12246f34cbfSopenharmony_ci 12346f34cbfSopenharmony_ci ``` 12446f34cbfSopenharmony_ci AudioCapturerParams capturerParams; 12546f34cbfSopenharmony_ci capturerParams.sampleFormat = SAMPLE_S16LE; 12646f34cbfSopenharmony_ci capturerParams.sampleRate = SAMPLE_RATE_44100; 12746f34cbfSopenharmony_ci capturerParams.channelCount = STEREO; 12846f34cbfSopenharmony_ci capturerParams.encodingType = ENCODING_PCM; 12946f34cbfSopenharmony_ci 13046f34cbfSopenharmony_ci audioCapturer->SetParams(capturerParams); 13146f34cbfSopenharmony_ci ``` 13246f34cbfSopenharmony_ci 13346f34cbfSopenharmony_ci4. (Optional) Call **GetParams(capturerParams)** to obtain the parameters set. 13446f34cbfSopenharmony_ci5. Call **Start()** to start an audio recording task. 13546f34cbfSopenharmony_ci6. Call **GetBufferSize()** to obtain the length of the buffer to be written. 13646f34cbfSopenharmony_ci 13746f34cbfSopenharmony_ci ``` 13846f34cbfSopenharmony_ci audioCapturer->GetBufferSize(bufferLen); 13946f34cbfSopenharmony_ci ``` 14046f34cbfSopenharmony_ci 14146f34cbfSopenharmony_ci7. Call **bytesRead()** to read the captured audio data and convert it to a byte stream. The application will repeatedly call this API to read data until it is manually stopped. 14246f34cbfSopenharmony_ci 14346f34cbfSopenharmony_ci ``` 14446f34cbfSopenharmony_ci // set isBlocking = true/false for blocking/non-blocking read 14546f34cbfSopenharmony_ci bytesRead = audioCapturer->Read(*buffer, bufferLen, isBlocking); 14646f34cbfSopenharmony_ci while (numBuffersToCapture) { 14746f34cbfSopenharmony_ci bytesRead = audioCapturer->Read(*buffer, bufferLen, isBlockingRead); 14846f34cbfSopenharmony_ci if (bytesRead < 0) { 14946f34cbfSopenharmony_ci break; 15046f34cbfSopenharmony_ci } else if (bytesRead > 0) { 15146f34cbfSopenharmony_ci fwrite(buffer, size, bytesRead, recFile); // example shows writes the recorded data into a file 15246f34cbfSopenharmony_ci numBuffersToCapture--; 15346f34cbfSopenharmony_ci } 15446f34cbfSopenharmony_ci } 15546f34cbfSopenharmony_ci ``` 15646f34cbfSopenharmony_ci 15746f34cbfSopenharmony_ci8. (Optional) Call **Flush()** to clear the recording stream buffer. 15846f34cbfSopenharmony_ci9. Call **Stop()** to stop recording. 15946f34cbfSopenharmony_ci10. After the recording task is complete, call **Release()** to release resources. 16046f34cbfSopenharmony_ci 16146f34cbfSopenharmony_ciFor details, see [**audio_capturer.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiocapturer/include/audio_capturer.h) and [**audio_info.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiocommon/include/audio_info.h). 16246f34cbfSopenharmony_ci 16346f34cbfSopenharmony_ci### Audio Management 16446f34cbfSopenharmony_ciYou can use the APIs provided in the [**audio_system_manager.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h) to control the volume and devices. 16546f34cbfSopenharmony_ci1. Call **GetInstance()** to obtain an **AudioSystemManager** instance. 16646f34cbfSopenharmony_ci ``` 16746f34cbfSopenharmony_ci AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); 16846f34cbfSopenharmony_ci ``` 16946f34cbfSopenharmony_ci#### Volume Control 17046f34cbfSopenharmony_ci2. Call **GetMaxVolume()** and **GetMinVolume()** to obtain the maximum volume and minimum volume allowed for an audio stream. 17146f34cbfSopenharmony_ci ``` 17246f34cbfSopenharmony_ci AudioVolumeType streamType = AudioVolumeType::STREAM_MUSIC; 17346f34cbfSopenharmony_ci int32_t maxVol = audioSystemMgr->GetMaxVolume(streamType); 17446f34cbfSopenharmony_ci int32_t minVol = audioSystemMgr->GetMinVolume(streamType); 17546f34cbfSopenharmony_ci ``` 17646f34cbfSopenharmony_ci3. Call **SetVolume()** and **GetVolume()** to set and obtain the volume of the audio stream, respectively. 17746f34cbfSopenharmony_ci ``` 17846f34cbfSopenharmony_ci int32_t result = audioSystemMgr->SetVolume(streamType, 10); 17946f34cbfSopenharmony_ci int32_t vol = audioSystemMgr->GetVolume(streamType); 18046f34cbfSopenharmony_ci ``` 18146f34cbfSopenharmony_ci4. Call **SetMute()** and **IsStreamMute** to set and obtain the mute status of the audio stream, respectively. 18246f34cbfSopenharmony_ci ``` 18346f34cbfSopenharmony_ci int32_t result = audioSystemMgr->SetMute(streamType, true); 18446f34cbfSopenharmony_ci bool isMute = audioSystemMgr->IsStreamMute(streamType); 18546f34cbfSopenharmony_ci ``` 18646f34cbfSopenharmony_ci5. Call **SetRingerMode()** and **GetRingerMode()** to set and obtain the ringer mode, respectively. The supported ringer modes are the enumerated values of **AudioRingerMode** defined in [**audio_info.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiocommon/include/audio_info.h). 18746f34cbfSopenharmony_ci ``` 18846f34cbfSopenharmony_ci int32_t result = audioSystemMgr->SetRingerMode(RINGER_MODE_SILENT); 18946f34cbfSopenharmony_ci AudioRingerMode ringMode = audioSystemMgr->GetRingerMode(); 19046f34cbfSopenharmony_ci ``` 19146f34cbfSopenharmony_ci6. Call **SetMicrophoneMute()** and **IsMicrophoneMute()** to set and obtain the mute status of the microphone, respectively. 19246f34cbfSopenharmony_ci ``` 19346f34cbfSopenharmony_ci int32_t result = audioSystemMgr->SetMicrophoneMute(true); 19446f34cbfSopenharmony_ci bool isMicMute = audioSystemMgr->IsMicrophoneMute(); 19546f34cbfSopenharmony_ci ``` 19646f34cbfSopenharmony_ci#### Device Control 19746f34cbfSopenharmony_ci7. Call **GetDevices**, **deviceType_**, and **deviceRole_** to obtain information about the audio input and output devices. For details, see the enumerated values of **DeviceFlag**, **DeviceType**, and **DeviceRole** defined in [**audio_info.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiocommon/include/audio_info.h). 19846f34cbfSopenharmony_ci ``` 19946f34cbfSopenharmony_ci DeviceFlag deviceFlag = OUTPUT_DEVICES_FLAG; 20046f34cbfSopenharmony_ci vector<sptr<AudioDeviceDescriptor>> audioDeviceDescriptors 20146f34cbfSopenharmony_ci = audioSystemMgr->GetDevices(deviceFlag); 20246f34cbfSopenharmony_ci sptr<AudioDeviceDescriptor> audioDeviceDescriptor = audioDeviceDescriptors[0]; 20346f34cbfSopenharmony_ci cout << audioDeviceDescriptor->deviceType_; 20446f34cbfSopenharmony_ci cout << audioDeviceDescriptor->deviceRole_; 20546f34cbfSopenharmony_ci ``` 20646f34cbfSopenharmony_ci8. Call **SetDeviceActive()** and **IsDeviceActive()** to activate or deactivate an audio device and obtain the device activation status, respectively. 20746f34cbfSopenharmony_ci ``` 20846f34cbfSopenharmony_ci ActiveDeviceType deviceType = SPEAKER; 20946f34cbfSopenharmony_ci int32_t result = audioSystemMgr->SetDeviceActive(deviceType, true); 21046f34cbfSopenharmony_ci bool isDevActive = audioSystemMgr->IsDeviceActive(deviceType); 21146f34cbfSopenharmony_ci ``` 21246f34cbfSopenharmony_ci9. (Optional) Call other APIs, such as **IsStreamActive()**, **SetAudioParameter()**, and **GetAudioParameter()**, provided in [**audio_system_manager.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h) if required. 21346f34cbfSopenharmony_ci10. Call **AudioManagerNapi::On** to subscribe to system volume changes. If a system volume change occurs, the following parameters are used to notify the application: 21446f34cbfSopenharmony_ci**volumeType**: type of the system volume changed. 21546f34cbfSopenharmony_ci**volume**: current volume level. 21646f34cbfSopenharmony_ci**updateUi**: whether to show the change on the UI. (Set **updateUi** to **true** for a volume increase or decrease event, and set it to **false** for other changes.) 21746f34cbfSopenharmony_ci ``` 21846f34cbfSopenharmony_ci const audioManager = audio.getAudioManager(); 21946f34cbfSopenharmony_ci 22046f34cbfSopenharmony_ci export default { 22146f34cbfSopenharmony_ci onCreate() { 22246f34cbfSopenharmony_ci audioManager.on('volumeChange', (volumeChange) ==> { 22346f34cbfSopenharmony_ci console.info('volumeType = '+volumeChange.volumeType); 22446f34cbfSopenharmony_ci console.info('volume = '+volumeChange.volume); 22546f34cbfSopenharmony_ci console.info('updateUi = '+volumeChange.updateUi); 22646f34cbfSopenharmony_ci } 22746f34cbfSopenharmony_ci } 22846f34cbfSopenharmony_ci } 22946f34cbfSopenharmony_ci ``` 23046f34cbfSopenharmony_ci 23146f34cbfSopenharmony_ci#### Audio Scene 23246f34cbfSopenharmony_ci11. Call **SetAudioScene()** and **getAudioScene()** to set and obtain the audio scene, respectively. 23346f34cbfSopenharmony_ci ``` 23446f34cbfSopenharmony_ci int32_t result = audioSystemMgr->SetAudioScene(AUDIO_SCENE_PHONE_CALL); 23546f34cbfSopenharmony_ci AudioScene audioScene = audioSystemMgr->GetAudioScene(); 23646f34cbfSopenharmony_ci ``` 23746f34cbfSopenharmony_ciFor details about the supported audio scenes, see the enumerated values of **AudioScene** defined in [**audio_info.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiocommon/include/audio_info.h). 23846f34cbfSopenharmony_ci#### Audio Stream Management 23946f34cbfSopenharmony_ciYou can use the APIs provided in [**audio_stream_manager.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h) to implement stream management. 24046f34cbfSopenharmony_ci1. Call **GetInstance()** to obtain an **AudioSystemManager** instance. 24146f34cbfSopenharmony_ci ``` 24246f34cbfSopenharmony_ci AudioStreamManager *audioStreamMgr = AudioStreamManager::GetInstance(); 24346f34cbfSopenharmony_ci ``` 24446f34cbfSopenharmony_ci 24546f34cbfSopenharmony_ci2. Call **RegisterAudioRendererEventListener()** to register a listener for renderer state changes. A callback will be invoked when the renderer state changes. You can override **OnRendererStateChange()** in the **AudioRendererStateChangeCallback** class. 24646f34cbfSopenharmony_ci ``` 24746f34cbfSopenharmony_ci const int32_t clientPid; 24846f34cbfSopenharmony_ci 24946f34cbfSopenharmony_ci class RendererStateChangeCallback : public AudioRendererStateChangeCallback { 25046f34cbfSopenharmony_ci public: 25146f34cbfSopenharmony_ci RendererStateChangeCallback = default; 25246f34cbfSopenharmony_ci ~RendererStateChangeCallback = default; 25346f34cbfSopenharmony_ci void OnRendererStateChange( 25446f34cbfSopenharmony_ci const std::vector<std::shared_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos) override 25546f34cbfSopenharmony_ci { 25646f34cbfSopenharmony_ci cout<<"OnRendererStateChange entered"<<endl; 25746f34cbfSopenharmony_ci } 25846f34cbfSopenharmony_ci }; 25946f34cbfSopenharmony_ci 26046f34cbfSopenharmony_ci std::shared_ptr<AudioRendererStateChangeCallback> callback = std::make_shared<RendererStateChangeCallback>(); 26146f34cbfSopenharmony_ci int32_t state = audioStreamMgr->RegisterAudioRendererEventListener(clientPid, callback); 26246f34cbfSopenharmony_ci int32_t result = audioStreamMgr->UnregisterAudioRendererEventListener(clientPid); 26346f34cbfSopenharmony_ci ``` 26446f34cbfSopenharmony_ci 26546f34cbfSopenharmony_ci3. Call **RegisterAudioCapturerEventListener()** to register a listener for capturer state changes. A callback will be invoked when the capturer state changes. You can override **OnCapturerStateChange()** in the **AudioCapturerStateChangeCallback** class. 26646f34cbfSopenharmony_ci ``` 26746f34cbfSopenharmony_ci const int32_t clientPid; 26846f34cbfSopenharmony_ci 26946f34cbfSopenharmony_ci class CapturerStateChangeCallback : public AudioCapturerStateChangeCallback { 27046f34cbfSopenharmony_ci public: 27146f34cbfSopenharmony_ci CapturerStateChangeCallback = default; 27246f34cbfSopenharmony_ci ~CapturerStateChangeCallback = default; 27346f34cbfSopenharmony_ci void OnCapturerStateChange( 27446f34cbfSopenharmony_ci const std::vector<std::shared_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos) override 27546f34cbfSopenharmony_ci { 27646f34cbfSopenharmony_ci cout<<"OnCapturerStateChange entered"<<endl; 27746f34cbfSopenharmony_ci } 27846f34cbfSopenharmony_ci }; 27946f34cbfSopenharmony_ci 28046f34cbfSopenharmony_ci std::shared_ptr<AudioCapturerStateChangeCallback> callback = std::make_shared<CapturerStateChangeCallback>(); 28146f34cbfSopenharmony_ci int32_t state = audioStreamMgr->RegisterAudioCapturerEventListener(clientPid, callback); 28246f34cbfSopenharmony_ci int32_t result = audioStreamMgr->UnregisterAudioCapturerEventListener(clientPid); 28346f34cbfSopenharmony_ci ``` 28446f34cbfSopenharmony_ci4. Call **GetCurrentRendererChangeInfos()** to obtain information about all running renderers, including the client UID, session ID, renderer information, renderer state, and output device details. 28546f34cbfSopenharmony_ci ``` 28646f34cbfSopenharmony_ci std::vector<std::shared_ptr<AudioRendererChangeInfo>> audioRendererChangeInfos; 28746f34cbfSopenharmony_ci int32_t currentRendererChangeInfo = audioStreamMgr->GetCurrentRendererChangeInfos(audioRendererChangeInfos); 28846f34cbfSopenharmony_ci ``` 28946f34cbfSopenharmony_ci 29046f34cbfSopenharmony_ci5. Call **GetCurrentCapturerChangeInfos()** to obtain information about all running capturers, including the client UID, session ID, capturer information, capturer state, and input device details. 29146f34cbfSopenharmony_ci ``` 29246f34cbfSopenharmony_ci std::vector<std::shared_ptr<AudioCapturerChangeInfo>> audioCapturerChangeInfos; 29346f34cbfSopenharmony_ci int32_t currentCapturerChangeInfo = audioStreamMgr->GetCurrentCapturerChangeInfos(audioCapturerChangeInfos); 29446f34cbfSopenharmony_ci ``` 29546f34cbfSopenharmony_ci For details, see **audioRendererChangeInfos** and **audioCapturerChangeInfos** in [**audio_info.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/interfaces/inner_api/native/audiocommon/include/audio_info.h). 29646f34cbfSopenharmony_ci 29746f34cbfSopenharmony_ci6. Call **IsAudioRendererLowLatencySupported()** to check whether low latency is supported. 29846f34cbfSopenharmony_ci ``` 29946f34cbfSopenharmony_ci const AudioStreamInfo &audioStreamInfo; 30046f34cbfSopenharmony_ci bool isLatencySupport = audioStreamMgr->IsAudioRendererLowLatencySupported(audioStreamInfo); 30146f34cbfSopenharmony_ci ``` 30246f34cbfSopenharmony_ci#### Using JavaScript APIs 30346f34cbfSopenharmony_ciJavaScript applications can call the audio management APIs to control the volume and devices. 30446f34cbfSopenharmony_ciFor details, see [**js-apis-audio.md**](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-audio-kit/js-apis-audio.md#audiomanager). 30546f34cbfSopenharmony_ci 30646f34cbfSopenharmony_ci### Bluetooth SCO Call 30746f34cbfSopenharmony_ciYou can use the APIs provided in [**audio_bluetooth_manager.h**](https://gitee.com/openharmony/multimedia_audio_framework/blob/master/frameworks/native/bluetoothclient/audio_bluetooth_manager.h) to implement Bluetooth calls over synchronous connection-oriented (SCO) links. 30846f34cbfSopenharmony_ci 30946f34cbfSopenharmony_ci1. Call **OnScoStateChanged()** to listen for SCO link state changes. 31046f34cbfSopenharmony_ci ``` 31146f34cbfSopenharmony_ci const BluetoothRemoteDevice &device; 31246f34cbfSopenharmony_ci int state; 31346f34cbfSopenharmony_ci void OnScoStateChanged(const BluetoothRemoteDevice &device, int state); 31446f34cbfSopenharmony_ci ``` 31546f34cbfSopenharmony_ci 31646f34cbfSopenharmony_ci2. (Optional) Call the static API **RegisterBluetoothScoAgListener()** to register a Bluetooth SCO listener, and call **UnregisterBluetoothScoAgListener()** to unregister the listener when it is no longer required. 31746f34cbfSopenharmony_ci## Supported Devices 31846f34cbfSopenharmony_ciThe following lists the device types supported by the audio framework. 31946f34cbfSopenharmony_ci 32046f34cbfSopenharmony_ci1. **USB Type-C Headset** 32146f34cbfSopenharmony_ci 32246f34cbfSopenharmony_ci A digital headset that consists of its own digital-to-analog converter (DAC) and amplifier that functions as part of the headset. 32346f34cbfSopenharmony_ci 32446f34cbfSopenharmony_ci2. **WIRED Headset** 32546f34cbfSopenharmony_ci 32646f34cbfSopenharmony_ci An analog headset that does not contain any DAC. It can have a 3.5 mm jack or a USB-C socket without DAC. 32746f34cbfSopenharmony_ci 32846f34cbfSopenharmony_ci3. **Bluetooth Headset** 32946f34cbfSopenharmony_ci 33046f34cbfSopenharmony_ci A Bluetooth Advanced Audio Distribution Mode (A2DP) headset for wireless audio transmission. 33146f34cbfSopenharmony_ci 33246f34cbfSopenharmony_ci4. **Internal Speaker and MIC** 33346f34cbfSopenharmony_ci 33446f34cbfSopenharmony_ci A device with a built-in speaker and microphone, which are used as default devices for playback and recording, respectively. 33546f34cbfSopenharmony_ci 33646f34cbfSopenharmony_ci## Repositories Involved 33746f34cbfSopenharmony_ci 33846f34cbfSopenharmony_ci[multimedia\_audio\_framework](https://gitee.com/openharmony/multimedia_audio_framework) 339