Init
API once.using GME;
Context
instance by using the ITMGContext
method instead of QAVContext.GetInstance()
.int ret = ITMGContext.GetInstance().Init(sdkAppId, openID);
Init
API before you can use the real-time voice, voice message, and speech-to-text services. The Init
API must be called in the same thread as other APIs. We recommend you call all APIs in the main thread.//class ITMGContextpublic abstract int Init(string sdkAppID, string openID);
Parameter | Type | Description |
sdkAppId | string | |
openID | string | openID can only be in Int64 type, which is passed in after being converted to a string. You can customize its rules, and it must be unique in the application. To pass in openID as a string, submit a ticket for application. |
int ret = ITMGContext.GetInstance().Init(sdkAppId, openID);// Determine whether the initialization is successful by the returned valueif (ret != QAVError.OK){Debug.Log("SDK initialization failed:"+ret);return;}
Poll
API in update
. The Poll
API is GME's message pump and should be called periodically for GME to trigger event callbacks; otherwise, the entire SDK service will run abnormally. For more information, see the EnginePollHelper
file in SDK Download Guide.public void Update(){ITMGContext.GetInstance().Poll();}
// Delegate function:public delegate void QAVEnterRoomComplete(int result, string error_info);// Event-triggered function:public abstract event QAVEnterRoomComplete OnEnterRoomCompleteEvent;
Delegate function:public delegate void QAVExitRoomComplete();Event-triggered function:public abstract event QAVExitRoomComplete OnExitRoomCompleteEvent;
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. QAVAuthBuffer GenAuthBuffer(int appId, 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 (For voice message, enter "null".) |
openId | string | User ID, which is the same as openId during initialization. |
key | string |
public static byte[] GetAuthBuffer(string AppID, string RoomID,string OpenId, string AuthKey){return QAVAuthBuffer.GenAuthBuffer(int.Parse(AppID), RoomID, OpenId, AuthKey);}
AV_OK
indicates successful API call but not successful room entry.ITMGContext EnterRoom(string roomId, int roomType, byte[] authBuffer)
Parameter | Type | Description |
roomId | String | Room ID, which can contain up to 127 characters |
roomType | ITMGRoomType | Just enter ITMGRoomType.ITMG_ROOM_TYPE_FLUENCY |
authBuffer | byte[] | Authentication code |
ITMGContext.GetInstance().EnterRoom(strRoomId, ITMGRoomType.ITMG_ROOM_TYPE_FLUENCY, byteAuthbuffer);
// Listen on an event:ITMGContext.GetInstance().OnEnterRoomCompleteEvent += new QAVEnterRoomComplete(OnEnterRoomComplete);// Process the event listened on:void OnEnterRoomComplete(int err, string errInfo){if (err != 0) {ShowLoginPanel("error code:" + err + " error message:" + errInfo);return;}else{// Entered room successfully}}
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. |
// Listen on an event:ITMGContext.GetInstance().OnEnterRoomCompleteEvent += new QAVEnterRoomComplete(OnEnterRoomComplete);// Process the event listened on:void OnEnterRoomComplete(int err, string errInfo){if (err != 0) {ShowLoginPanel("error code:" + err + " error message:" + errInfo);return;}else{// Entered room successfully// Turn on micITMGContext.GetInstance().GetAudioCtrl().EnableMic(true);}}
// Listen on an event:ITMGContext.GetInstance().OnEnterRoomCompleteEvent += new QAVEnterRoomComplete(OnEnterRoomComplete);// Process the event listened on:void OnEnterRoomComplete(int err, string errInfo){if (err != 0) {ShowLoginPanel("error code:" + err + " error message:" + errInfo);return;}else{// Entered room successfully// Turn on the speakerITMGContext.GetInstance().GetAudioCtrl().EnableSpeaker(true);}}
ITMGContext.GetInstance().ExitRoom();
Listen on an event:ITMGContext.GetInstance().OnExitRoomCompleteEvent += new QAVExitRoomComplete(OnExitRoomComplete);Process the event listened on:void OnExitRoomComplete(){// Send a callback after room exit}
authBuffer
, please see genAuthBuffer
(the voice chat authentication information API).ITMGPTT int ApplyPTTAuthbuffer (byte[] authBuffer)
Parameter | Type | Description |
authBuffer | String | Authentication |
UserConfig.SetAppID(transform.Find ("appId").GetComponent<InputField> ().text);UserConfig.SetUserID(transform.Find ("userId").GetComponent<InputField> ().text);UserConfig.SetAuthKey(transform.Find("authKey").GetComponent<InputField>().text);byte[] authBuffer = UserConfig.GetAuthBuffer(UserConfig.GetAppID(), UserConfig.GetUserID(), null,UserConfig.GetAuthKey());ITMGContext.GetInstance ().GetPttCtrl ().ApplyPTTAuthbuffer(authBuffer);
StopRecording
. The callback will be returned after the recording is stopped.ITMGPTT int StartRecordingWithStreamingRecognition(string filePath)
Parameter | Type | Description |
filePath | String | Path of stored audio file |
string recordPath = Application.persistentDataPath + string.Format("/{0}.silk", sUid++);int ret = ITMGContext.GetInstance().GetPttCtrl().StartRecordingWithStreamingRecognition(recordPath);
OnStreamingSpeechComplete
or OnStreamingSpeechisRunning
notification, which is as detailed below:OnStreamingSpeechComplete
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.OnStreamingSpeechisRunning
returns the recognized text in real time during the recording, which is equivalent to returning the recognized text while speaking.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 |
// Listen on an event:ITMGContext.GetInstance().GetPttCtrl().OnStreamingSpeechComplete +=new QAVStreamingRecognitionCallback (OnStreamingSpeechComplete);ITMGContext.GetInstance().GetPttCtrl().OnStreamingSpeechisRunning += new QAVStreamingRecognitionCallback (OnStreamingRecisRunning);// Process the event listened on:void OnStreamingSpeechComplete(int code, string fileid, string filepath, string result){// Callback for streaming speech recognition}void OnStreamingRecisRunning(int code, string fileid, string filePath, string result){if (code == 0){setBtnText(mStreamBtn, "Streaming");InputField field = transform.Find("recordFilePath").GetComponent<InputField>();field.text = filePath;field = transform.Find("downloadUrl").GetComponent<InputField>();field.text = "Stream is Running";field = transform.Find("convertTextResult").GetComponent<InputField>();field.text = result;showWarningText("Recording");}}
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 int StopRecording()
ITMGContext.GetInstance().GetPttCtrl().StopRecording();
Was this page helpful?