Init
and Poll
.AppID
and key. For more information, see Activating Services.GmeError.AV_OK
will be returned with the value being 0
.Poll
API should be called periodically for GME to trigger event callbacks.gme.dart GME business implementation APIsgmeType.dart GME type definition filegmeError.dart GME error type definition file
API | Description |
InitSDK | Initializes GME. |
Poll | Triggers the event callback. |
Uninit | Uninitializes GME. |
import 'package:gme/gme.dart';import 'package:gme/gmeType.dart';
Init
API before you can use the real-time voice chat, voice messaging, 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.Future<int> InitSDK(String appID, 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. |
Returned Value | Description |
GmeError.AV_OK= 0 | SDK initialized successfully. |
AV_ERR_SDK_NOT_FULL_UPDATE=7015 | Solution: Check whether the SDK file is complete. We recommend that you delete it and then import the SDK again. |
AV_ERR_SDK_NOT_FULL_UPDATE
is only a reminder but will not cause an initialization failure.int res = await ITMGContext.GetInstance().InitSDK(_editAppID.text,_editOpenID.text);// Determine whether the initialization is successful by the returned valueif (ret != GmeError.AV_OK){print("Failed to initialize the SDK:");return;}
Poll
API in the timer. 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.Future<void> Poll()
Future<void> pollTimer() async {_pollTimer = Timer.periodic(Duration(milliseconds: 100), (Timer timer) {ITMGContext.GetInstance().Poll();});}
openid
, switching game account requires uninitializing GME and then using the new openid
to initialize again.Future<int> Uninit()
SetMaxMessageLength
API to set it after initialization.API | Description |
GenAuthBuffer | Gets the authentication information. |
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. Future<Uint8List> GenAuthBuffer(String appID, String roomID, String openID, String key)
Parameter | Type | Description |
appId | string | `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 |
Future<int> ApplyPTTAuthbuffer(Uint8List authBuffer)
Uint8List authBuffer = await ITMGContext.GetInstance().GenAuthBuffer(_editAppID.text, _editRoomID.text, _editOpenID.text, _editKey.text);m_context.ApplyPTTAuthbuffer(authBuffer);
Future<int> SetMaxMessageLength(int msTime)
Parameter | Type | Description |
msTime | number | Voice message duration in ms. Value range: 1000 < `msTime` <= 58000 |
ITMGContext.GetInstance().GetPTT().SetMaxMessageLength(fileLen);
API | Description |
StartRecordingWithStreamingRecognition | Starts streaming recording. |
StopRecording | Stops recording. |
Future<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 voice message file is to be converted to text. For parameters, see Language Parameter Reference List. |
translateLanguage | string | The language in which the voice message file is to be translated to text. For parameters, see Language Parameter Reference List. |
string filePath = "xx/xxx/xxx.silk"int res = await ITMGContext.GetInstance().GetPTT().StartRecordingWithStreamingRecognition(filePath, strCurLanguage, strCurLanguage);if (ret == 0) {this.currentStatus = "Start streaming recording";} else {this.currentStatus = "Failed to start streaming recording";}
OnEvent
notification, which is as detailed below:ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_COMPLETE
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.
ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_IS_RUNNING
returns the recognized text in real time during the recording, which is equivalent to returning the recognized text while speaking.Message | Description |
result | Return code indicating whether streaming speech recognition is successful |
text | Text converted from speech |
file_path | Local path of the stored recording file |
file_id | Backend URL address of the recording file, which will be retained for 90 days |
file_id
is empty when the 'ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_IS_RUNNING' message is listened for.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. |
void handleEventMsg(int eventType, String data){switch (eventType) {case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_COMPLETE:{HandleSTREAM2TEXTComplete(data,true);break;}...case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_IS_RUNNING:{HandleSTREAM2TEXTComplete(data, false);break;}}}ITMGContext.GetInstance().SetEvent(handleEventMsg);
API | Description |
StartRecording | Starts recording. |
PauseRecording | Pauses recording. |
ResumeRecording | Resumes recording. |
StopRecording | Stops recording. |
CancelRecording | Cancels recording. |
Future<int> StartRecording(String filePath)
Parameter | Type | Description |
filePath | string | Path of the stored voice message file |
string filepath = "xxxx/xxx.silk";int res = await ITMGContext.GetInstance().GetPTT().StartRecording(filepath);
Future<int> StopRecording()
ITMGContext.GetInstance().GetPTT().StopRecording();
StopRecording
. The callback for recording start will be returned after the recording is stopped.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 | Cause | Solution |
4097 | A parameter is empty. | 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. |
void handleEventMsg(int eventType, String data){switch (eventType) {case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM:{// Processbreak;}...case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVNET_TYPE_PTT_RECORD_COMPLETE:{// Processbreak;}}}ITMGContext.GetInstance().SetEvent(handleEventMsg);
ResumeRecording
API.Future<int> PauseRecording()
ITMGContext.GetInstance().GetPTT().PauseRecording();
Future<int> ResumeRecording()
ITMGContext.GetInstance().GetPTT().ResumeRecording();
Future<int> CancelRecording()
ITMGContext.GetInstance().GetPTT().CancelRecording();
API | Description |
UploadRecordedFile | Uploads an audio file. |
DownloadRecordedFile | Downloads an audio file. |
PlayRecordedFile | Plays back audio. |
StopPlayFile | Stops playing back audio. |
GetFileSize | Gets the audio file size. |
GetVoiceFileDuration | Gets the audio file duration. |
Future<int> UploadRecordedFile(String filePath)
Parameter | Type | Description |
filePath | String | Path of the uploaded audio file, which is a local path. |
ITMGContext.GetInstance().GetPTT().UploadRecordedFile(_filePath);
ITMG_MAIN_EVNET_TYPE_PTT_UPLOAD_COMPLETE
will be returned, which will be identified in the OnEvent
function.
The passed parameters include result
, file_path
, and file_id
.Parameter | Type | Description |
result | number | `0`: Recording is completed. |
filepath | string | Path of the stored recording file |
fileid | string | File URL |
Error Code | Cause | Solution |
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 | A network error occurred. | 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 | No `appinfo` is set. | Check whether the `apply` API is called or whether the input parameters are empty. |
void handleEventMsg(int eventType, String data){switch (eventType) {...case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVNET_TYPE_PTT_UPLOAD_COMPLETE:{// Processbreak;}}}ITMGContext.GetInstance().SetEvent(handleEventMsg);
Future<int> DownloadRecordedFile(String fileId, String filePath)
Parameter | Type | Description |
fileId | string | File URL |
filePath | string | Local path of the saved file, which must be accessible and cannot be the `fileid`. |
ITMGContext.GetInstance().GetPTT().DownloadRecordedFile(_fileId, _filePath);
ITMG_MAIN_EVNET_TYPE_PTT_DOWNLOAD_COMPLETE
will be returned, which will be identified in the OnEvent
function.
The passed parameters include result
, file_path
, and file_id
.Parameter | Type | Description |
result | number | `0`: Download 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 | Solution |
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 | No `appinfo` is set. | Check whether the authentication key is correct and whether the voice messaging and speech-to-text feature is initialized. |
void handleEventMsg(int eventType, String data){switch (eventType) {...case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM:{// Processbreak;}}}ITMGContext.GetInstance().SetEvent(handleEventMsg);
Future<int> PlayRecordedFile(String filePath, int voiceType)
Parameter | Type | Description |
filePath | string | Local audio file path |
voicetype | ITMG_VOICE_TYPE |
Error Code | Cause | Solution |
20485 | Playback is not started. | Ensure the existence of the file and the validity of the file path. |
int res = await ITMGContext.GetInstance().GetPTT().PlayRecordedFile(_filePath, _nVoiceType);
ITMG_MAIN_EVNET_TYPE_PTT_PLAY_COMPLETE
will be returned, which will be identified in the OnEvent
function.
The passed parameter includes result
and file_path
.Parameter | Type | Description |
code | number | `0`: Playback is completed. |
filepath | string | Path of the stored recording file |
Error Code | Cause | Solution |
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 | A parameter is empty. | Check whether the API parameters in the code are correct. |
20484 | An internal error occurred. | 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. |
void handleEventMsg(int eventType, String data){switch (eventType) {case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVNET_TYPE_PTT_PLAY_COMPLETE:{// Processbreak;}}}
Future<int> StopPlayFile()
ITMGContext.GetInstance().GetPTT().StopPlayFile();
Future<int> GetFileSize(String filePath)
Parameter | Type | Description |
filePath | string | Path of the audio file, which is a local path |
final int res = await ITMGContext.GetInstance().GetPTT().GetFileSize(_filePath);
Future<int> GetVoiceFileDuration(String filePath)
Parameter | Type | Description |
filePath | string | Path of the audio file, which is a local path |
final int res = await ITMGContext.GetInstance().GetPTT().GetVoiceFileDuration(_filePath);
Future<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 to text. For parameters, see Language Parameter Reference List. |
ITMGContext.GetInstance().GetPTT().SpeechToText(_fileId, "cmn-Hans-CN", "cmn-Hans-CN");
OnEvent
function.
The passed parameters include result
, file_path
and text
(recognized text).Parameter | Type | Description |
result | number | `0`: Recording is completed. |
fileid | string | URL of the audio file, which will be retained on the server for 90 days. |
text | string | Converted text |
Error Code | Cause | Solution |
32769 | An internal error occurred. | Analyze logs, get the actual error code returned from the backend to the client, and ask backend personnel for assistance. |
32770 | A network error occurred. | 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 | No `appinfo` is 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 | Speech-to-text translation returned an error. | 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. |
void handleEventMsg(int eventType, String data){switch (eventType) {case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM:{// Processbreak;}...case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVNET_TYPE_PTT_SPEECH2TEXT_COMPLETE:{// Processbreak;}}}
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 | Sets the playback volume level. |
GetSpeakerVolume | Gets the playback volume level. |
Future<int> GetMicLevel()
final int res = await ITMGContext.GetInstance().GetPTT().GetMicLevel();
Future<int> SetMicVolume(int volume)
Parameter | Type | Description |
vol | number | Value range: 0-200. Default value: `100`. `0` indicates that the audio is mute, while `100` indicates that the volume level remains unchanged. |
final int res = await ITMGContext.GetInstance().GetPTT().SetMicVolume(100);
Future<int> GetMicVolume()
final int res = await ITMGContext.GetInstance().GetPTT().GetMicVolume();
Future<int> GetSpeakerLevel()
final int res = await ITMGContext.GetInstance().GetPTT().GetSpeakerLevel();
Future<int> SetSpeakerVolume(int volume)
final int res = await ITMGContext.GetInstance().GetPTT().SetSpeakerVolume(100);
Future<int> GetSpeakerVolume()
final int res = await ITMGContext.GetInstance().GetPTT().GetSpeakerVolume();
Future<String> GetSDKVersion()
_sdkVersions = await ITMGContext.GetInstance().GetSDKVersion();
Future<int> SetLogLevel(int levelWrite, int levelPrint)
Parameter | Type | Description |
level | ITMG_LOG_LEVEL | Sets the log level. `TMG_LOG_LEVEL_NONE` indicates not to log. Default value: `TMG_LOG_LEVEL_INFO`. |
level
description: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(ITMG_LOG_LEVEL.TMG_LOG_LEVEL_ERROR,ITMG_LOG_LEVEL.TMG_LOG_LEVEL_ERROR);
Future<int> SetLogPath(String logDir)
Parameter | Type | Description |
logPath | string | Path |
String logDir = ""// Set a path by yourselfITMGContext.GetInstance().SetLogPath(curPath);
この記事はお役に立ちましたか?