tencent cloud

Feedback

Speech-to-Text Service

Last updated: 2023-05-19 15:46:00
    This document describes how to integrate with and debug GME client APIs for the voice message and speech-to-text services for Unity.

    Key Considerations for Using GME

    GME provides the real-time voice chat service, voice messaging and speech-to-text services, which all depend on core APIs such as Init and Poll.

    Notes

    You have created a GME application and obtained the SDK AppID and key. For more information, see Activating Services.
    You have activated GME voice chat, voice messaging, and speech-to-text services. For more information, see Activating Services.
    Configure your project before using GME; otherwise, the SDK will not take effect.
    After a GME API is called successfully, QAVError.OK will be returned with the value being 0.
    GME APIs should be called in the same thread.
    The Poll API should be called periodically for GME to trigger event callbacks.
    For detailed error codes, see Error Codes.
    Notes
    There is a default call rate limit for speech-to-text APIs. For more information on how calls are billed within the limit, see Purchase Guide. If you want to increase the limit or learn more about how excessive calls are billed, submit a ticket.
    Non-streaming speech-to-text API **SpeechToText()**: There can be up to 10 concurrent requests per account.
    Streaming speech-to-text API **StartRecordingWithStreamingRecognition()**: There can be up to 50 concurrent requests per account.
    Voice chat streaming speech-to-text API **StartRealTimeASR()**: There can be up to 50 concurrent requests per account.

    Integrating the SDK

    Directions

    Key processes involved in SDK integration are as follows:
    
    2. Call Poll periodically to trigger callbacks

    C# classes

    Class
    Description
    ITMGContext
    Core APIs
    ITMGPTT
    Voice messaging and speech-to-text APIs

    Core APIs

    API
    Description
    Init
    Initializes GME.
    Poll
    Triggers an event callback.
    Pause
    Pauses the system.
    Resume
    Resumes the system.
    Uninit
    Uninitializes GME.

    Importing header files

    using GME;

    Getting an instance

    Get the Context instance by using the ITMGContext method instead of QAVContext.GetInstance().

    Initializing the SDK

    You need to initialize the SDK through the 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.

    API prototype

    //class ITMGContext
    public abstract int Init(string sdkAppID, string openID);
    Parameter
    Type
    Description
    sdkAppId
    string
    AppID provided in the GME console, which can be obtained as instructed in Activating Services.
    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 values

    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.
    Notes on 7015 error code
    The error code 7015 is identified based on the MD5 value. If this error is reported during integration, check the integrity and version of the SDK file as prompted.
    The returned value AV_ERR_SDK_NOT_FULL_UPDATE is only a reminder but will not cause an initialization failure.
    Due to the third-party enhancement, the Unity packaging mechanism, and other factors, the library file MD5 will be affected, resulting in misjudgment. Therefore, ignore this error in the logic for official releases, and avoid displaying it on the UI.

    Sample code

    int ret = ITMGContext.GetInstance().Init(sdkAppId, openID);
    // Determine whether the initialization is successful by the returned value
    if (ret != QAVError.OK)
    {
    Debug.Log("SDK initialization failed:"+ret);
    return;
    }

    Triggering event callback

    Event callbacks can be triggered by periodically calling the 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.
    Notes
    The Poll API must be called periodically and in the main thread to avoid abnormal API callbacks.

    API prototype

    ITMGContext public abstract int Poll();

    Sample code

    public void Update()
    {
    ITMGContext.GetInstance().Poll();
    }

    Pausing the system

    When a 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.

    API prototype

    ITMGContext public abstract int Pause()

    Resuming the system

    When a Resume event occurs in the system, the engine should also be notified for resumption. The Resume API only supports resuming voice chat.

    API prototype

    ITMGContext public abstract int Resume()

    Uninitializing SDK

    This API is used to uninitialize the SDK. If the game account is bound to openid, switching game account requires uninitializing GME and then using the new openid to initialize again.

    API prototype

    ITMGContext public abstract int Uninit()

    Voice Messaging and Speech-to-Text Services

    Note
    The speech-to-text service consists of fast recording-to-text conversion and streaming speech-to-text conversion.
    You do not need to enter a voice chat room when using the voice messaging service.
    The maximum recording duration of a voice message is 58 seconds by default, and the minimum recording duration cannot be less than 1 second. If you want to customize the recording duration, for example, to modify the maximum recording duration to 10 seconds, please call the SetMaxMessageLength API to set it after initialization.

    Flowchart for using the voice message service

    

    Flowchart for using the speech-to-text service

    
    API
    Description
    GenAuthBuffer
    Generates the local authentication key.
    ApplyPTTAuthbuffer
    Initializes authentication.
    SetMaxMessageLength
    Specifies the maximum duration of a voice message.

    Generating the local authentication key

    Generate AuthBuffer for encryption and authentication of relevant features. For release in the production environment, use the backend deployment key as detailed in Authentication Key.

    API prototype

    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
    Permission key from the Tencent Cloud console.

    Application authentication

    After the authentication information is generated, the authentication is assigned to the SDK.

    API prototype

    ITMGPTT int ApplyPTTAuthbuffer (byte[] authBuffer)
    Parameter
    Type
    Description
    authBuffer
    byte[]
    Authentication

    Sample code

    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);

    Specifying the maximum duration of voice message

    This API is used to specify the maximum duration of a voice message, which can be up to 58 seconds.

    API prototype

    ITMGPTT int SetMaxMessageLength(int msTime)
    Parameter
    Type
    Description
    msTime
    int
    Audio duration in ms. Value range: 1000 < msTime < = 58000.

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().SetMaxMessageLength(58000);

    Streaming Speech Recognition

    Voice messaging and speech-to-text APIs

    API
    Description
    StartRecordingWithStreamingRecognition
    Starts streaming recording.
    StopRecording
    This API is used to stop audio recording.
    

    Starting streaming speech recognition

    This API is used to start streaming speech recognition. Text obtained from speech-to-text conversion will be returned in real time in its callback. It can specify a language for recognition or translate the text recognized in speech into a specified language and return the translation. To stop recording, call StopRecording.

    API prototype

    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.

    Sample code

    string recordPath = Application.persistentDataPath + string.Format("/{0}.silk", sUid++);
    int ret = ITMGContext.GetInstance().GetPttCtrl().StartRecordingWithStreamingRecognition(recordPath, "cmn-Hans-CN","cmn-Hans-CN");
    Notes
    Translation incurs additional fees. For more information, see Purchase Guide.

    Callback for streaming speech recognition

    After streaming speech recognition is started, you need to listen on callback messages in the 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.
    The event message will be identified in the 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
    Notes
    The file_id is empty when the 'ITMG_MAIN_EVNET_TYPE_PTT_STREAMINGRecognition_IS_RUNNING' message is listened.

    Error codes

    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.
    If the error code 4098 is reported, see Speech-to-text Conversion for solutions.

    Sample code

    // 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");
    }
    }

    Voice Message Recording

    The recording process is as follows: start recording > stop recording > return recording callback > start the next recording.

    Voice messaging and speech-to-text APIs

    API
    Description
    StartRecording
    Starts recording.
    PauseRecording
    Pauses recording.
    ResumeRecording
    Resumes recording.
    StopRecording
    This API is used to stop audio recording.
    CancelRecording
    Cancels recording.

    Starting recording

    This API is used to start recording.

    API prototype

    ITMGPTT int StartRecording(string fileDir)
    Parameter
    Type
    Description
    fileDir
    string
    Path of the stored audio file

    Sample code

    string recordPath = Application.persistentDataPath + string.Format ("/{0}.silk", sUid++);
    int ret = ITMGContext.GetInstance().GetPttCtrl().StartRecording(recordPath);
    

    Stopping recording

    This API is used to stop recording. It is async, and a callback for recording completion will be returned after recording stops. A recording file will be available only after recording succeeds.

    API prototype

    ITMGPTT int StopRecording()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().StopRecording();

    Callback for recording start

    A callback will be executed through a delegate function to pass a message when recording is completed.
    **To stop recording, call StopRecording**. The callback for recording start will be returned after the recording is stopped.

    API prototype

    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 codes

    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.

    Sample code

    // Listen on an event
    ITMGContext.GetInstance().GetPttCtrl().OnRecordFileComplete += new QAVRecordFileCompleteCallback (OnRecordFileComplete);
    // Process the event listened on
    void OnRecordFileComplete(int code, string filepath){
    // Callback for recording start
    }

    Pausing recording

    This API is used to pause recording. If you want to resume recording, call the ResumeRecording API.

    API prototype

    ITMGPTT int PauseRecording()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().PauseRecording();

    Resuming recording

    This API is used to resume recording.

    API prototype

    ITMGPTT int ResumeRecording()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().ResumeRecording();

    Canceling recording

    This API is used to cancel recording. There is no callback after cancellation.

    API prototype

    ITMGPTT int CancelRecording()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().CancelRecording();

    Voice Message Upload, Download, and Playback

    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.

    Uploading an audio file

    This API is used to upload an audio file.

    API prototype

    ITMGPTT int UploadRecordedFile (string filePath)
    Parameter
    Type
    Description
    filePath
    String
    Path of the uploaded audio file, which is a local path.

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().UploadRecordedFile(filePath);

    Callback for audio file upload completion

    A callback will be executed through a delegate function to pass a message when the upload of audio file is completed.

    API prototype

    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 codes

    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.

    Sample code

    // Listen on an event
    ITMGContext.GetInstance().GetPttCtrl().OnUploadFileComplete +=new QAVUploadFileCompleteCallback (OnUploadFileComplete);
    // Process the event listened on
    void OnUploadFileComplete(int code, string filepath, string fileid){
    // Callback for audio file upload completion
    }

    Downloading the audio file

    This API is used to download an audio file.

    API prototype

    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.

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().DownloadRecordedFile(fileId, filePath);

    Callback for audio file download completion

    A callback will be executed through a delegate function to pass a message when the download of audio file is completed.

    API prototype

    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 codes

    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.

    Sample code

    // Listen on an event
    ITMGContext.GetInstance().GetPttCtrl().OnDownloadFileComplete +=new QAVDownloadFileCompleteCallback(OnDownloadFileComplete);
    // Process the event listened on
    void OnDownloadFileComplete(int code, string filepath, string fileid){
    // Callback for audio file download completion
    }

    Playing back audio

    This API is used to play back audio.

    API prototype

    ITMGPTT PlayRecordedFile(string filePath)
    ITMGPTT PlayRecordedFile(string filePath,int voiceType);
    Parameter
    Type
    Description
    filePath
    string
    Local audio file path
    voicetype
    int
    Voice changing type. For more information, see Voice Changing.

    Error codes

    Error Code
    Cause
    Suggestion
    20485
    Playback is not started.
    Ensure the existence of the file and the validity of the file path.

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().PlayRecordedFile(filePath);

    Callback for audio playback

    A callback will be executed through a delegate function to pass a message when an audio file is played back.

    API prototype

    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 codes

    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.

    Sample code

    // 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
    }

    Stopping audio playback

    This API is used to stop audio playback. There will be a callback for playback completion when the playback stops.

    API prototype

    ITMGPTT int StopPlayFile()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().StopPlayFile();

    Getting audio file size

    This API is used to get the size of an audio file.

    API prototype

    ITMGPTT GetFileSize(string filePath)
    Parameter
    Type
    Description
    filePath
    String
    Path of the audio file, which is a local path.

    Sample code

    int fileSize = ITMGContext.GetInstance().GetPttCtrl().GetFileSize(filepath);

    Getting audio file duration

    This API is used to get the duration of an audio file in milliseconds.

    API prototype

    ITMGPTT int GetVoiceFileDuration(string filePath)
    Parameter
    Type
    Description
    filePath
    String
    Path of the audio file, which is a local path.

    Sample code

    int fileDuration = ITMGContext.GetInstance().GetPttCtrl().GetVoiceFileDuration(filepath);

    Fast Recording-to-Text Conversion

    API
    Description
    SpeechToText
    Converts speech to text.

    Converting audio file to text

    This API is used to convert a specified audio file to text.

    API prototype

    ITMGPTT int SpeechToText(String fileID)
    Parameter
    Type
    Description
    fileID
    String
    Audio file URL

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().SpeechToText(fileID);

    Translating audio file into text in specified language

    This API can specify a language for recognition or translate the text recognized in speech into a specified language and return the translation.
    Notes
    Translation incurs additional fees. For more information, see Purchase Guide.

    API prototype

    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.

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().SpeechToText(fileID,"cmn-Hans-CN","cmn-Hans-CN");

    Callback for recognition

    A callback will be executed through a delegate function to pass a message when a specified audio file is recognized and converted to text.

    API prototype

    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 codes

    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.

    Sample code

    // Listen on an event
    ITMGContext.GetInstance().GetPttCtrl().OnSpeechToTextComplete += new QAVSpeechToTextCallback(OnSpeechToTextComplete);
    // Process the event listened on
    void OnSpeechToTextComplete(int code, string fileid, string result){
    // Callback for recognition
    }

    Voice Message Volume Level APIs

    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.

    Getting the real-time mic volume of voice message

    This API is used to get the real-time mic volume. An int-type value will be returned. Value range: 0-200.

    API prototype

    ITMGPTT int GetMicLevel()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().GetMicLevel();

    Setting the recording volume of voice message

    This API is used to set the recording volume of voice message. Value range: 0-200.

    API prototype

    ITMGPTT int SetMicVolume(int vol)

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().SetMicVolume(100);

    Getting the recording volume of voice message

    This API is used to get the recording volume of voice message. An int-type value will be returned. Value range: 0-200.

    API prototype

    ITMGPTT int GetMicVolume()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().GetMicVolume();

    Getting the real-time speaker volume of voice message

    This API is used to get the real-time speaker volume. An int-type value will be returned. Value range: 0-200.

    API prototype

    ITMGPTT int GetSpeakerLevel()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().GetSpeakerLevel();

    Setting the playback volume of voice message

    This API is used to set the playback volume of voice message. Value range: 0-200.

    API prototype

    ITMGPTT int SetSpeakerVolume(int vol)

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().SetSpeakerVolume(100);

    Getting the playback volume of voice message

    This API is used to get the playback volume of voice message. An int-type value will be returned. Value range: 0-200.

    API prototype

    ITMGPTT int GetSpeakerVolume()

    Sample code

    ITMGContext.GetInstance().GetPttCtrl().GetSpeakerVolume();

    Advanced APIs

    Getting version number

    This API is used to get the SDK version number for analysis.

    API prototype

    ITMGContext abstract string GetSDKVersion()

    Sample code

    ITMGContext.GetInstance().GetSDKVersion();

    Setting log printing level

    This API is used to set the level of logs to be printed, and needs to be called before the initialization. It is recommended to keep the default level.

    API prototype

    ITMGContext SetLogLevel(ITMG_LOG_LEVEL levelWrite, ITMG_LOG_LEVEL levelPrint)

    Parameter description

    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

    Sample code

    ITMGContext.GetInstance().SetLogLevel(TMG_LOG_LEVEL_INFO,TMG_LOG_LEVEL_INFO);

    Setting the log printing path

    This API is used to set the log printing path. The default path is as follows. It needs to be called before initialization.
    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

    API prototype

    ITMGContext SetLogPath(string logDir)
    Parameter
    Type
    Description
    logDir
    String
    Path

    Sample code

    ITMGContext.GetInstance().SetLogPath(path);
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support