tencent cloud

Feedback

Sound Effect and Accompaniment

Last updated: 2023-04-27 17:06:32
This document describes how to integrate with and debug GME APIs for the karaoke feature in voice chat.

Prerequisites

To use the karaoke feature in voice chat, you must integrate the GME SDK and enable voice chat.
The room type parameter needs to be specified during room entry. Set RoomType to 2 (recommended) or 3 for room entry.
If an error code is returned, troubleshoot as instructed in Error Codes.

Flowchart

The room entry process is as shown below:




Voice chat room entry APIs:
ITMGContext.GetInstance(this).Init(String.valueOf(mAppId), mUserId);// Initialize the SDK
ITMGContext.GetInstance(this).SetTMGDelegate(new MyDelegate());// Set the delegate class to receive various callbacks and events
EnginePollHelper.createEnginePollHelper();// Call `Poll` periodically to trigger callbacks

byte[] authbuff = AuthBuffer.getInstance().genAuthBuffer(mAppId, mRoomId, mUserId,mAppKey);// Get the authentication information
ITMGContext.GetInstance(this).EnterRoom(mRoomId, 2, authbuff);// Enter a room
Note
For more information on the call process and APIs, see Game Multimedia Engine.

Getting Karaoke Feature APIs

1. Download the standard SDK file in SDK Download Guide.
2. Download and import the karaoke feature API file for your platform.
Note
This feature supports the MP3 and OGG formats.
For OGG audio files, click here to download the dynamic OGG library (you don't need to import the library for the SDK for iOS as it is provided in the SDK).
For MP3 audio files, click here to download the dynamic MP3 library (you need to import it only for the SDK for iOS).

Configuration for Android

APIs for Android are provided in the standard JAR package, so you don't need to download additional API files.

Configuration for iOS

1. To use the karaoke feature on iOS, you need to download the dynamic MP3 library and import it to your project.
2. Import the downloaded library and add it in Link Binary With Libraries.
3. Add the TMGEngine_adv.h header file to the same directory as the other SDK header files in your project.

Configuration for Windows

To use the karaoke feature on Windows, download header files tmg_sdk_adv.h and tmg_type_adv.h and import them to the project.

Configuration for the Unity engine

To use the karaoke feature in a game with the Unity engine, download and copy the header files TMGEngine_Adv.cs and ITMGEngine_Adv.cs in the Unity folder to the project to import them.
To export the project for iOS, import the dynamic MP3 library as described above.

Recording APIs

Starting recording

The StartRecord API is used to start recording. There is a callback function for recording completion, and you need to listen for ITMG_MAIN_EVENT_TYPE_RECORD_COMPLETED.
Make sure that the mic is turned on during recording (both the device and upstreaming need to be enabled) and the file path is accessible, as the SDK doesn't create folders actively.

Function prototype

int StartRecord(int type, String dstFile, String accMixFile, String accPlayFile)
Parameter
Type
Description
type
int
Set this parameter to ITMG_AUDIO_RECORDING_KTV in a karaoke scenario or ITMG_AUDIO_RECORDING_SELF for an MP3 recording file.
dstFile
String
Target file path for saving the recorded music
accMixFile
String
Accompaniment without the original vocals, which can be mixed with voice to generate a music file.
accPlayFile
String
Music file to be played back, which is the same file as accMixFile in normal cases. However, if the user is unfamiliar with the song, this parameter can be set to the path of the music file with the original vocals. In this case, the file with the original vocals will be played back, but the accompaniment without the original vocals will be mixed.

Sample code

//Android
ITMGAudioRecordCtrl.GetInstance().StartRecord(ITMGAudioRecordCtrl.ITMG_AUDIO_RECORDING_KTV, dstFile, accMixFile, accPlayFile);
// iOS
#import "GMESDK/TMGEngine_adv.h"
[[ITMGAudioRecordCtrl GetInstance]StartPreview]

Stopping recording

The StopRecord API is used to stop recording.

Function prototype

int StopRecord()

Pausing recording

The PauseRecord API is used to pause recording.

Function prototype

int PauseRecord()

Resuming recording

The ResumeRecord API is used to resume recording.

Function prototype

int ResumeRecord()

Recording callback

ITMG_MAIN_EVENT_TYPE_RECORD_COMPLETED is the callback for recording completion, which will be triggered when the accompaniment playback ends or StopRecord is called.

Callback parameters

Parameter
Type
Description
result
int
Recording result. 0 indicates success. For other error codes, troubleshoot as instructed in Error Codes.
filepath
String
Target file path, which is the same as the dstFile parameter passed in through StartRecord.
duration
String
Recording file duration in ms.

Setting the file to be played back

When the StartRecord API is called for recording, the music file to be played back will be set. This API can be used to set another file for playback. Generally, it is used to switch between the song with vocals and accompaniment without vocals.

Function prototype

int SetAccompanyFile(String accPlayFile)
Parameter
Type
Description
accPlayFile
String
Music file to be played back

Getting the accompaniment duration

This API is used to get the duration of the accompaniment file accMixFile in ms.

Function prototype

int GetAccompanyTotalTimeByMs()

Getting the current recording duration

This API is used to get the current recording duration in ms.

Function prototype

int GetRecordTimeByMs()

Seeking for recording

This API is used to seek to the specified time for recording. If the parameter value is earlier than the current time, the repeated part will be recorded again. If the parameter value is later than the current time, the unrecorded part will be filled with silence.

Function prototype

int SetRecordTimeByMs(int timeMs)
Parameter
Type
Description
timeMs
int
The time to be sought to in ms

Karaoke File Preview

Getting the recording file duration

This API is used to get the recording file duration.

Function prototype

int GetRecordFileDurationByMs()

Starting recording file preview

This API is used to start recording file preview.

Function prototype

int StartPreview()

Stopping recording file preview

This API is used to stop recording file preview.

Function prototype

int StopPreview()

Pausing recording file preview

This API is used to pause recording file preview.

Function prototype

int PausePreview()

Resuming recording file preview

This API is used to resume recording file preview.

Function prototype

int ResumePreview()

Setting the current preview time point

This API is used to set the current preview time point.

Function prototype

int SetPreviewTimeByMs(int time)
Parameter
Type
Description
time
int
Preview file time point in ms

Getting the current preview time point

This API is used to get the current preview time point.

Function prototype

int GetPreviewTimeByMs()

Playback preview callback

ITMG_MAIN_EVENT_TYPE_RECORD_PREVIEW_COMPLETED is the callback for preview completion, which will be triggered when the preview file playback ends or the StopPreview API is called.

Callback parameters

Parameter
Type
Description
result
int
Playback result. 0 indicates success.

File Mix APIs

Mixing files

This API is used to mix the recorded voice and accompaniment into a file.

Function prototype

int MixRecordFile();

Canceling mix

This API is used to cancel the mix operation.

Function prototype

int CancelMixRecordFile();

File mix callback

ITMG_MAIN_EVENT_TYPE_RECORD_MIX_COMPLETED is the callback for mix completion.

Callback parameters

Parameter
Type
Description
result
int
Mix result. 0 indicates success.
filepath
String
Target file path, which is the same as the dstFile parameter passed in through StartRecord.
duration
String
Recording file duration in ms.

Advanced Settings

Setting the accompaniment volume level ratio

This API is used to set both the ratios of the voice and accompaniment volume levels after recording.

Function prototype

int SetMixWieghts(float mic, float acc)
Parameter
Type
Description
mic
float
Ratio of the voice volume level. Value range: 0–2. 1.0, a value less than 1.0, and a value greater than 1.0 indicate to keep, decrease, and increase the original volume level respectively.
acc
float
Ratio of the accompaniment volume level. Value range: 0–2. 1.0, a value less than 1.0, and a value greater than 1.0 indicate to keep, decrease, and increase the original volume level respectively.

Setting the offset

This API is used to set the offset of the voice against the accompaniment. Generally, it is used to align the voice with beats after recording.

Function prototype

int AdjustAudioTimeByMs(int time)
Parameter
Type
Description
time
int
Offset of the voice against the accompaniment in ms. If the value is greater than 0, the voice will be moved backward; if the value is less than 0, the voice will be moved forward.

Setting the sound effect

This API is used to set the sound effect during or after recording. For specific karaoke sound effects, see Sound Effect in Voice Chat.

Function prototype

int SetRecordKaraokeType(int type)
Parameter
Type
Description
type
int
This type is the same as the karaoke sound effect type in voice chat. For more information, see Sound Effect in Voice Chat.
Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support