Init
API once.
The billing will not start after initialization. Receiving or sending a voice message in speech-to-text service is counted as a voice message DAU.QAVError.OK
will be returned with the value being 0.Poll
API should be called periodically for GME to trigger event callbacks.Init
API before you can use the voice chat and speech-to-text services.Init
API before calling any APIs of GME.API | Description |
InitEngine | Initializes GME |
Poll | Triggers event callback |
Pause | Pauses the system |
Resume | Resumes the system |
Uninit | Uninitializes GME |
SetDefaultAudienceAudioCategory | Sets audio playback in background on device |
#import "GMESDK/TMGEngine.h"#import "GMESDK/QAVAuthBuffer.h"
ITMGContext
object first.+ (ITMGContext*) GetInstance;
//TMGSampleViewController.mITMGContext* _context = [ITMGContext GetInstance];
Delegate
method to send callback notifications to the application. Register the callback function to the SDK for receiving callback messages.ITMGDelegate
is used for declaration.@interface TMGDemoViewController ()<ITMGDelegate>{}ITMGDelegate < NSObject >//TMGSampleViewController.mITMGContext* _context = [ITMGContext GetInstance];_context.TMGDelegate = [DispatchCenter getInstance];
OnEvent
. For the message type, see ITMG_MAIN_EVENT_TYPE
. The message content is a dictionary for parsing the API callback contents.- (void)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary*)data;
//TMGRealTimeViewController.mTMGRealTimeViewController ()< ITMGDelegate >- (void)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary *)data {NSString *log = [NSString stringWithFormat:@"OnEvent:%d,data:%@", (int)eventType, data];[self showLog:log];NSLog(@"====%@====", log);switch (eventType) {// Step 6/11 : Perform the enter room eventcase ITMG_MAIN_EVENT_TYPE_ENTER_ROOM: {int result = ((NSNumber *)[data objectForKey:@"result"]).intValue;NSString *error_info = [data objectForKey:@"error_info"];[self showLog:[NSString stringWithFormat:@"OnEnterRoomComplete:%d msg:(%@)", result, error_info]];if (result == 0) {[self updateStatusEnterRoom:YES];}}break;}}// Refer to DispatchCenter.h and DispatchCenter.m
sdkAppID
parameter, see Activating Services.-(int)InitEngine:(NSString*)sdkAppID openID:(NSString*)openID;
Parameter | Type | Description |
sdkAppId | String | |
OpenId | String | OpenId can only be in Int64 type, which is passed after being converted to a string. |
Returned Value | Description |
QAV_OK= 0 | Initialized SDK successfully. |
QAV_ERR_SDK_NOT_FULL_UPDATE= 7015 | Checks whether the SDK file is complete. It is recommended to 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._openId = _userIdText.text;_appId = _appIdText.text;[[ITMGContext GetInstance] InitEngine:SDKAPPID openID:_openId];
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.
For more information, see the EnginePollHelper.m file in Demo.Poll
API must be called periodically and in the main thread to avoid abnormal API callbacks.-(void)Poll;
[[ITMGContext GetInstance] Poll];
Pause
event occurs in the system, the engine should also be notified for pause.
If you need to pause the audio when switching to the background, you can call the Pause
API in the listening code used to switch to the background, and call the Resume
API in the listening event used to resume the foreground.-(QAVResult)Pause;
Resume
event occurs in the system, the engine should also be notified for resumption. The Resume
API only supports resuming voice chat.-(QAVResult)Resume;
-(int)Uninit;
[[ITMGContext GetInstance] Uninit];
API | Description |
ApplyPTTAuthbuffer | Initializes authentication |
SetMaxMessageLength | Specifies the maximum length of voice message |
StartRecording | Starts recording |
StartRecordingWithStreamingRecognition | Starts streaming recording |
PauseRecording | Pauses recording |
ResumeRecording | Resumes recording |
StopRecording | Stops recording |
CancelRecording | Cancels recording |
GetMicLevel | Gets the real-time mic volume |
SetMicVolume | Sets the recording volume |
GetMicVolume | Gets the recording volume |
GetSpeakerLevel | Gets the real-time speaker volume |
SetSpeakerVolume | Sets the playback volume |
GetSpeakerVolume | Gets the playback volume |
UploadRecordedFile | Uploads the audio file |
DownloadRecordedFile | Downloads the audio file |
PlayRecordedFile | Plays back audio |
StopPlayFile | Stops playing back audio |
GetFileSize | Gets the audio file size |
GetVoiceFileDuration | Gets the audio file duration |
SpeechToText | Converts speech to text |
SetMaxMessageLength
API to set it after initialization.Init
API before you can use the voice chat and voice message services.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. null
.@interface QAVAuthBuffer : NSObject+ (NSData*) GenAuthBuffer:(unsigned int)appId roomId:(NSString*)roomId openID:(NSString*)openID key:(NSString*)key;+ @end
Parameter | Type | Description |
appId | int | |
roomId | NSString | Enter null . |
openID | NSString | User ID, which is the same as openID during initialization. |
key | NSString |
#import "GMESDK/QAVAuthBuffer.h"NSData* authBuffer = [QAVAuthBuffer GenAuthBuffer:SDKAPPID3RD.intValue roomId:_roomId openID:_openId key:AUTHKEY];
authBuffer
, see genAuthBuffer
(the voice chat authentication information API).public abstract int ApplyPTTAuthbuffer(byte[] authBuffer);
Parameter | Type | Description |
authBuffer | NSData* | Authentication |
[[[ITMGContext GetInstance]GetPTT]ApplyPTTAuthbuffer:(NSData *)authBuffer];
StopRecording
. The callback will be returned after the recording is stopped.-(int)StartRecordingWithStreamingRecognition:(NSString *)filePath;-(int)StartRecordingWithStreamingRecognition:(NSString *)filePath language:(NSString*)speechLanguage translatelanguage:(NSString*)translateLanguage;
Parameter | Type | Description |
filePath | String | Path of 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 | The language into which the audio file will be translated. For parameters, see Language Parameter Reference List (This parameter is currently unavailable. Enter the same value as that of speechLanguage ) |
recordfilePath = [docDir stringByAppendingFormat:@"/test_%d.ptt",index++];[[[ITMGContext GetInstance] GetPTT] StartRecordingWithStreamingRecognition:recordfilePath language:@"cmn-Hans-CN"];
onEvent
. Event messages are divided into: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.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. fileid is fixed at http://gme-v2- |
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 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. |
- (void)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary*)data{NSNumber *number = [data objectForKey:@"result"];switch (eventType){case ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_COMPLETE:{if (data != NULL &&[[data objectForKey:@"result"] intValue]== 0){donwLoadUrlPath = data[@"file_id"];recordfilePath = [data objectForKey:@"file_path"];_localFileField.text = recordfilePath;_donwloadUrlField.text = [data objectForKey:@"file_id"] ;UITextField *_audiotoTextField =(UITextField*)objc_getAssociatedObject(self, [PTT_AUDIO_TO_TEXT UTF8String]);_audiotoTextField.text = [data objectForKey:@"text"] ;}}break;}}
-(QAVResult)SetMaxMessageLength:(int)msTime
Parameter | Type | Description |
msTime | int | Audio duration in ms. Value range: 1000 < msTime <= 58000 |
[[[ITMGContext GetInstance]GetPTT]SetMaxMessageLength:(int)msTime];
StopRecording
.-(int)StartRecording:(NSString*)filePath;
Parameter | Type | Description |
filePath | NSString | Path of stored audio file |
recordfilePath =[docDir stringByAppendingFormat:@"/test_%d.ptt",index++];[[[ITMGContext GetInstance]GetPTT]StartRecording:recordfilePath];
-(QAVResult)StopRecording;
[[[ITMGContext GetInstance]GetPTT]StopRecording];
StopRecording
. The callback for recording start will be returned after the recording is stopped.OnEvent
will be called after recording is started. The event message ITMG_MAIN_EVNET_TYPE_PTT_RECORD_COMPLETE
will be returned, which will be identified in the OnEvent
function.
The passed parameter includes result
and file_path
.Error Code Value | Cause | Suggested Solution |
4097 | Parameter is empty. | Check whether the API parameters in the code are correct. |
4098 | Initialization error. | Check whether the device is being used, whether the permissions are normal, and whether the initialization is normal. |
4099 | Recording is in progress. | Ensure that the SDK recording feature is used at the right time. |
4100 | Audio data is not 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. | 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)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary *)data{NSLog(@"OnEvent:%lu,data:%@",(unsigned long)eventType,data);switch (eventType) {case ITMG_MAIN_EVNET_TYPE_PTT_RECORD_COMPLETE:{//Recording callback}break;}}
ResumeRecording
API.-(int)PauseRecording;
[[[ITMGContext GetInstance]GetPTT]PauseRecording;
-(int)ResumeRecording;
[[[ITMGContext GetInstance]GetPTT]ResumeRecording;
-(QAVResult)CancelRecording;
[[[ITMGContext GetInstance]GetPTT]CancelRecording];
ITMGPTT
.-(QAVResult)GetMicLevel;
[[[ITMGContext GetInstance]GetPTT]GetMicLevel];
ITMGPTT
.-(QAVResult)SetMicVolume:(int) volume;
[[[ITMGContext GetInstance]GetPTT]SetMicVolume:100];
ITMGPTT
.-(int)GetMicVolume;
[[[ITMGContext GetInstance]GetPTT]GetMicVolume];
ITMGPTT
.-(QAVResult)GetSpeakerLevel;
[[[ITMGContext GetInstance]GetPTT]GetSpeakerLevel];
ITMGPTT
.-(QAVResult)SetSpeakerVolume:(int)volume;
[[[ITMGContext GetInstance]GetPTT]SetSpeakerVolume:100];
ITMGPTT
.-(int)GetSpeakerVolume;
[[[ITMGContext GetInstance]GetPTT]GetSpeakerVolume];
-(int)PlayRecordedFile:(NSString*)filePath;-(int)PlayRecordedFile:(NSString*)filePath VoiceType:(ITMG_VOICE_TYPE) type;
Parameter | Type | Description |
downloadFilePath | NSString | Local audio file path |
type | ITMG_VOICE_TYPE |
Error Code Value | Cause | Suggested Solution |
20485 | Playback is not started. | Ensure the existence of the file and the validity of the file path. |
[[[ITMGContext GetInstance]GetPTT]PlayRecordedFile:path];
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
.Error Code Value | Cause | Suggested Solution |
20481 | Initialization error. | 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 | Parameter is empty. | 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. |
-(void)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary *)data{NSLog(@"OnEvent:%lu,data:%@",(unsigned long)eventType,data);switch (eventType) {case ITMG_MAIN_EVNET_TYPE_PTT_PLAY_COMPLETE:{// Callback for audio playback}break;}}
-(int)StopPlayFile;
[[[ITMGContext GetInstance]GetPTT]StopPlayFile];
-(int)GetFileSize:(NSString*)filePath;
Parameter | Type | Description |
filePath | NSString | Path of audio file, which is a local path. |
[[[ITMGContext GetInstance]GetPTT]GetFileSize:path];
-(int)GetVoiceFileDuration:(NSString*)filePath;
Parameter | Type | Description |
filePath | NSString | Path of audio file, which is a local path. |
[[[ITMGContext GetInstance]GetPTT]GetVoiceFileDuration:path];
-(void)UploadRecordedFile:(NSString*)filePath;
Parameter | Type | Description |
filePath | NSString | Path of uploaded audio file, which is a local path. |
[[[ITMGContext GetInstance]GetPTT]UploadRecordedFile:path];
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
.Error Code Value | Cause | Suggested 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 message 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 can 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 can access the internet. |
8200 | No appinfo is set. | Check whether the apply API is called or whether the input parameters are empty. |
-(void)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary *)data{NSLog(@"OnEvent:%lu,data:%@",(unsigned long)eventType,data);switch (eventType) {case ITMG_MAIN_EVNET_TYPE_PTT_UPLOAD_COMPLETE:{if (data != NULL &&[[data objectForKey:@"result"] intValue]== 0){_donwloadUrlField.text = [data objectForKey:@"file_id"] ;donwLoadUrlPath = [data objectForKey:@"file_id"] ;}}break;}}
-(void)DownloadRecordedFile:(NSString*)fileId downloadFilePath:(NSString*)downloadFilePath
Parameter | Type | Description |
fileID | NSString | File URL path |
downloadFilePath | NSString | Local path of saved file |
[[[ITMGContext GetInstance]GetPTT]DownloadRecordedFile:fileIdpath downloadFilePath:path];
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
.Error Code Value | Cause | Suggested 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 message and speech-to-text feature is initialized. |
12291 | Network storage system exception | 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 | Server file system error. | Check whether the device can access the internet and whether the file exists on the server. |
12293 | The HTTP network failed during the process of 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 message and speech-to-text feature is initialized. |
-(void)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary *)data{NSLog(@"OnEvent:%lu,data:%@",(unsigned long)eventType,data);switch (eventType) {case ITMG_MAIN_EVNET_TYPE_PTT_DOWNLOAD_COMPLETE:{if (data != NULL &&[[data objectForKey:@"result"] intValue]== 0){_audiofileToPlayField.text = [data objectForKey:@"file_path"] ;donwLoadLocalPath = [data objectForKey:@"file_path"];}else{donwLoadLocalPath = NULL;}}break;}}
-(void)SpeechToText:(NSString*)fileID;
Parameter | Type | Description |
fileID | NSString | URL of audio file |
[[[ITMGContext GetInstance]GetPTT]SpeechToText:fileID];
-(void)SpeechToText:(NSString*)fileID (NSString*)speechLanguage (NSString*)translateLanguage;
Parameter | Type | Description |
fileID | NSString* | URL of audio file, which will be retained on the server for 90 days |
speechLanguage | NSString* | The language in which the audio file is to be converted to text. For parameters, see Language Parameter Reference List. |
translateLanguage | NSString* | The language into which the audio file will be translated. For parameters, see Language Parameter Reference List. This parameter is currently unavailable. Enter the same value as that of speechLanguage . |
[[[ITMGContext GetInstance]GetPTT]SpeechToText:fileID speechLanguage:"cmn-Hans-CN" translateLanguage:"cmn-Hans-CN"];
OnEvent
function.
The passed parameters include result
, file_path
and text
(recognized text).Error Code Value | Cause | Suggested 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 | Network 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 | No appinfo is set. | Check whether the authentication key is correct and whether the voice message and speech-to-text feature is initialized. |
32776 | authbuffer check failed. | Check whether authbuffer is correct. |
32784 | Incorrect speech-to-text conversion parameter. | Check whether the API parameter fileid in the code is empty. |
32785 | Speech-to-text translation returned an error. | Error with the backend of voice message and speech-to-text feature. Analyze logs, get the actual error code returned from the backend to the client, and ask backend personnel for assistance. |
-(void)OnEvent:(ITMG_MAIN_EVENT_TYPE)eventType data:(NSDictionary *)data{NSLog(@"OnEvent:%lu,data:%@",(unsigned long)eventType,data);switch (eventType) {case ITMG_MAIN_EVNET_TYPE_PTT_SPEECH2TEXT_COMPLETE:{if (data != NULL &&[[data objectForKey:@"result"] intValue]== 0){UITextField *_audiotoTextField =(UITextField*)objc_getAssociatedObject(self, [PTT_AUDIO_TO_TEXT UTF8String]);_audiotoTextField.text = [data objectForKey:@"text"] ;}}break;}}
-(NSString*)GetSDKVersion;
[[ITMGContext GetInstance] GetSDKVersion];
-(ITMG_RECORD_PERMISSION)CheckMicPermission;
Parameter | Value | Description |
ITMG_PERMISSION_GRANTED | 0 | Mic permission is granted. |
ITMG_PERMISSION_Denied | 1 | Mic is disabled. |
ITMG_PERMISSION_NotDetermined | 2 | No authorization box has been popped up to request the permission. |
ITMG_PERMISSION_ERROR | 3 | An error occurred while calling the API. |
[[ITMGContext GetInstance] CheckMicPermission];
-(void)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 |
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];
-(void)SetLogPath:(NSString*)logDir;
Parameter | Type | Description |
logDir | NSString | Path |
[[ITMGContext GetInstance] SetLogPath:Path];
Message | Description |
ITMG_MAIN_EVNET_TYPE_PTT_RECORD_COMPLETE | Indicates that PTT recording is completed. |
ITMG_MAIN_EVNET_TYPE_PTT_UPLOAD_COMPLETE | Indicates that PTT upload is completed. |
ITMG_MAIN_EVNET_TYPE_PTT_DOWNLOAD_COMPLETE | Indicates that PTT download is completed. |
ITMG_MAIN_EVNET_TYPE_PTT_PLAY_COMPLETE | Indicates that PTT playback is completed. |
ITMG_MAIN_EVNET_TYPE_PTT_SPEECH2TEXT_COMPLETE | Indicates that speech-to-text conversion is completed. |
Message | Data | Sample |
ITMG_MAIN_EVNET_TYPE_PTT_RECORD_COMPLETE | result; file_path | {"file_path":"","result":0} |
ITMG_MAIN_EVNET_TYPE_PTT_UPLOAD_COMPLETE | result; file_path;file_id | {"file_id":"","file_path":"","result":0} |
ITMG_MAIN_EVNET_TYPE_PTT_DOWNLOAD_COMPLETE | result; file_path;file_id | {"file_id":"","file_path":"","result":0} |
ITMG_MAIN_EVNET_TYPE_PTT_PLAY_COMPLETE | result; file_path | {"file_path":"","result":0} |
ITMG_MAIN_EVNET_TYPE_PTT_SPEECH2TEXT_COMPLETE | result; text;file_id | {"file_id":"","text":"","result":0} |
ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRECOGNITION_COMPLETE | result; file_path; text;file_id | {"file_id":"","file_path":","text":"","result":0} |
Was this page helpful?