Voice Chat Live Streaming and Listening
This document primarily introduces how to use
RTC Room Engine
SDK to implement voice chat live streaming and listening functionality.Prerequisites
Before using the
RTC Room Engine
SDK, you need to call the Log In SDK first so that subsequent features can be used normally.Audio Live Broadcast
The core steps to implement voice chat live streaming using
RTC Room Engine
require three steps: create and join a live room, become a speaker and push the stream, enable media devices. The following provides a detailed introduction.Procedure 1: Create and Join a Live Room
Before going live, you need to fill in key parameters
TUIRoomInfo
. Next, we will provide a detailed introduction:Parameter: TUIRoomInfo
TUIRoomInfo
is composed of many fields, but you only need to care about filling in the following fields:Parameter Name | Field Description | Additional Notes | Data Type | Fill-In Example |
roomId | room ID | Only allow combination of uppercase and lowercase letters (a-z, A-Z), digits (0-9), underline and hyphen. This field is a required parameter when creating a room. It supports a maximum of 48 bytes. | New Character String | "live_100001" |
name | room name | String type room name. (If it is empty, it will be consistent with roomId.) | New Character String | "denny`s room" |
seatMode | Mic on mode | This field takes effect only after microphone position control is enabled. Divide into "freeToTake mode" and "applyToTake mode". In freeToTake mode, audiences can freely become speakers without application. In microphone mode, audiences need the room owner's approval after consent to become speakers. | Enumeration Value | TUISeatMode.applyToTake |
maxSeatCount | maximum number of microphone slots | The maximum number of microphone slots of digit type means that up to maxSeatCount people can be online simultaneously. The maximum number of microphone slots matches the maximum number of mic-on users of the purchased package. | Digits | 10 |
isSeatEnabled | Whether microphone position control is enabled? | Boolean type enable flag for microphone position control. | Boolean value | true |
roomType | Room type | Divide into two room types: "conference" and "live". Voice chat belongs to live streaming, so use live here. | Enumeration Value | TUIRoomType.live |
After preparing the parameter
TUIRoomInfo
, you can call the API functions createRoom
and enterRoom
to create and join a live room.Before going live, you need to fill in key parameters
RoomInfo
. Next, we will provide a detailed introduction:Parameter: RoomInfo
RoomInfo
is composed of many fields, but you only need to care about filling in the following fields:Parameter Name | Field Description | Additional Notes | Data Type | Fill-In Example |
roomId | room ID | Only allow combination of uppercase and lowercase letters (a-z, A-Z), digits (0-9), underline and hyphen. This field is a required parameter when creating a room. It supports a maximum of 48 bytes. | New Character String | "live_100001" |
name | room name | String type room name. (If it is empty, it will be consistent with roomId.) | New Character String | "denny`s room" |
seatMode | Mic on mode | This field takes effect only after microphone position control is enabled. Divide into "FREE_TO_TAKE mode" and "APPLY_TO_TAKE mode". In FREE_TO_TAKE mode, audiences can freely become speakers without application. In MICROPHONE mode, audiences need the room owner's approval after consent to become speakers. | Enumeration Value | SeatMode.APPLY_TO_TAKE |
maxSeatCount | maximum number of microphone slots | The maximum number of microphone slots of digit type means that up to maxSeatCount people can be online simultaneously. The maximum number of microphone slots matches the maximum number of mic-on users of the purchased package. | Digits | 10 |
isSeatEnabled | Whether microphone position control is enabled? | Boolean type enable flag for microphone position control. | Boolean value | true |
roomType | Room type | Divide into two room types: "CONFERENCE" and "LIVE". Voice chat belongs to live streaming, so use live here. | Enumeration Value | RoomType.Live |
After preparing the parameter
RoomInfo
, you can call the API functions createRoom
and enterRoom
to create and join a live room.import RTCRoomEnginelet roomInfo = TUIRoomInfo()roomInfo.roomId = "voice_100001" // Please replace with your own room IDroomInfo.name = "denny's room" // Please replace with your own room nameroomInfo.seatMode = .applyToTake // You can also replace it with.freeToTake according to your needsroomInfo.maxSeatCount = 10 // Please replace with the maximum number of microphone slots of the Live package you have purchasedroomInfo.isSeatEnabled = true // If you don't need microphone position control, you can set isSeatEnabled to falseroomInfo.roomType = .live // Please ensure the room type is the live typeTUIRoomEngine.sharedInstance().createRoom(roomInfo) { [weak self] inguard let self = self else { return }TUIRoomEngine.sharedInstance.enterRoom(self.roomId, roomType: .live) { [weak self] roomInfo inguard let self = self else { return }// Successfully joined the live room} onError: { code, message in// Failed to join the live room}} onError: { code, message in// Failed to create a live streaming room}
TUIRoomDefine.RoomInfo roomInfo = new TUIRoomDefine.RoomInfo();roomInfo.roomId = "voice_100001"; // Please replace with your own room IDroomInfo.name = "denny's room"; // Please replace with your own room nameroomInfo.seatMode = TUIRoomDefine.SeatMode.APPLY_TO_TAKE; // You can also replace it with.freeToTake according to your needsroomInfo.maxSeatCount = 10; // Please replace with the maximum number of microphone slots of the Live package you have purchasedroomInfo.isSeatEnabled = true; // If you don't need microphone position control, you can set isSeatEnabled to falseroomInfo.roomType = TUIRoomDefine.RoomType.LIVE; // Please ensure the room type is the live typeTUIRoomEngine.sharedInstance().createRoom(roomInfo, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {TUIRoomEngine.sharedInstance().enterRoom(roomInfo.roomId, TUIRoomDefine.RoomType.LIVE, new TUIRoomDefine.GetRoomInfoCallback() {@Overridepublic void onSuccess(TUIRoomDefine.RoomInfo roomInfo) {// Successfully joined the live room}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to join the live room}});}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to create a live streaming room}});
Procedure 2: Become a Speaker and Start Streaming
Only after becoming a speaker can you start streaming. Therefore, after you successfully create a room, you need to call the
takeSeat
API to become a speaker and start streaming.import RTCRoomEnginelet index = 0 // Please replace this with the seat number you want to apply forlet timeout = 30 // Please replace this with the timeout period for your application to become a speaker, in seconds. If set to 0, the SDK will not perform timeout detection or trigger a timeout callback.TUIRoomEngine.sharedInstance().takeSeat(index, timeout: TimeInterval(timeout)) { requestId, userId in// Become a speaker successfully} onRejected: { requestId, userId, messagae in// Seat request rejected} onCancelled: { requestId, userId in// Request to speak canceled} onTimeout: { requestId, userId in// Seat request timed out} onError: { requestId, userId, code, message in// Failed to join the microphone}
int index = 0; // Please replace this with the seat number you want to apply forint timeout = 30; // Please replace this with the timeout period for your application to request to speak, in seconds. If set to 0, the SDK will not perform timeout detection or trigger a timeout callback.TUIRoomEngine.sharedInstance().takeSeat(index, timeout, new TUIRoomDefine.RequestCallback() {@Overridepublic void onAccepted(String requestId, String userId) {// Become a speaker successfully}@Overridepublic void onRejected(String requestId, String userId, String message) {// Seat request rejected}@Overridepublic void onCancelled(String requestId, String userId) {// Request to speak canceled}@Overridepublic void onTimeout(String requestId, String userId) {// Seat request timed out}@Overridepublic void onError(String requestId, String userId, TUICommonDefine.Error error, String message) {// Failed to join the microphone}});
Step 3: Turn on the Media Device
After going live, you also need to call the
openLocalMicrophone
API to turn on the microphone, input a parameter quality
in types of TUIAudioQuality
, to ensure that the audience can hear your sound.TUIAudioQuality
is an enumeration.Parameter Name | Field Description |
speech | Voice mode. Mono; audio raw bit rate: 18 kbps; suitable for scenarios mainly for voice calls. |
default | Default mode. Mono; audio raw bit rate: 50 kbps; the default audio quality of the SDK. It is recommended unless otherwise needed. |
music | Music mode. Stereo + full-band; audio raw bit rate: 128 kbps; suitable for scenarios requiring high-quality music transmission, such as online karaoke, music live streaming. |
After going live, you also need to call the
openLocalMicrophone
API to turn on the microphone, input a parameter quality
in types of AudioQuality
, to ensure that the audience can hear your sound.AudioQuality
is an enumeration.Parameter Name | Field Description |
SPEECH | Voice mode. Mono; audio raw bit rate: 18 kbps; suitable for scenarios mainly for voice calls. |
DEFAULT | Default mode. Mono; audio raw bit rate: 50 kbps; the default audio quality of the SDK. It is recommended unless otherwise needed. |
MUSIC | Music mode. Stereo + full-band; audio raw bit rate: 128 kbps; suitable for scenarios requiring high-quality music transmission, such as online karaoke, music live streaming. |
Open the local microphone in music mode as an example.
import RTCRoomEnginelet audioQuality: TUIAudioQuality =.music // Select the corresponding mode according to your scenario requirements for audio quality.TUIRoomEngine.sharedInstance().openLocalMicrophone(audioQuality) {// Successfully turn on the microphone} onError: { code, message in// Failed to open the mic}
TUIRoomDefine.AudioQuality audioQuality = TUIRoomDefine.AudioQuality.MUSIC; // Select the corresponding mode according to your scenario requirements for audio quality.TUIRoomEngine.sharedInstance().openLocalMicrophone(audioQuality, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// Successfully turn on the microphone}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to open the mic}});
Audio Listening
You just need to successfully call the
enterRoom
API to enter the room and then you can listen to the voice of the voice chat room anchor.enterRoom: You need to pass in two parameters: the Room Id of the room where the anchor you want to listen to is located and the room type.
Note:
There are two room types: conference and live. Voice chat rooms belong to live streaming rooms. Therefore, when you are calling
enterRoom
to enter a voice chat room, you need to pass in live
for the room type.import RTCRoomEnginelet roomId = "voice_100001" // room ID to listen tolet roomType = .live // Set as.live hereTUIRoomEngine.sharedInstance().enterRoom(roomId, roomType: roomType) { roomInfo in// Entered room successfully} onError: { code, message in// Failed to enter the room}
String roomId = "voice_100001"; // room ID to listen toTUIRoomDefine.RoomType roomType = TUIRoomDefine.RoomType.LIVE; // Set as .live hereTUIRoomEngine.sharedInstance().enterRoom(roomId, roomType, new TUIRoomDefine.GetRoomInfoCallback() {@Overridepublic void onSuccess(TUIRoomDefine.RoomInfo roomInfo) {// Entered room successfully}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to enter the room}});