Audio Settings
this document primarily introduces how to use
RTC Room Engine
SDK to implement audio settings related features.Prerequisites
Before using the audio settings related features provided by
RTC Room Engine
SDK, you need to complete log in to the SDK and ensure that you are in a live room.User Guide
Turn On/Off Local Microphone
You can turn on or off your local microphone by calling two APIs:
openLocalMicrophone
and closeLocalMicrophone
.When calling
openLocalMicrophone
to turn on the microphone, you need to input a parameter quality
in types of TUIAudioQuality
to set the audio encoding quality. TUIAudioQuality
includes following types. You can select based on your business requirement:Enumerated Value Type | Meaning |
speech | Voice mode. Mono; Raw Bit Rate of audio: 18 kbps; suitable for scenarios mainly for voice calls. |
default | Default mode. Mono; Raw Bit Rate of audio: 50 kbps; the default audio quality of the SDK. It is the recommended choice unless otherwise needed. |
music | Music mode. Stereo + full-band; Raw Bit Rate of audio: 128 kbps; suitable for scenarios requiring high-quality music transmission, such as online karaoke, music live streaming. |
You can turn on or off your local microphone by calling two APIs:
openLocalMicrophone
and closeLocalMicrophone
.When calling
openLocalMicrophone
to turn on the microphone, you need to input a parameter quality
in types of AudioQuality
to set the audio encoding quality. AudioQuality
includes following types. You can select based on your business requirement:Enumerated Value Type | Meaning |
SPEECH | Voice mode. Mono; Raw Bit Rate of audio: 18 kbps; suitable for scenarios mainly for voice calls. |
DEFAULT | Default mode. Mono; Raw Bit Rate of audio: 50 kbps; the default audio quality of the SDK. It is the recommended choice unless otherwise needed. |
MUSIC | Music mode. Stereo + full-band; Raw Bit Rate of audio: 128 kbps; suitable for scenarios requiring high-quality music transmission, such as online karaoke, music live streaming. |
Following is the example code for turning on and off the local microphone in default mode.
import RTCRoomEnginelet roomEngine = TUIRoomEngine.sharedInstance()// Turn on the local microphoneroomEngine.openLocalMicrophone(.default) {// Successfully turn on the microphone} onError: { code, message in// Fail to turn on the microphone}// Turn off the local microphoneroomEngine.closeLocalMicrophone()
TUIRoomEngine roomEngine = TUIRoomEngine.sharedInstance();// Turn on the local microphoneroomEngine.openLocalMicrophone(TUIRoomDefine.AudioQuality.DEFAULT, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Successfully turn on the microphone}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Fail to turn on the microphone}});// Turn off the local microphoneroomEngine.closeLocalMicrophone();
Update Local Audio Encoding Quality
When updating the local audio encoding quality, the type of the passed parameters
TUIAudioQuality
needs to be consistent with what was mentioned in the previous context. Below, taking the default mode as an example, call the updateAudioQuality
API to update the encoding quality of local audio:import RTCRoomEnginelet audioQuality: TUIAudioQuality = .defaultTUIRoomEngine.sharedInstance().updateAudioQuality(audioQuality)
When updating the local audio encoding quality, the type of the passed parameters
AudioQuality
needs to be the same as mentioned above. Below, taking the default mode as an example, call the updateAudioQuality
API to update the encoding quality of local audio:TUIRoomDefine.AudioQuality audioQuality = TUIRoomDefine.AudioQuality.DEFAULT;TUIRoomEngine.sharedInstance().updateAudioQuality(audioQuality);
Pause/Resume Publishing Local Audio Stream
When you are in the live streaming room, you may need to pause/resume publishing your local audio stream. You can achieve this by calling the following interfaces:
import RTCRoomEnginelet roomEngine = TUIRoomEngine.sharedInstance()// Pause publishing local audio streamroomEngine.muteLocalAudio()// Resume publishing local audio streamroomEngine.unmuteLocalAudio() {// Resume publishing successful} onError: { code, message in// Resume publishing failed}
TUIRoomEngine roomEngine = TUIRoomEngine.sharedInstance();// Pause publishing local audio streamroomEngine.muteLocalAudio();// Resume publishing local audio streamroomEngine.unmuteLocalAudio(new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Resume publishing successful}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Restore publication failed}});
Note:
Inside the room, if you have enabled your microphone and called the above API to suspend/resume the publishing of the local audio stream, the SDK will notify users in the room through the onUserAudioStateChanged callback in
TUIRoomObserver
.