Init
and Poll
.AppID
and key. For more information, see Activating Services.QAVError.OK
will be returned with the value being 0
.Poll
API should be called periodically for GME to trigger event callbacks.Poll
periodically to trigger callbacksClass | Description |
ITMGContext | Core APIs |
ITMGPTT | Voice messaging and speech-to-text APIs |
API | Description |
Init | Initializes GME. |
Poll | Triggers an event callback. |
Pause | Pauses the system. |
Resume | Resumes the system. |
Uninit | Uninitializes GME. |
using GME;
Context
instance by using the ITMGContext
method instead of QAVContext.GetInstance()
.Init
API before you can use the real-time voice chat, 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. |
Return Value | Handling |
QAVError.OK= 0 | The SDK was initialized successfully. |
AV_ERR_SDK_NOT_FULL_UPDATE=7015 | Checks whether the SDK file is complete. We recommend that you delete it and then import it again. |
AV_ERR_SDK_NOT_FULL_UPDATE
is only a reminder but will not cause an initialization failure.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.Poll
API must be called periodically and in the main thread to avoid abnormal API callbacks.ITMGContext public abstract int Poll();
public void Update(){ITMGContext.GetInstance().Poll();}
Pause
event occurs in the system, the engine should also be notified for pause. For example, when the application switches to the background (OnApplicationPause, isPause=True), and you do not need the background to play back the audio in the room, please call Pause
API to pause the GME service.ITMGContext public abstract int Pause()
Resume
event occurs in the system, the engine should also be notified for resumption. The Resume
API only supports resuming voice chat.ITMGContext public abstract int Resume()
openid
, switching game account requires uninitializing GME and then using the new openid
to initialize again.ITMGContext public abstract int Uninit()
SetMaxMessageLength
API to set it after initialization.API | Description |
GenAuthBuffer | Generates the local authentication key. |
ApplyPTTAuthbuffer | Initializes authentication. |
SetMaxMessageLength | Specifies the maximum duration of a voice message. |
AuthBuffer
for encryption and authentication of relevant features. For release in the production environment, 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 | Enter null or an empty string. |
openId | string | User ID, which is the same as OpenId during initialization. |
key | string |
ITMGPTT int ApplyPTTAuthbuffer (byte[] authBuffer)
Parameter | Type | Description |
authBuffer | byte[] | 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);
ITMGPTT int SetMaxMessageLength(int msTime)
Parameter | Type | Description |
msTime | int | Audio duration in ms. Value range: 1000 < msTime < = 58000. |
ITMGContext.GetInstance().GetPttCtrl().SetMaxMessageLength(58000);
API | Description |
StartRecordingWithStreamingRecognition | Starts streaming recording. |
StopRecording | This API is used to stop audio recording. |
ITMGPTT int StartRecordingWithStreamingRecognition(string filePath)ITMGPTT int StartRecordingWithStreamingRecognition(string filePath, string speechLanguage,string translateLanguage)
Parameter | Type | Description |
filePath | String | Path of the stored audio file |
speechLanguage | String | The language in which the audio file is to be converted to text. For parameters, see Language Parameter Reference List. |
translateLanguage | String | Enter the value of speechLanguage . |
string recordPath = Application.persistentDataPath + string.Format("/{0}.silk", sUid++);int ret = ITMGContext.GetInstance().GetPttCtrl().StartRecordingWithStreamingRecognition(recordPath, "cmn-Hans-CN","cmn-Hans-CN");
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
notification based on the actual needs. The passed parameters include the following four messages.Parameter | Description |
result | Return code indicating whether streaming speech-to-text conversion is successful |
text | Text converted from speech |
file_path | Local path of the stored recording file |
file_id | Backend URL address of recording file, which will be retained for 90 days |
Error Code | Description | 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 conversion 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. |
32787 | Speech-to-text conversion succeeded, but the text translation service was not activated. | Activate the text translation service in the console. |
32788 | Speech-to-text conversion succeeded, but the language parameter of the text translation service was invalid. | Check the parameter passed in. |
// 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");}}
API | Description |
StartRecording | Starts recording. |
PauseRecording | Pauses recording. |
ResumeRecording | Resumes recording. |
StopRecording | This API is used to stop audio recording. |
CancelRecording | Cancels recording. |
ITMGPTT int StartRecording(string fileDir)
Parameter | Type | Description |
fileDir | string | Path of the stored audio file |
string recordPath = Application.persistentDataPath + string.Format ("/{0}.silk", sUid++);int ret = ITMGContext.GetInstance().GetPttCtrl().StartRecording(recordPath);
ITMGPTT int StopRecording()
ITMGContext.GetInstance().GetPttCtrl().StopRecording();
StopRecording
**. The callback for recording start will be returned after the recording is stopped.public delegate void QAVRecordFileCompleteCallback(int code, string filepath);public abstract event QAVRecordFileCompleteCallback OnRecordFileComplete;
Parameter | Type | Description |
code | string | 0 : Recording is completed. |
filepath | string | Path of the stored recording file, which must be accessible and cannot be the fileid . |
Error Code | Caused By | Suggestion |
4097 | Empty parameters. | Check whether the API parameters in the code are correct. |
4098 | An initialization error occurred. | Check whether the device is being used, whether the permissions are normal, and whether the initialization is normal. |
4099 | Recording is in progress. | Make sure that the SDK recording feature is used at the right time. |
4100 | No audio data is captured. | Check whether the mic is working properly. |
4101 | An error occurred while accessing the file during recording. | Ensure the existence of the file and the validity of the file path. |
4102 | The mic is not authorized. | The mic permission is required for using the SDK. To add the permission, see the SDK project configuration document for the corresponding engine or platform. |
4103 | The recording duration is too short. | The recording duration should be in ms and longer than 1,000 ms. |
4104 | No recording operation is started. | Check whether the recording starting API has been called. |
// Listen on an eventITMGContext.GetInstance().GetPttCtrl().OnRecordFileComplete += new QAVRecordFileCompleteCallback (OnRecordFileComplete);// Process the event listened onvoid OnRecordFileComplete(int code, string filepath){// Callback for recording start}
ResumeRecording
API.ITMGPTT int PauseRecording()
ITMGContext.GetInstance().GetPttCtrl().PauseRecording();
ITMGPTT int ResumeRecording()
ITMGContext.GetInstance().GetPttCtrl().ResumeRecording();
ITMGPTT int CancelRecording()
ITMGContext.GetInstance().GetPttCtrl().CancelRecording();
API | Description |
UploadRecordedFile | Uploads an audio file. |
DownloadRecordedFile | Downloads an audio file. |
PlayRecordedFile | Plays back an audio file. |
StopPlayFile | Stops playing back an audio file. |
GetFileSize | Gets the audio file size. |
GetVoiceFileDuration | Gets the audio file duration. |
ITMGPTT int UploadRecordedFile (string filePath)
Parameter | Type | Description |
filePath | String | Path of the uploaded audio file, which is a local path. |
ITMGContext.GetInstance().GetPttCtrl().UploadRecordedFile(filePath);
public delegate void QAVUploadFileCompleteCallback(int code, string filepath, string fileid);public abstract event QAVUploadFileCompleteCallback OnUploadFileComplete;
Parameter | Type | Description |
code | int | 0 : Recording is completed. |
filepath | string | Path of the stored recording file |
fileid | string | File URL |
Error Code | Cause | Suggestion |
8193 | An error occurred while accessing the file during upload. | Ensure the existence of the file and the validity of the file path. |
8194 | Signature verification failed. | Check whether the authentication key is correct and whether the voice messaging and speech-to-text feature is initialized. |
8195 | Network error. | Check whether the device can access the internet. |
8196 | The network failed while getting the upload parameters. | Check whether the authentication is correct and whether the device network can normally access the internet. |
8197 | The packet returned during the process of getting the upload parameters is empty. | Check whether the authentication is correct and whether the device network can normally access the internet. |
8198 | Failed to decode the packet returned during the process of getting the upload parameters. | Check whether the authentication is correct and whether the device network can normally access the internet. |
8200 | appinfo is not set. | Check whether the apply API is called or whether the input parameter is not specified or null. |
// Listen on an eventITMGContext.GetInstance().GetPttCtrl().OnUploadFileComplete +=new QAVUploadFileCompleteCallback (OnUploadFileComplete);// Process the event listened onvoid OnUploadFileComplete(int code, string filepath, string fileid){// Callback for audio file upload completion}
ITMGPTT DownloadRecordedFile (string fileID, string downloadFilePath)
Parameter | Type | Description |
fileID | String | File URL |
downloadFilePath | String | Local path of the saved file, which must be accessible and cannot be the fileid . |
ITMGContext.GetInstance().GetPttCtrl().DownloadRecordedFile(fileId, filePath);
public delegate void QAVDownloadFileCompleteCallback(int code, string filepath, string fileid);public abstract event QAVDownloadFileCompleteCallback OnDownloadFileComplete;
Parameter | Type | Description |
code | int | 0 : Recording is completed. |
filepath | string | Path of the stored recording file |
fileid | string | URL of the recording file, which will be retained on the server for 90 days. |
Error Code | Cause | Suggestion |
12289 | An error occurred while accessing the file during download. | Check whether the file path is valid. |
12290 | Signature verification failed. | Check whether the authentication key is correct and whether the voice messaging and speech-to-text feature is initialized. |
12291 | A network storage system exception occurred. | The server failed to get the audio file. Check whether the API parameter fileid is correct, whether the network is normal, and whether the file exists in COS. |
12292 | A server file system error occurred. | Check whether the device can access the internet and whether the file exists on the server. |
12293 | The HTTP network failed while getting the download parameters. | Check whether the device can access the internet. |
12294 | The packet returned during the process of getting the download parameters is empty. | Check whether the device can access the internet. |
12295 | Failed to decode the packet returned during the process of getting the download parameters. | Check whether the device can access the internet. |
12297 | appinfo is not set. | Check whether the authentication key is correct and whether the voice messaging and speech-to-text feature is initialized. |
// Listen on an eventITMGContext.GetInstance().GetPttCtrl().OnDownloadFileComplete +=new QAVDownloadFileCompleteCallback(OnDownloadFileComplete);// Process the event listened onvoid OnDownloadFileComplete(int code, string filepath, string fileid){// Callback for audio file download completion}
ITMGPTT PlayRecordedFile(string filePath)ITMGPTT PlayRecordedFile(string filePath,int voiceType);
Parameter | Type | Description |
filePath | string | Local audio file path |
voicetype | int |
Error Code | Cause | Suggestion |
20485 | Playback is not started. | Ensure the existence of the file and the validity of the file path. |
ITMGContext.GetInstance().GetPttCtrl().PlayRecordedFile(filePath);
public delegate void QAVPlayFileCompleteCallback(int code, string filepath);public abstract event QAVPlayFileCompleteCallback OnPlayFileComplete;
Parameter | Type | Description |
code | int | 0 : Playback is completed. |
filepath | string | Path of the stored recording file |
Error Code | Cause | Suggestion |
20481 | An initialization error occurred. | Check whether the device is being used, whether the permissions are normal, and whether the initialization is normal. |
20482 | During playback, the client tried to interrupt and play back the next one but failed (which should succeed normally). | Check whether the code logic is correct. |
20483 | Empty parameters. | Check whether the API parameters in the code are correct. |
20484 | Internal error | An error occurred while initializing the player. This error code is generally caused by failure in decoding, and the error should be located with the aid of logs. |
// Listen on an event:ITMGContext.GetInstance().GetPttCtrl().OnPlayFileComplete +=new QAVPlayFileCompleteCallback(OnPlayFileComplete);// Process the event listened on:void OnPlayFileComplete(int code, string filepath){// Callback for audio playback}
ITMGPTT int StopPlayFile()
ITMGContext.GetInstance().GetPttCtrl().StopPlayFile();
ITMGPTT GetFileSize(string filePath)
Parameter | Type | Description |
filePath | String | Path of the audio file, which is a local path. |
int fileSize = ITMGContext.GetInstance().GetPttCtrl().GetFileSize(filepath);
ITMGPTT int GetVoiceFileDuration(string filePath)
Parameter | Type | Description |
filePath | String | Path of the audio file, which is a local path. |
int fileDuration = ITMGContext.GetInstance().GetPttCtrl().GetVoiceFileDuration(filepath);
API | Description |
SpeechToText | Converts speech to text. |
ITMGPTT int SpeechToText(String fileID)
Parameter | Type | Description |
fileID | String | Audio file URL |
ITMGContext.GetInstance().GetPttCtrl().SpeechToText(fileID);
ITMGPTT int SpeechToText(String fileID,String speechLanguage)ITMGPTT int SpeechToText(String fileID,String speechLanguage,String translatelanguage)
Parameter | Type | Description |
fileID | String | URL of the audio file, which will be retained on the server for 90 days. |
speechLanguage | String | The language in which the audio file is to be converted to text. For parameters, see Language Parameter Reference List. |
translatelanguage | String | The language in which the audio file is to be translated into text. For parameters, see Language Parameter Reference List. |
ITMGContext.GetInstance().GetPttCtrl().SpeechToText(fileID,"cmn-Hans-CN","cmn-Hans-CN");
public delegate void QAVSpeechToTextCallback(int code, string fileid, string result);public abstract event QAVSpeechToTextCallback OnSpeechToTextComplete;
Parameter | Type | Description |
code | int | 0 : Recording is completed. |
fileid | string | URL of the audio file, which will be retained on the server for 90 days. |
result | string | Converted text |
Error Code | Cause | Suggestion |
32769 | Internal error | Analyze logs, get the actual error code returned from the backend to the client, and ask backend personnel for assistance. |
32770 | Network connection failed. | Check whether the device can access the internet. |
32772 | Failed to decode the returned packet. | Analyze logs, get the actual error code returned from the backend to the client, and ask backend personnel for assistance. |
32774 | appinfo is not set. | Check whether the authentication key is correct and whether the voice messaging and speech-to-text feature is initialized. |
32776 | authbuffer check failed. | Check whether authbuffer is correct. |
32784 | The speech-to-text conversion parameter is incorrect. | Check whether the API parameter fileid in the code is empty. |
32785 | A speech-to-text translation error occurred. | An error occurred in the voice messaging and speech-to-text feature on the backend. Analyze logs, get the actual error code returned from the backend to the client, and ask backend personnel for assistance. |
32787 | Speech-to-text conversion succeeded, but the text translation service was not activated. | Activate the text translation service in the console. |
32788 | Speech-to-text conversion succeeded, but the language parameter of the text translation service was invalid. | Check the parameter passed in. |
// Listen on an eventITMGContext.GetInstance().GetPttCtrl().OnSpeechToTextComplete += new QAVSpeechToTextCallback(OnSpeechToTextComplete);// Process the event listened onvoid OnSpeechToTextComplete(int code, string fileid, string result){// Callback for recognition}
API | Description |
GetMicLevel | Gets the real-time mic volume level. |
SetMicVolume | Sets the recording volume level. |
GetMicVolume | Gets the recording volume level. |
GetSpeakerLevel | Gets the real-time speaker volume level. |
SetSpeakerVolume | This API is used to set the playback volume. |
GetSpeakerVolume | Gets the playback volume level. |
ITMGPTT int GetMicLevel()
ITMGContext.GetInstance().GetPttCtrl().GetMicLevel();
ITMGPTT int SetMicVolume(int vol)
ITMGContext.GetInstance().GetPttCtrl().SetMicVolume(100);
ITMGPTT int GetMicVolume()
ITMGContext.GetInstance().GetPttCtrl().GetMicVolume();
ITMGPTT int GetSpeakerLevel()
ITMGContext.GetInstance().GetPttCtrl().GetSpeakerLevel();
ITMGPTT int SetSpeakerVolume(int vol)
ITMGContext.GetInstance().GetPttCtrl().SetSpeakerVolume(100);
ITMGPTT int GetSpeakerVolume()
ITMGContext.GetInstance().GetPttCtrl().GetSpeakerVolume();
ITMGContext abstract string GetSDKVersion()
ITMGContext.GetInstance().GetSDKVersion();
ITMGContext SetLogLevel(ITMG_LOG_LEVEL levelWrite, ITMG_LOG_LEVEL levelPrint)
Parameter | Type | Description |
levelWrite | ITMG_LOG_LEVEL | Sets the level of logs to be written. TMG_LOG_LEVEL_NONE indicates not to write. Default value: TMG_LOG_LEVEL_INFO . |
levelPrint | ITMG_LOG_LEVEL | Sets the level of logs to be printed. TMG_LOG_LEVEL_NONE indicates not to print. Default value: TMG_LOG_LEVEL_ERROR . |
ITMG_LOG_LEVEL
description:ITMG_LOG_LEVEL | Description |
TMG_LOG_LEVEL_NONE | Does not print logs |
TMG_LOG_LEVEL_ERROR | Prints error logs (default) |
TMG_LOG_LEVEL_INFO | Prints info logs |
TMG_LOG_LEVEL_DEBUG | Prints debug logs |
TMG_LOG_LEVEL_VERBOSE | Prints verbose logs |
ITMGContext.GetInstance().SetLogLevel(TMG_LOG_LEVEL_INFO,TMG_LOG_LEVEL_INFO);
Platform | Path |
Windows | %appdata%\\Tencent\\GME\\ProcessName |
iOS | Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents |
Android | /sdcard/Android/data/xxx.xxx.xxx/files |
macOS | /Users/username/Library/Containers/xxx.xxx.xxx/Data/Documents |
ITMGContext SetLogPath(string logDir)
Parameter | Type | Description |
logDir | String | Path |
ITMGContext.GetInstance().SetLogPath(path);
Was this page helpful?