This document describes how to implement the GME real-time audio feature on Android.
NoteThis document is available for GME SDK version 2.9.
GME provides two services: voice chat service and voice message and speech-to-text service, both of which rely on key APIs such as Init and Poll.
Note on Init APIIf you need to use voice chat and voice message services at the same time, you only need to call
Init
API once.
Billing will not start after initialization. After you call Entering a voice chat roomAPI: EnterRoom to enter the room successfully, the billing will start.
QAVError.OK
will be returned with the value being 0.Poll
API should be called periodically for GME to trigger event callbacks.Class | Description |
---|---|
ITMGContext | Key APIs |
ITMGRoom | Room APIs |
ITMGRoomManager | Room management APIs |
ITMGAudioCtrl | Audio APIs |
ITMGAudioEffectCtrl | Sound effect and accompaniment APIs |
Before the initialization, the SDK is in the uninitialized status, and you need to initialize it through the Init
API before you can use the voice chat and speech-to-text services.
You need to call the Init
API before calling any APIs of GME.
If you have any questions when using the service, please see General FAQs.
API | Description |
---|---|
Init | Initializes GME |
Poll | Triggers event callback |
Pause | Pauses the system |
Resume | Resumes the system |
Uninit | Uninitializes GME |
NoteIf you need to switch the account, please call
UnInit
to uninitialize the SDK. No fee is incurred for calling Init API.
To use the voice feature, get the ITMGContext
object first.
import com.tencent.TMG.ITMGContext;
ITMGContext.getInstance(this);
The API class uses the Delegate
method to send callback notifications to the application. Register the callback function to the SDK for receiving callback messages.
static public abstract class ITMGDelegate {
public void OnEvent(ITMG_MAIN_EVENT_TYPE type, Intent data){}
}
Override this callback function in the constructor to process the parameters of the callback.
Parameter | Type | Description |
---|---|---|
type | ITMGContext.ITMG_MAIN_EVENT_TYPE | Event type in the callback response |
data | Intent message type | Callback message, i.e., event data |
private ITMGContext.ITMGDelegate itmgDelegate = null;
itmgDelegate = new ITMGContext.ITMGDelegate() {
@Override
public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {
if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM == type)
{
// Analyze the returned result
int nErrCode = data.getIntExtra("result" , -1);
String strErrMsg = data.getStringExtra("error_info");
}
}
}
Register the callback function to the SDK before room entry.
public abstract int SetTMGDelegate(ITMGDelegate delegate);
Parameter | Type | Description |
---|---|---|
delegate | ITMGDelegate | SDK callback function |
ITMGContext.GetInstance(this).SetTMGDelegate(itmgDelegate);
sdkAppID
parameter, please see Voice Service Activation Guide.Note
- The SDK must be initialized before a user can enter a voice chat room.
- The Init API must be called in the same thread with other APIs. It is recommended to call all APIs in the main thread.
public abstract int Init(String sdkAppId, String openId);
Parameter | Type | Description |
---|---|---|
sdkAppId | String | AppId provided by the GME service from the Tencent Cloud console |
OpenId | String | OpenId can only be in Int64 type, which is passed after being converted to a string. |
Returned Value | Description |
---|---|
QAVError.OK= 0 | Initialized SDK successfully |
AV_ERR_SDK_NOT_FULL_UPDATE=7015 | Checks whether the SDK file is complete. It is recommended to delete it and then import the SDK again. |
The returned value AV_ERR_SDK_NOT_FULL_UPDATE
is only a reminder but will not cause an initialization failure.
String sdkAppID = "14000xxxxx";
String openID = "100";
int ret = ITMGContext.GetInstance(this).Init(sdkAppId, openId);
if(ret != 0){
Log.e(TAG,"SDK initialization failed");
}
Event callbacks can be triggered by periodically calling the Poll
API in update
. The Poll
API should be called periodically for GME to trigger event callbacks; otherwise, the entire SDK service will run exceptionally.
Refer to the EnginePollHelper.java file in Demo.
Calling the `Poll` API periodicallyThe
Poll
API must be called periodically and in the main thread to avoid abnormal API callbacks.
public abstract int Poll();
private Handler mhandler = new Handler();private Runnable mRunnable = new Runnable() { @Override public void run() { if (s_pollEnabled) { if (ITMGContext.GetInstance(null) != null) ITMGContext.GetInstance(null).Poll(); } mhandler.postDelayed(mRunnable, 33); }};
When a Pause
event occurs in the system, the engine should also be notified for pause.
If you need to pause the audio when switching to the background, you can call the Pause
API in the listening code used to switch to the background, and call the Resume
API in the listening event used to resume the foreground.
public abstract int Pause();
When a Resume
event occurs in the system, the engine should also be notified for resumption. The Resume
API only supports resuming voice chat.
public abstract int Resume();
This API is used to uninitialize the SDK to make it uninitialized. Switching accounts requires uninitialization.
public abstract int Uninit();
Voice chat refers to the one-to-one or one-to-many real-time voice call feature.
You should initialize and call the SDK to enter a room before voice chat can start.
If you have any questions when using the service, please see FAQs About Voice Chat.
API | Description |
---|---|
GenAuthBuffer | Initializes authentication |
EnterRoom | Enters room |
IsRoomEntered | Indicates whether room entry is successful |
ExitRoom | Exits room |
ChangeRoomType | Modifies user's room audio type |
GetRoomType | Gets user's room audio type |
Entered the room successfullyIf the room entry callback result is 0, the room entry is successful. The returned value of 0 from the
EnterRoom
API does not necessarily mean that the room entry is successful.
Generate AuthBuffer
for encryption and authentication of relevant features. For release in the production environment, please use the backend deployment key as detailed in Authentication Key.
AuthBuffer public native byte[] genAuthBuffer(int sdkAppId, String roomId, String openId, String key)
Parameter | Type | Description |
---|---|---|
appId | int | AppId from the Tencent Cloud console. |
roomId | string | Room ID, which can contain up to 127 characters. |
openId | string | User ID, which is the same as OpenId during initialization. |
key | string | Permission key from the Tencent Cloud console. |
import com.tencent.av.sig.AuthBuffer;// Header file
byte[] authBuffer = AuthBuffer.getInstance().genAuthBuffer(Integer.parseInt(sdkAppId), strRoomID,openId, key);
When a user enters a room with the generated authentication information, the ITMG_MAIN_EVENT_TYPE_ENTER_ROOM
message will be received as a callback. Mic and speaker are not enabled by default after room entry. The returned value of AV_OK
indicates a success.
The audio type of the room is determined by the first user to enter the room. After that, if a member in the room changes the room type, it will take effect for all members there. For example, if the first user entering the room uses the smooth sound quality, and the second user entering the room uses the HD sound quality, the room audio type of the second user will become smooth sound quality. Only when a member in the room calls the ChangeRoomType
API, the audio type of the room will be changed.
For more information on how to choose a room audio type, please see Sound Quality Selection.
public abstract int EnterRoom(String roomID, int roomType, byte[] authBuffer);
Parameter | Type | Description |
---|---|---|
roomId | String | Room ID, which can contain up to 127 characters |
roomType | int | Room audio type |
authBuffer | byte[] | Authentication code |
ITMGContext.GetInstance(this).EnterRoom(roomId,roomType, authBuffer);
After the user enters the room, the message ITMG_MAIN_EVENT_TYPE_ENTER_ROOM
will be sent and identified in the OnEvent
function for callback and processing. A successful callback means that the room entry is successful, and the billing starts.
private ITMGContext.ITMGDelegate itmgDelegate = null;
itmgDelegate= new ITMGContext.ITMGDelegate() {
@Override
public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {
}
};
Sample code for processing the callback, including room entry and network disconnection events.
public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {
if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM == type)
{
// Analyze the returned result
int nErrCode = data.getIntExtra("result" , -1);
String strErrMsg = data.getStringExtra("error_info");
if (nErrCode == AVError.AV_OK)
{
//If you receive a success response for room entry, you can proceed with your operation
ScrollView_ShowLog("EnterRoom success");
Log.i(TAG,"EnterRoom success!");
}
else
{
//If you fail to enter the room, you need to analyze the returned error message
ScrollView_ShowLog("EnterRoom fail :" + strErrMsg);
Log.i(TAG,"EnterRoom fail!");
}
}
if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ROOM_DISCONNECT == type)
{
//waiting timeout, please check your network
}
}
Message | Data | Sample |
---|---|---|
ITMG_MAIN_EVENT_TYPE_ENTER_ROOM | result; error_info | {"error_info":"","result":0} |
ITMG_MAIN_EVENT_TYPE_ROOM_DISCONNECT | result; error_info | {"error_info":"waiting timeout, please check your network","result":0} |
If the network is disconnected, there will be a disconnected callback prompt ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ROOM_DISCONNECT
. At this time, the SDK will automatically reconnect, and the callback is ITMG_MAIN_EVENT_TYPE_RECONNECT_START
. When the reconnection is successful, there will be a callback ITMG_MAIN_EVENT_TYPE_RECONNECT_SUCCESS
.
Code | Cause and Suggested Solution |
---|---|
7006 | Authentication failed AppID does not exist or is incorrect.authbuff .OpenId does not meet the specification. |
7007 | The user is already in another room. |
1001 | The user was already in the process of entering a room but repeated this operation. It is recommended not to call the room entering API until the room entry callback is returned. |
1003 | The user was already in the room and called the room entering API again. |
1101 | Make sure that the SDK is initialized, OpenId complies with the rules, the APIs are called in the same thread, and the Poll API is called normally. |
This API is called to exit the current room. It is an async API. The returned value of AV_OK
indicates a successful async delivery.
NoteIf there is a scenario in the application where room entry is performed immediately after room exit, you don't need to wait for the
RoomExitComplete
callback notification from theExitRoom
API during API call; instead, you can directly call the API.
public abstract int ExitRoom();
ITMGContext.GetInstance(this).ExitRoom();
After the user exits a room, a callback will be returned with the message being ITMG_MAIN_EVENT_TYPE_EXIT_ROOM
.
public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {
if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_EXIT_ROOM == type)
{
// Receive the event of successful room exit
}
}
Message | Data | Sample |
---|---|---|
ITMG_MAIN_EVENT_TYPE_EXIT_ROOM | result; error_info | {"error_info":"","result":0} |
This API is used to determine whether the user has entered a room. A bool-type value will be returned. The call is invalid during the process of room entry.
public abstract boolean IsRoomEntered();
ITMGContext.GetInstance(this).IsRoomEntered();
User can call this API to quickly switch the voice chat room after entering the room. After the room is switched, the device is not reset, that is, if the microphone is already enabled in this room, the microphone will keep enabled after the room is switched.
The callback for quickly switching rooms is ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_SWITCH_ROOM
, and the fields are error_info
and result
.
public abstract int SwitchRoom(String targetRoomID, byte[] authBuffer);
Parameter | Type | Description |
---|---|---|
targetRoomID | String | ID of the room to enter |
authBuffer | byte[] | Generates a new authentication with the ID of the room to enter |
if(ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_SWITCH_ROOM == type) {
int result = data.getIntExtra("result", 1);
String errorInfo = data.getStringExtra("error_info");
if (result == 0) {
Toast.makeText(getActivity(), "switch room success.", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getActivity(), "switch room failed.. error info=" + errorInfo, Toast.LENGTH_SHORT).show();
}
}
Call this API to connect the microphones of different rooms. It’s invoked after a user enters the room. Note that the type of invoking room and target room must be the same.
User A in Room 1 speaks to User B in Room 2. When User C in Room 1 speaks, users in Room 2 cannot hear. User C can only hear other users in Room 1 and User B in Room 2 but not other users in Room 2.
/// <summary> Enable the room sharing, and connect the mic of the OpenID in another room.</summary>
public abstract int StartRoomSharing(String targetRoomID, String targetOpenID, byte[] authBuffer);
/// <summary> Stop the enabled room sharing.</summary>
public abstract int StopRoomSharing();
Parameter | Type | Description |
---|---|---|
targetRoomID | String | ID of the room to connect mic |
targetOpenID | String | The target OpenID to connect mic |
authBuffer | byte[] | Reserved flag. You just need to enter NULL. |
if (mSwtichRoomShareStart.isChecked())
{
String strRoomID = mEditRoomShareRoomID.getText().toString();
String strOpenID = mEditRoomShareOpenID.getText().toString();
int nRet = ITMGContext.GetInstance(getActivity()).GetRoom().StartRoomSharing(strRoomID, strOpenID, null);
if (nRet != 0)
{
Toast.makeText(getActivity(), String.format("StartRoomSharing failed nRet=" + nRet), Toast.LENGTH_SHORT).show();
}else
{
int nRet = ITMGContext.GetInstance(getActivity()).GetRoom().StopRoomSharing();
if (nRet != 0)
{
Toast.makeText(getActivity(), String.format("StopRoomSharing failed nRet=" + nRet), Toast.LENGTH_SHORT).show();
}
}
}
This API is used to obtain the user speaking in the room and display it in the UI, and to send a notification when someone entering or exiting the room.
Notification for this event will be sent only when the status changes. To get member status in real time, cache the notification when it is received at a higher layer. The event message is ITMG_MAIN_EVNET_TYPE_USER_UPDATE
, where the data contains event_id
and user_list
. The event message will be identified in the OnEvent
function.
Notifications for audio events are subject to a threshold, and a notification will be sent only when this threshold is exceeded. The notification “A member has stopped sending audio packets" will be sent if no audio packets are received in more than two seconds. This event only returns the member speaking event, but not the specific volume level. If you need the specific volume levels of members in the room, use the GetRecvStreamLevel
API.
event_id | Description | Maintenance |
---|---|---|
ITMG_EVENT_ID_USER_ENTER | A member enters the room | Member list |
ITMG_EVENT_ID_USER_EXIT | A member exits the room | Member list |
ITMG_EVENT_ID_USER_HAS_AUDIO | A member sends audio packets. This event can be used to determine whether a user is speaking and display the voiceprint effect. It can be called together with getRecvStreamLevel. | Chat member list |
ITMG_EVENT_ID_USER_NO_AUDIO | A member stops sending audio packets | Chat member list |
public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {
if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVNET_TYPE_USER_UPDATE == type)
{
// Update member status
int nEventID = data.getIntExtra("event_id", 0);
String[] openIdList =data.getStringArrayExtra("user_list");
switch (nEventID)
{
case ITMG_EVENT_ID_USER_ENTER:
// A member enters the room
break;
case ITMG_EVENT_ID_USER_EXIT:
// A member exits the room
break;
case ITMG_EVENT_ID_USER_HAS_AUDIO:
// A member sends audio packets
break;
case ITMG_EVENT_ID_USER_NO_AUDIO:
// A member stops sending audio packets
break;
default:
break;
}
}
}
Message | Data | Sample |
---|---|---|
ITMG_MAIN_EVNET_TYPE_USER_UPDATE | event_id; user_list | {"event_id":0,"user_list":""} |
This API is used to mute a user by specifying the ID. It only applies on the invoker side. 0
indicates the call is successful. For example, A, B, and C are all speaking in the same room:
public abstract int AddAudioBlackList(String openId);
Parameter | Type | Description |
---|---|---|
openId | String | ID of user to be muted |
ITMGContext.GetInstance(this).GetAudioCtrl().AddAudioBlackList(openId);
This API is used to unmute a user by specifying the ID. 0
indicates the call is successful.
public abstract int RemoveAudioBlackList(String openId);
Parameter | Type | Description |
---|---|---|
openId | String | ID of the user to be unmuted |
ITMGContext.GetInstance(this).GetAudioCtrl().RemoveAudioBlackList(openId);
The voice chat APIs can only be called after SDK initialization and room entry.
When Enable/Disable Mic/Speaker is clicked on the UI, the following practices are recommended:
EnableMic
and EnableSpeaker
APIs, which is equivalent to calling the EnableAudioCaptureDevice/EnableAudioSend
and EnableAudioPlayDevice/EnableAudioRecv
APIs.EnableAudioCaptureDevice(true)
and EnableAudioPlayDevice(true)
once after room entry, and call EnableAudioSend/Recv
to send/receive audio streams when Enable/Disable Mic is clicked.EnableAudioCaptureDevice
and EnableAudioPlayDevice
.pause
API to pause the audio engine and call the resume
API to resume the audio engine.API | Description |
---|---|
EnableMic | Enables/disables mic |
GetMicState | Gets mic status |
EnableAudioCaptureDevice | Enables/disables capturing device |
IsAudioCaptureDeviceEnabled | Gets capturing device status |
EnableAudioSend | Enables/disables audio upstreaming |
IsAudioSendEnabled | Gets audio upstreaming status |
GetMicLevel | Gets real-time mic volume |
GetSendStreamLevel | Gets real-time audio upstreaming volume |
SetMicVolume | Sets mic volume |
GetMicVolume | Gets mic volume |
EnableSpeaker | Enables/disables speaker |
GetSpeakerState | Gets speaker status |
EnableAudioPlayDevice | Enables/disables playback device |
IsAudioPlayDeviceEnabled | Gets playback device status |
EnableAudioRecv | Enables/disables audio downstreaming |
IsAudioRecvEnabled | Gets audio downstreaming status |
GetSpeakerLevel | Gets real-time speaker volume |
GetRecvStreamLevel | Gets real-time downstreaming audio levels of other members in room |
SetSpeakerVolume | Sets speaker volume |
GetSpeakerVolume | Gets speaker volume |
EnableLoopBack | Enables/disables in-ear monitoring |
This API is used to enable/disable the mic. Mic and speaker are not enabled by default after room entry.
If accompaniment is used, please call this API as instructed in Accompaniment in Voice Chat.
EnableMic = EnableAudioCaptureDevice + EnableAudioSend
public abstract int EnableMic(boolean isEnabled);
Parameter | Type | Description |
---|---|---|
isEnabled | boolean | To enable the mic, set this parameter to true ; otherwise, set it to false . |
// Enable mic
ITMGContext.GetInstance(this).GetAudioCtrl().EnableMic(true);
This API is used to get the mic status. The returned value 0 indicates that the mic is off, while 1 is on.
public abstract int GetMicState();
int micState = ITMGContext.GetInstance(this).GetAudioCtrl().GetMicState();
This API is used to enable/disable a capturing device. The device is not enabled by default after room entry.
public abstract int EnableAudioCaptureDevice(boolean isEnabled);
Parameter | Type | Description |
---|---|---|
isEnabled | boolean | To enable a capturing device, set this parameter to true ; otherwise, set it to false . |
// Enable capturing device
ITMGContext.GetInstance(this).GetAudioCtrl().EnableAudioCaptureDevice(true);
This API is used to get the status of a capturing device.
public abstract boolean IsAudioCaptureDeviceEnabled();
bool IsAudioCaptureDevice = ITMGContext.GetInstance(this).GetAudioCtrl().IsAudioCaptureDeviceEnabled();
This API is used to enable/disable audio upstreaming. If a capturing device is already enabled, it will send captured audio data; otherwise, it will remain mute. For more information on how to enable/disable the capturing device, please see the EnableAudioCaptureDevice
API.
public abstract int EnableAudioSend(boolean isEnabled);
Parameter | Type | Description |
---|---|---|
isEnabled | boolean | To enable audio upstreaming, set this parameter to true ; otherwise, set it to false . |
ITMGContext.GetInstance(this).GetAudioCtrl().EnableAudioSend(true);
This API is used to get the status of audio upstreaming.
public abstract boolean IsAudioSendEnabled();
bool IsAudioSend = ITMGContext.GetInstance(this).GetAudioCtrl().IsAudioSendEnabled();
This API is used to get the real-time mic volume. An int-type value in the range of 0-100 will be returned. It is recommended to call this API once every 20 ms.
This API is not applicable to the voice message service.
public abstract int GetMicLevel();
int micLevel = ITMGContext.GetInstance(this).GetAudioCtrl().GetMicLevel();
This API is used to get the local real-time audio upstreaming volume. An int-type value in the range of 0-100 will be returned.
This API is not applicable to the voice message service.
ITMGContext TMGAudioCtrl int GetSendStreamLevel()
int Level = ITMGContext.GetInstance(this).GetAudioCtrl().GetSendStreamLevel();
This API is used to set the mic volume. The corresponding parameter is volume
, which is equivalent to attenuating or gaining the captured sound. 0 indicates that the audio is mute, while 100 indicates that the volume remains unchanged. The default value is 100.
This API is not applicable to the voice message service.
public abstract int SetMicVolume(int volume);
Parameter | Type | Description |
---|---|---|
volume | int | Sets volume. Value range: 0-200 |
ITMGContext.GetInstance(this).GetAudioCtrl().SetMicVolume(volume);
This API is used to obtain the microphone volume. An "int" value is returned. Value 101 represents API SetMicVolume has not been called.
This API is not applicable to the voice message service.
public abstract int GetMicVolume();
ITMGContext.GetInstance(this).GetAudioCtrl().GetMicVolume();
This API is used to enable/disable the speaker.
If accompaniment is used, please call this API as instructed in Accompaniment in Voice Chat.
EnableSpeaker = EnableAudioPlayDevice + EnableAudioRecv
public abstract int EnableSpeaker(boolean isEnabled);
Parameter | Type | Description |
---|---|---|
isEnabled | boolean | To disable the speaker, set this parameter to false ; otherwise, set it to true . |
// Enable the speaker
ITMGContext.GetInstance(this).GetAudioCtrl().EnableSpeaker(true);
This API is used to get the speaker status. 0 indicates that the speaker is off, while 1, on.
public abstract int GetSpeakerState();
int micState = ITMGContext.GetInstance(this).GetAudioCtrl().GetSpeakerState();
This API is used to enable/disable a playback device.
public abstract int EnableAudioPlayDevice(boolean isEnabled);
Parameter | Type | Description |
---|---|---|
isEnabled | boolean | To disable a playback device, set this parameter to false ; otherwise, set it to true . |
// Enable the playback device
ITMGContext.GetInstance(this).GetAudioCtrl().EnableAudioPlayDevice(true);
This API is used to get the status of a playback device.
public abstract boolean IsAudioPlayDeviceEnabled();
bool IsAudioPlayDevice = ITMGContext.GetInstance(this).GetAudioCtrl().IsAudioPlayDeviceEnabled();
This API is used to enable/disable audio downstreaming. If a playback device is already enabled, it will play back audio data from other members in the room; otherwise, it will remain mute. For more information on how to enable/disable the playback device, please see the EnableAudioPlayDevice
API.
public abstract int EnableAudioRecv(boolean isEnabled);
Parameter | Type | Description |
---|---|---|
isEnabled | boolean | To enable audio downstreaming, set this parameter to true ; otherwise, set it to false . |
ITMGContext.GetInstance(this).GetAudioCtrl().EnableAudioRecv(true);
This API is used to get the status of audio downstreaming.
public abstract boolean IsAudioRecvEnabled();
bool IsAudioRecv = ITMGContext.GetInstance(this).GetAudioCtrl().IsAudioRecvEnabled();
This API is used to get the real-time speaker volume. An int-type value will be returned to indicate the volume. It is recommended to call this API once every 20 ms.
public abstract int GetSpeakerLevel();
int SpeakLevel = ITMGContext.GetInstance(this).GetAudioCtrl().GetSpeakerLevel();
This API is used to get the real-time audio downstreaming volume of other members in the room. An int-type value will be returned. Value range: 0-200.
public abstract int GetRecvStreamLevel(String openId);
Parameter | Type | Description |
---|---|---|
openId | string | openId of another member in the room |
int Level = ITMGContext.GetInstance(this).GetAudioCtrl().GetRecvStreamLevel(openId);
This API is used to set the volume of a member in the room. It takes effect only on the invoker side.
public abstract int SetSpeakerVolumeByOpenID(String openId, int volume);
Parameter | Type | Description |
---|---|---|
openId | String * | ID of the target user |
volume | int | Range: [0-200]; Default: 100 |
Executed statements
// Lower the volume of user 123333 to 80%
String strOpenID = "1233333";
int nOpenVolume = Integer.valueOf(80);
int nRet = ITMGContext.GetInstance(getActivity()).GetAudioCtrl().SetSpeakerVolumeByOpenID(strOpenID, nOpenVolume);
if (nRet != 0)
{
// Toast error occurred
}
else
{
// Toast set successfully
}
Call this API to get volume set by SetSpeakerVolumeByOpenID
public abstract int GetSpeakerVolumeByOpenID(String openId);
Returns the volume setting of the user with the specified.
This API is used to set the speaker volume.
The corresponding parameter is volume. 0 indicates that the audio is mute, while 100 indicates that the volume remains unchanged. The default value is 100.
public abstract int SetSpeakerVolume(int volume);
Parameter | Type | Description |
---|---|---|
volume | int | Sets the volume. Value range: 0-200 |
int speVol = (int)(value * 100);ITMGContext.GetInstance(this).GetAudioCtrl().SetSpeakerVolume(volume);
This API is used to get the speaker volume. An int-type value will be returned to indicate the volume. 101 indicates that the SetSpeakerVolume
API has not been called.
"Level" indicates the real-time volume, and "Volume" the speaker volume. The final volume = Level * Volume%. For example, if the "Level" is 100 and "Volume" is 60, the final volume is "60".
public abstract int GetSpeakerVolume();
ITMGContext.GetInstance(this).GetAudioCtrl().GetSpeakerVolume();
This API is used to enable in-ear monitoring. You need to call EnableLoopBack+EnableSpeaker
before you can hear your own voice.
public abstract int EnableLoopBack(boolean enable);
Parameter | Type | Description |
---|---|---|
enable | boolean | Specifies whether to enable in-ear monitoring. |
ITMGContext.GetInstance(this).GetAudioCtrl().EnableLoopBack(true);
This API is used to modify a user's room audio type. For the result, please see the callback event. The event type is ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_TYPE
. The audio type of the room is determined by the first user to enter the room. After that, if a member in the room changes the room type, it will take effect for all members there.
public abstract int ChangeRoomType(int nRoomType);
Parameter | Type | Description |
---|---|---|
nRoomType | int | Target room type to be switched to. For room audio types, please see the EnterRoom API. |
ITMGContext.GetInstance(this).GetRoom().ChangeRoomType(nRoomType);
This API is used to get a user's room audio type. The returned value is the room audio type. Value 0 indicates that an error occurred while getting the user's room audio type. For room audio types, please see the EnterRoom
API.
public abstract int GetRoomType();
ITMGContext.GetInstance(this).GetRoom().GetRoomType();
After the room type is set, the event message ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_TYPE
will be returned in the callback. The returned parameters include result
, error_info
, and new_room_type
. The new_room_type
represents the following information. The event message will be identified in the OnEvent
function.
Event Subtype | Parameter | Description |
---|---|---|
ITMG_ROOM_CHANGE_EVENT_ENTERROOM | 1 | Indicates that the existing audio type is inconsistent with and changed to that of the entered room. |
ITMG_ROOM_CHANGE_EVENT_START | 2 | Indicates that a user is already in the room and the audio type starts changing (e.g., calling the ChangeRoomType API to change the audio type). |
ITMG_ROOM_CHANGE_EVENT_COMPLETE | 3 | Indicates that a user is already in the room and the audio type has been changed. |
ITMG_ROOM_CHANGE_EVENT_REQUEST | 4 | Indicates that a room member calls the ChangeRoomType API to request a change of room audio type. |
public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_TYPE == type) {// Process the room type events }}
Message | Data | Sample |
---|---|---|
ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_TYPE | result;error_info;new_room_type;subEventType | {"error_info":"","new_room_type":0,"subEventType":0,"result":0} |
The message for quality monitoring event triggered once every two seconds after room entry is ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_QUALITY
. The returned parameters include weight
, loss
, and delay
, which represent the following information.
This API is used to monitor the network quality. If the user's network is poor, the business layer will remind the user to switch to a better network through the UI.
Parameter | Type | Description |
---|---|---|
weight | int | Value range: 1-50. 50 indicates excellent sound quality, 1 indicates very poor (barely usable) sound quality, and 0 represents an initial meaningless value. Generally, if the value is below 30, the business layer will remind users that the network is poor and recommend them to switch the network. |
loss | double | Upstream packet loss rate |
delay | int | Voice chat delay in ms |
This API is used to get the SDK version number for analysis.
public abstract String GetSDKVersion();
ITMGContext.GetInstance(this).GetSDKVersion();
This API is used to return the mic permission status.
public abstract ITMG_RECORD_PERMISSION CheckMicPermission();
Parameter | Value | Description |
---|---|---|
ITMG_PERMISSION_GRANTED | 0 | Mic permission is granted. |
ITMG_PERMISSION_Denied | 1 | Mic is disabled. |
ITMG_PERMISSION_NotDetermined | 2 | No authorization box has been popped up to request the permission. |
ITMG_PERMISSION_ERROR | 3 | An error occurred while calling the API. |
ITMGContext.GetInstance(this).CheckMicPermission();
This API is used to set the level of logs to be printed, and needs to be called before the initialization. It is recommended to keep the default level.
public abstract int SetLogLevel(int levelWrite, int levelPrint);
Parameter | Type | Description |
---|---|---|
levelWrite | ITMG_LOG_LEVEL | Sets the level of logs to be written. TMG_LOG_LEVEL_NONE indicates not to write. Default value: TMG_LOG_LEVEL_INFO |
levelPrint | ITMG_LOG_LEVEL | Sets the level of logs to be printed. TMG_LOG_LEVEL_NONE indicates not to print. Default value: TMG_LOG_LEVEL_ERROR |
ITMG_LOG_LEVEL | Description |
---|---|
TMG_LOG_LEVEL_NONE | Does not print logs |
TMG_LOG_LEVEL_ERROR | Prints error logs (default) |
TMG_LOG_LEVEL_INFO | Prints info logs |
TMG_LOG_LEVEL_DEBUG | Prints debug logs |
TMG_LOG_LEVEL_VERBOSE | Prints verbose logs |
ITMGContext.GetInstance(this).SetLogLevel(TMG_LOG_LEVEL_INFO,TMG_LOG_LEVEL_INFO);
This API is used to set the log printing path, and needs to be called before initialization. The default path is /sdcard/Android/data/xxx.xxx.xxx/files.
public abstract int SetLogPath(String logDir);
Parameter | Type | Description |
---|---|---|
logDir | String | Path |
ITMGContext.GetInstance(this).SetLogPath(path);
This API is used to get information on the quality of real-time audio/video calls, which is mainly used to view real-time call quality and troubleshoot and can be ignored on the business side.
public abstract String GetQualityTips();
ITMGContext.GetInstance(this).GetRoom().GetQualityTips();
Message | Description |
---|---|
ITMG_MAIN_EVENT_TYPE_ENTER_ROOM | Indicates that a member enters an audio room. |
ITMG_MAIN_EVENT_TYPE_EXIT_ROOM | Indicates that a member exits an audio room. |
ITMG_MAIN_EVENT_TYPE_ROOM_DISCONNECT | Indicates that a room is disconnected for network or other reasons. |
ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_TYPE | Indicates a room type change event. |
ITMG_MAIN_EVNET_TYPE_USER_UPDATE | Indicates that the room members are updated. |
ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_QUALITY | Indicates the room quality information. |
Message | Data | Sample |
---|---|---|
ITMG_MAIN_EVENT_TYPE_ENTER_ROOM | result; error_info | {"error_info":"","result":0} |
ITMG_MAIN_EVENT_TYPE_EXIT_ROOM | result; error_info | {"error_info":"","result":0} |
ITMG_MAIN_EVENT_TYPE_ROOM_DISCONNECT | result; error_info | {"error_info":"waiting timeout, please check your network","result":0} |
ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_TYPE | result; error_info; sub_event_type; new_room_type | {"error_info":"","new_room_type":0,"result":0} |
ITMG_MAIN_EVENT_TYPE_SPEAKER_NEW_DEVICE | result; error_info | {"deviceID":"{0.0.0.00000000}.{a4f1e8be-49fa-43e2-b8cf-dd00542b47ae}","deviceName":"Speaker (Realtek High Definition Audio)","error_info":"","isNewDevice":true,"isUsedDevice":false,"result":0} |
ITMG_MAIN_EVENT_TYPE_SPEAKER_LOST_DEVICE | result; error_info | {"deviceID":"{0.0.0.00000000}.{a4f1e8be-49fa-43e2-b8cf-dd00542b47ae}","deviceName":"Speaker (Realtek High Definition Audio)","error_info":"","isNewDevice":false,"isUsedDevice":false,"result":0} |
ITMG_MAIN_EVENT_TYPE_MIC_NEW_DEVICE | result; error_info | {"deviceID":"{0.0.1.00000000}.{5fdf1a5b-f42d-4ab2-890a-7e454093f229}","deviceName":"Mic (Realtek High Definition Audio)","error_info":"","isNewDevice":true,"isUsedDevice":true,"result":0} |
ITMG_MAIN_EVENT_TYPE_MIC_LOST_DEVICE | result; error_info | {"deviceID":"{0.0.1.00000000}.{5fdf1a5b-f42d-4ab2-890a-7e454093f229}","deviceName":"Mic (Realtek High Definition Audio)","error_info":"","isNewDevice":false,"isUsedDevice":true,"result":0} |
ITMG_MAIN_EVNET_TYPE_USER_UPDATE | user_list; event_id | {"event_id":1,"user_list":["0"]} |
ITMG_MAIN_EVENT_TYPE_NUMBER_OF_USERS_UPDATE | AllUser; AccUser; ProxyUser | {"AllUser":3,"AccUser":2,"ProxyUser":1} |
ITMG_MAIN_EVENT_TYPE_NUMBER_OF_AUDIOSTREAMS_UPDATE | AudioStreams | {"AudioStreams":3} |
ITMG_MAIN_EVENT_TYPE_CHANGE_ROOM_QUALITY | weight; loss; delay | {"weight":5,"loss":0.1,"delay":1} |
Was this page helpful?