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:
|
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:
|
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 RTCRoomEngine
let roomEngine = TUIRoomEngine.sharedInstance()
roomEngine.openLocalMicrophone(.default) {
} onError: { code, message in
}
roomEngine.closeLocalMicrophone()
TUIRoomEngine roomEngine = TUIRoomEngine.sharedInstance();
roomEngine.openLocalMicrophone(TUIRoomDefine.AudioQuality.DEFAULT, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
roomEngine.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 RTCRoomEngine
let audioQuality: TUIAudioQuality = .default
TUIRoomEngine.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 RTCRoomEngine
let roomEngine = TUIRoomEngine.sharedInstance()
roomEngine.muteLocalAudio()
roomEngine.unmuteLocalAudio() {
} onError: { code, message in
}
TUIRoomEngine roomEngine = TUIRoomEngine.sharedInstance();
roomEngine.muteLocalAudio();
roomEngine.unmuteLocalAudio(new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
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.