This document describes the GME APIs for accompaniment in voice chat so that developers can easily integrate and debug them.
API | Description |
---|---|
StartAccompany | Starts playing back the accompaniment. |
StopAccompany | Stops playing back the accompaniment. |
IsAccompanyPlayEnd | Indicates whether the accompaniment is over. |
PauseAccompany | Pauses playing back the accompaniment. |
ResumeAccompany | Resumes playing back the accompaniment. |
SetAccompanyVolume | Sets the accompaniment volume. |
GetAccompanyVolume | Obtains the accompaniment volume. |
SetAccompanyFileCurrentPlayedTimeByMs | Sets the playback progress. |
Note:To use accompaniment in voice chat, you must integrate the GME SDK and enable real-time voice chat.
After you enter a voice chat room, call EnableAudioCaputreDevice
to enable the capturing device, and call StartAccompany
to play back the accompaniment. To capture human voices via the microphone, you should call EnableAudioSend
to enable the microphone first.
This API (StartAccompany) is used to start playing back the accompaniment in M4A, WAV, or MP3 format. Calling this API resets the volume.
ITMGAudioEffectCtrl virtual int StartAccompany(const char* filePath, bool loopBack, int loopCount, int msTime)
Parameter | Type | Description |
---|---|---|
filePath | char* | Path of the accompaniment file. |
loopBack | bool | Indicates whether to output the accompaniment in a mixing mode. This is generally set to true , indicating that the audience can also hear the accompaniment. |
loopCount | int | The number of loops. -1 indicates an infinite loop, and 0 indicates not to play back. |
msTime | int | Delay time |
// Code for Windows
ITMGContextGetInstance()->GetAudioEffectCtrl()->StartAccompany(filePath,true,-1,0);
// Code for Android
ITMGContext.GetInstance(this).GetAudioEffectCtrl().StartAccompany(filePath,true,loopCount,0);
// Code for iOS
[[[ITMGContext GetInstance] GetAudioEffectCtrl] StartAccompany:path loopBack:isLoopBack loopCount:loopCount msTime:0];
Call the StartAccompanyDownloading
API to start downloading and playing back the accompaniment. The accompaniment download is implemented in the code. When the download is not completed, the file path can be passed as a parameter to StartAccompanyDownloading
, which can implement download-and-play. fileSize
is the estimated full file size. When calling this API to pass in a partially downloaded file, first ensure that the file size is at least 10 KB.
ITMGAudioEffectCtrl virtual int StartAccompany(const char* filePath, bool loopBack, int loopCount, int msTime, int fileSize)
Note:For the iOS client, follow the steps below:
After the accompaniment is over, call the function OnEvent
, and the event message ITMG_MAIN_EVENT_TYPE_ACCOMPANY_FINISH will be returned.
The returned parameter data
includes “result” and “file_path”.
void TMGTestScene::OnEvent(ITMG_MAIN_EVENT_TYPE eventType,const char* data){
switch (eventType) {
case ITMG_MAIN_EVENT_TYPE_ENTER_ROOM:
{
// Process
break;
}
...
case ITMG_MAIN_EVENT_TYPE_ACCOMPANY_FINISH:
{
// Process
break;
}
}
}
This API (StopAccompany) is used to stop playing back the accompaniment.
ITMGAudioEffectCtrl virtual int StopAccompany(int duckerTime)
Parameter | Type | Description |
---|---|---|
duckerTime | int | Ducking time |
ITMGContextGetInstance()->GetAudioEffectCtrl()->StopAccompany(0);
If it is over, true
is returned. If it is not, false
is returned.
ITMGAudioEffectCtrl virtual bool IsAccompanyPlayEnd()
ITMGContextGetInstance()->GetAudioEffectCtrl()->IsAccompanyPlayEnd();
This API (PauseAccompany) is used to pause the accompaniment playback.
ITMGAudioEffectCtrl virtual int PauseAccompany()
ITMGContextGetInstance()->GetAudioEffectCtrl()->PauseAccompany();
This API (ResumeAccompany) is used to resume the accompaniment playback.
ITMGAudioEffectCtrl virtual int ResumeAccompany()
ITMGContextGetInstance()->GetAudioEffectCtrl()->ResumeAccompany();
This API is used to specify whether the speaker can hear the accompaniment.
ITMGAudioEffectCtrl virtual int EnableAccompanyPlay(bool enable)
Parameter | Type | Description |
---|---|---|
enable | bool | Indicates whether the audience can hear the accompaniment. |
ITMGContextGetInstance()->GetAudioEffectCtrl()->EnableAccompanyPlay(false);
This API is used to specify whether the audience can hear the accompaniment.
ITMGAudioEffectCtrl virtual int EnableAccompanyLoopBack(bool enable)
Parameter | Type | Description |
---|---|---|
enable | bool | Indicates whether the audience can hear the accompaniment. |
ITMGContextGetInstance()->GetAudioEffectCtrl()->EnableAccompanyLoopBack(false);
This API (SetAccompanyVolume) is used to set the accompaniment volume. Value range: 0 - 200. The default value is 100. A value greater than 100 means volume up, while a value less than 100 means volume down.
ITMGAudioEffectCtrl virtual int SetAccompanyVolume(int vol)
Parameter | Type | Description |
---|---|---|
vol | int | Specifies the volume value. |
int vol=100;
ITMGContextGetInstance()->GetAudioEffectCtrl()->SetAccompanyVolume(vol);
This API (GetAccompanyVolume) is used to obtain the accompaniment volume.
ITMGAudioEffectCtrl virtual int GetAccompanyVolume()
ITMGContextGetInstance()->GetAudioEffectCtrl()->GetAccompanyVolume();
This action requires using both of these two APIs: GetAccompanyFileTotalTimeByMs
and GetAccompanyFileCurrentPlayedTimeByMs
. Please note that Current/Total = current loop times, and Current % Total = current loop playback position.
ITMGAudioEffectCtrl virtual int GetAccompanyFileTotalTimeByMs()
ITMGAudioEffectCtrl virtual int GetAccompanyFileCurrentPlayedTimeByMs()
ITMGContextGetInstance()->GetAudioEffectCtrl()->GetAccompanyFileTotalTimeByMs();
ITMGContextGetInstance()->GetAudioEffectCtrl()->GetAccompanyFileCurrentPlayedTimeByMs();
This API (SetAccompanyFileCurrentPlayedTimeByMs) is used to set the playback progress.
ITMGAudioEffectCtrl virtual int SetAccompanyFileCurrentPlayedTimeByMs(unsigned int time)
Parameter | Type | Description |
---|---|---|
time | int | Specifies the playback progress in milliseconds |
ITMGContextGetInstance()->GetAudioEffectCtrl()->SetAccompanyFileCurrentPlayedTimeByMs(time);
This API (SetAccompanyKey) is used to specify the accompaniment key, and should be called before starting the accompaniment playback.
ITMGAudioEffectCtrl virtual int SetAccompanyKey(int nKey)
Parameter | Type | Description |
---|---|---|
nKey | int | Key(s) to adjust by. Value range (recommended): -4 to 4, where 0 indicates using the original key. |
Error Message | Error Code | Description | Solution |
---|---|---|---|
QAV_ERR_ACC_OPENFILE_FAILED | 4001 | Failed to open the file | Checks whether the file or its path exists, and whether you have access to the file. |
QAV_ERR_ACC_FILE_FORAMT_NOTSUPPORT | 4002 | Invalid file format | Checks whether the file format is correct. |
QAV_ERR_ACC_DECODER_FAILED | 4003 | Decoding failure | Checks whether the file format is correct. |
QAV_ERR_ACC_BAD_PARAM | 4004 | Invalid parameter | Checks whether the parameters in the code are correct. |
QAV_ERR_ACC_MEMORY_ALLOC_FAILED | 4005 | Memory allocation failed | System resources have run out. If this error persists, please submit a ticket for assistance. |
QAV_ERR_ACC_CREATE_THREAD_FAILED | 4006 | Failed to create a thread | System resources have run out. If this error persists, please submit a ticket for assistance. |
QAV_ERR_ACC_STATE_ILLIGAL | 4007 | Invalid state | This error occurs if an API is called in a state that does not allow calling. |
Was this page helpful?