#include "tmg_sdk.h"class UEDEMO1_API AUEDemoLevelScriptActor : public ALevelScriptActor, public ITMGDelegate{public:...private:...}
ITMGContext* context = ITMGContextGetInstance();context->SetTMGDelegate(this);
//class ITMGContextITMGContext virtual int Init(const char* sdkAppId, const char* openId)
参数 | 类型 | 含义 |
sdkAppId | const char* | |
OpenId | const char* | OpenId 只支持 Int64 类型(转为 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());
//头文件中的声明virtual void Tick(float DeltaSeconds);void AUEDemoLevelScriptActor::Tick(float DeltaSeconds) {Super::Tick(DeltaSeconds);ITMGContextGetInstance()->Poll();}
//函数实现://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){//在此对eventType进行判断及操作}
int QAVSDK_AuthBuffer_GenAuthBuffer(unsigned int dwSdkAppID, const char* strRoomID, const char* strOpenID,const char* strKey, unsigned char* strAuthBuffer, unsigned int bufferLength);
参数 | 类型 | 含义 |
dwSdkAppID | int | 来自腾讯云控制台的 AppId 号码 |
strRoomID | char* | 房间号,最大支持127字符 |
strOpenID | char* | 用户标识。与 Init 时候的 openID相同。 |
strKey | char* | |
strAuthBuffer | char* | 返回的 authbuff |
bufferLength | int | 传入的 authbuff 长度,建议为 500 |
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)
参数 | 类型 | 含义 |
roomID | char* | 房间号,最大支持127字符 |
roomType | ITMG_ROOM_TYPE | 房间音频类型 |
authBuffer | char* | 鉴权码 |
buffLen | int | 鉴权码长度 |
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);}}
错误码值 | 原因及建议方案 |
7006 | 鉴权失败,原因如下: AppID 不存在或者错误 authbuff 鉴权错误 鉴权过期 openId 不符合规范 |
7007 | 已经在其它房间 |
1001 | 已经在进房过程中,然后又重复了此操作。建议在进房回调返回之前不要再调用进房接口 |
1003 | 已经进房了在房间中,又调用一次进房接口 |
1101 | 确保已经初始化 SDK,确保 openId 是否符合规则,或者确保在同一线程调用接口,以及确保 Poll 接口正常调用 |
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."));//打开麦克风ITMGContextGetInstance()->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."));//打开扬声器ITMGContextGetInstance()->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:{//进行处理break;}}}
ITMGPTT virtual int ApplyPTTAuthbuffer(const char* authBuffer, int authBufferLen)
参数 | 类型 | 含义 |
authBuffer | char* | 鉴权 |
authBufferLen | int | 鉴权长度 |
ITMGContextGetInstance()->GetPTT()->ApplyPTTAuthbuffer(authBuffer,authBufferLen);
ITMGPTT virtual int StartRecordingWithStreamingRecognition(const char* filePath)ITMGPTT virtual int StartRecordingWithStreamingRecognition(const char* filePath,const char* translateLanguage,const char* translateLanguage)
参数 | 类型 | 含义 |
filePath | char* | 存放的语音路径 |
speechLanguage | char* | 识别成指定文字的语言参数,参数请参考 语音转文字的语言参数参考列表 |
translateLanguage | char* |
ITMGContextGetInstance()->GetPTT()->StartRecordingWithStreamingRecognition(filePath,"cmn-Hans-CN","cmn-Hans-CN");
ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_COMPLETE
,在停止录制并完成识别后才返回文字,相当于一段话说完才会返回识别的文字。消息名称 | 含义 |
result | 用于判断流式语音识别是否成功的返回码 |
text | 语音转文字识别的文本 |
file_path | 录音存放的本地地址 |
file_id | 录音在后台的 url 地址,录音在服务器存放90天 |
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);}}
错误码 | 含义 | 处理方式 |
32775 | 流式语音转文本失败,但是录音成功 | 调用 UploadRecordedFile 接口上传录音,再调用 SpeechToText 接口进行语音转文字操作 |
32777 | 流式语音转文本失败,但是录音成功,上传成功 | 返回的信息中有上传成功的后台 url 地址,调用 SpeechToText 接口进行语音转文字操作 |
32786 | 流式语音转文本失败 | 在流式录制状态当中,请等待流式录制接口执行结果返回 |
ITMGPTT virtual int StopRecording()
ITMGContextGetInstance()->GetPTT()->StopRecording();
本页内容是否解决了您的问题?