Init
API once.#include "tmg_sdk.h"class UEDEMO1_API AUEDemoLevelScriptActor : public ALevelScriptActor, public ITMGDelegate{public:...private:...}
ITMGContext
first before you can call the EnterRoom
function, because all calls begin with ITMGContext
and callbacks are passed to the application through ITMGDelegate
.ITMGContext* context = ITMGContextGetInstance();context->SetTMGDelegate(this);
//class ITMGContextITMGContext virtual int Init(const char* sdkAppId, const char* openId)
Parameter | Type | Description |
sdkAppId | const char* | |
OpenId | const char* | OpenId can only be in Int64 type, which is passed after being converted to a string. |
std::string appid = TCHAR_TO_UTF8(CurrentWidget->editAppID->GetText().ToString().operator*());std::string userId = TCHAR_TO_UTF8(CurrentWidget->editUserID->GetText().ToString().operator*());ITMGContextGetInstance()->Init(appid.c_str(), userId.c_str());
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 UEDemoLevelScriptActor.cpp file in the demo.// Declaration in the header filevirtual void Tick(float DeltaSeconds);void AUEDemoLevelScriptActor::Tick(float DeltaSeconds) {Super::Tick(DeltaSeconds);ITMGContextGetInstance()->Poll();}
Delegate
method to send callback notifications to the application. ITMG_MAIN_EVENT_TYPE
indicates the message type. The data on Windows is in json string format. For the key-value pairs, please see the relevant documentation.// Function implementation://UEDemoLevelScriptActor.h:class UEDEMO1_API AUEDemoLevelScriptActor : public ALevelScriptActor, public SetTMGDelegate{public:void OnEvent(ITMG_MAIN_EVENT_TYPE eventType, const char* data);}//UEDemoLevelScriptActor.cpp:void AUEDemoLevelScriptActor::OnEvent(ITMG_MAIN_EVENT_TYPE eventType, const char* data){// Identify and manipulate `eventType` here}
AuthBuffer
for encryption and authentication of relevant features.To get authentication for voice message and speech-to-text, the room ID parameter must be set to null
.int QAVSDK_AuthBuffer_GenAuthBuffer(unsigned int dwSdkAppID, const char* strRoomID, const char* strOpenID,const char* strKey, unsigned char* strAuthBuffer, unsigned int bufferLength);
Parameter | Type | Description |
dwSdkAppID | int | AppId from the Tencent Cloud console. |
strRoomID | char* | Room ID, which can contain up to 127 characters. |
strOpenID | char* | User ID, which is the same as openID during initialization. |
strKey | char* | |
strAuthBuffer | char* | Returned authbuff |
bufferLength | int | Length of the authbuff passed in. 500 is recommended. |
unsigned int bufferLen = 512;unsigned char retAuthBuff[512] = {0};QAVSDK_AuthBuffer_GenAuthBuffer(atoi(SDKAPPID3RD), roomId, "10001", AUTHKEY,retAuthBuff,bufferLen);
ITMGContext virtual int EnterRoom(const char* roomID, ITMG_ROOM_TYPE roomType, const char* authBuff, int buffLen)
Parameter | Type | Description |
roomId | char* | Room ID, which can contain up to 127 characters |
roomType | ITMG_ROOM_TYPE | Room audio type |
authBuffer | char* | Authentication key |
buffLen | int | Authentication key length |
ITMGContext* context = ITMGContextGetInstance();context->EnterRoom(roomID, ITMG_ROOM_TYPE_FLUENCY, (char*)retAuthBuff,bufferLen);
void UBaseViewController::OnEvent(ITMG_MAIN_EVENT_TYPE eventType, const char *data) {FString jsonData = FString(UTF8_TO_TCHAR(data));TSharedPtr<FJsonObject> JsonObject;TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(FString(UTF8_TO_TCHAR(data)));FJsonSerializer::Deserialize(Reader, JsonObject);if (eventType == ITMG_MAIN_EVENT_TYPE_ENTER_ROOM) {int32 result = JsonObject->GetIntegerField(TEXT("result"));FString error_info = JsonObject->GetStringField(TEXT("error_info"));if (result == 0) {GEngine->AddOnScreenDebugMessage(INDEX_NONE, 20.0f, FColor::Yellow, TEXT("Enter room success."));}else {FString msg = FString::Printf(TEXT("Enter room failed. result=%d, info = %ls"), result, *error_info);GEngine->AddOnScreenDebugMessage(INDEX_NONE, 20.0f, FColor::Yellow, *msg);}onEnterRoomCompleted(result, error_info);}}
Error Code Value | Cause and Suggested Solution |
7006 | Authentication failed. Possible causes: The `AppID` does not exist or is incorrect. An error occurred while authenticating the `authbuff`. Authentication expired. The `openId` does not meet the specification. |
7007 | 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. |
void UBaseViewController::OnEvent(ITMG_MAIN_EVENT_TYPE eventType, const char *data) {FString jsonData = FString(UTF8_TO_TCHAR(data));TSharedPtr<FJsonObject> JsonObject;TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(FString(UTF8_TO_TCHAR(data)));FJsonSerializer::Deserialize(Reader, JsonObject);if (eventType == ITMG_MAIN_EVENT_TYPE_ENTER_ROOM) {int32 result = JsonObject->GetIntegerField(TEXT("result"));FString error_info = JsonObject->GetStringField(TEXT("error_info"));if (result == 0) {GEngine->AddOnScreenDebugMessage(INDEX_NONE, 20.0f, FColor::Yellow, TEXT("Enter room success."));// Enable micITMGContextGetInstance()->GetAudioCtrl()->EnableMic(true);}else {FString msg = FString::Printf(TEXT("Enter room failed. result=%d, info = %ls"), result, *error_info);GEngine->AddOnScreenDebugMessage(INDEX_NONE, 20.0f, FColor::Yellow, *msg);}onEnterRoomCompleted(result, error_info);}}
void UBaseViewController::OnEvent(ITMG_MAIN_EVENT_TYPE eventType, const char *data) {FString jsonData = FString(UTF8_TO_TCHAR(data));TSharedPtr<FJsonObject> JsonObject;TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(FString(UTF8_TO_TCHAR(data)));FJsonSerializer::Deserialize(Reader, JsonObject);if (eventType == ITMG_MAIN_EVENT_TYPE_ENTER_ROOM) {int32 result = JsonObject->GetIntegerField(TEXT("result"));FString error_info = JsonObject->GetStringField(TEXT("error_info"));if (result == 0) {GEngine->AddOnScreenDebugMessage(INDEX_NONE, 20.0f, FColor::Yellow, TEXT("Enter room success."));// Enable the speakerITMGContextGetInstance()->GetAudioCtrl()->EnableSpeaker(true);}else {FString msg = FString::Printf(TEXT("Enter room failed. result=%d, info = %ls"), result, *error_info);GEngine->AddOnScreenDebugMessage(INDEX_NONE, 20.0f, FColor::Yellow, *msg);}onEnterRoomCompleted(result, error_info);}}
ITMGContext* context = ITMGContextGetInstance();context->ExitRoom();
void TMGTestScene::OnEvent(ITMG_MAIN_EVENT_TYPE eventType,const char* data){switch (eventType) {case ITMG_MAIN_EVENT_TYPE_EXIT_ROOM:{// Processbreak;}}}
authBuffer
, please see genAuthBuffer
(the voice chat authentication information API).ITMGPTT virtual int ApplyPTTAuthbuffer(const char* authBuffer, int authBufferLen)
Parameter | Type | Description |
authBuffer | char* | Authentication |
authBufferLen | int | Authentication length |
ITMGContextGetInstance()->GetPTT()->ApplyPTTAuthbuffer(authBuffer,authBufferLen);
StopRecording
. The callback will be returned after the recording is stopped.ITMGPTT virtual int StartRecordingWithStreamingRecognition(const char* filePath)ITMGPTT virtual int StartRecordingWithStreamingRecognition(const char* filePath,const char* translateLanguage,const char* translateLanguage)
Parameter | Type | Description |
filePath | char* | Path of stored audio file |
speechLanguage | char* | The language in which the audio file is to be converted to text. For parameters, please see Language Parameter Reference List |
translateLanguage | char* | The language into which the audio file will be translated. For parameters, please see Language Parameter Reference List (This parameter is currently unavailable. Enter the same value as that of speechLanguage ) |
ITMGContextGetInstance()->GetPTT()->StartRecordingWithStreamingRecognition(filePath,"cmn-Hans-CN","cmn-Hans-CN");
onEvent
. The event message is ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_COMPLETE
, namely returns text after the recording is stopped and the recognition is completed, which is equivalent to returning the recognized text after a paragraph of speech.OnEvent function
based on the actual needs. The passed parameters include the following four messages.Message Name | Description |
result | A return code for judging whether the streaming speech recognition is successful. |
text | Text converted from speech |
file_path | Local path of stored recording file |
file_id | Backend URL address of recording file, which will be retained for 90 days |
void UBaseViewController::OnEvent(ITMG_MAIN_EVENT_TYPE eventType, const char *data) {FString jsonData = FString(UTF8_TO_TCHAR(data));TSharedPtr<FJsonObject> JsonObject;TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(FString(UTF8_TO_TCHAR(data)));FJsonSerializer::Deserialize(Reader, JsonObject);...else if(eventType == ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_COMPLETE){int32 nResult = JsonObject->GetIntegerField(TEXT("result"));FString text = JsonObject->GetStringField(TEXT("text"));FString fileid = JsonObject->GetStringField(TEXT("file_id"));FString file_path = JsonObject->GetStringField(TEXT("file_path"));onPttStreamRecognitionCompleted(nResult,file_path, fileid, text);}else if(eventType == ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_IS_RUNNING){int32 nResult = JsonObject->GetIntegerField(TEXT("result"));FString text = JsonObject->GetStringField(TEXT("text"));FString fileid = TEXT("STREAMINGRECOGNITION_IS_RUNNING");FString file_path = JsonObject->GetStringField(TEXT("file_path"));onPttStreamRecognitionisRunning(nResult,file_path, fileid, text);}}
Error Code | Description | Suggested Solution |
32775 | Streaming speech-to-text conversion failed, but recording succeeded. | Call the `UploadRecordedFile` API to upload the recording file and then call the `SpeechToText` API to perform speech-to-text conversion. |
32777 | Streaming speech-to-text converting failed, but recording and upload succeeded | The message returned contains a backend URL after successful upload. Call the `SpeechToText` API to perform speech-to-text conversion. |
32786 | Streaming speech-to-text conversion failed. | During streaming recording, wait for the execution result of the streaming recording API to return. |
ITMGPTT virtual int StopRecording()
ITMGContextGetInstance()->GetPTT()->StopRecording();
Was this page helpful?