Skip to content

Get Voice Configuration ​

Description ​

This API applies only to games that support multiple voice-over tracks. It obtains the corresponding voice configuration based on the current IP address. Games without this requirement do not need to integrate this API.


Function ​

java
GDSDK.gamedreamerGetVoiceConfig(Context context, GamedreamerVoiceListener listener)

Callbacks ​

onSuccess(VoiceResult result) ​

Called when the voice configuration is retrieved successfully.

PropertyTypeDescription
regionCodeStringThe region code corresponding to the current IP address.
voiceCodeVoiceCodeThe voice-over language identifier. Compare it with VoiceCode.CANTONESE or VoiceCode.MANDARIN for validation.
voiceNameStringThe voice-over language name.

onFail(VoiceSdkError error) ​

Called when retrieving the voice configuration fails. error contains the error information.


Usage Recommendations ​

  • Call this API after a successful login. If login has not yet been completed, the SDK shows a prompt and does not trigger the callback.
  • If the configuration fails to be retrieved, the caller is recommended to retry. If the retry also fails, use the default voice-over.
  • To support additional voice-over languages, contact technical support for confirmation first.
  • After the voice configuration is successfully obtained, the caller should cache the result. There is no need to call this API repeatedly.

Sample Code ​

java
import com.gd.sdk.dto.VoiceSdkError;
import com.gd.sdk.dto.VoiceResult;
import com.gd.sdk.dto.VoiceCode;
import com.gd.sdk.listener.GamedreamerVoiceListener;

GDSDK.gamedreamerGetVoiceConfig(this, new GamedreamerVoiceListener() {
    @Override
    public void onSuccess(VoiceResult result) {
        Log.i(TAG, "regionCode=" + result.getRegionCode()
                + ", voice=" + result.getVoiceCode().getValue()
                + ", voiceName=" + result.getVoiceName());
        if (result.getVoiceCode().equals(VoiceCode.CANTONESE)) {
            simpleToast("檢測到粵語");
        } else if (result.getVoiceCode().equals(VoiceCode.MANDARIN)) {
            simpleToast("檢測到普通話");
        } else {
            simpleToast("檢測到其他語言:" + result.getVoiceCode().getValue());
        }
    }

    @Override
    public void onFail(VoiceSdkError error) {
        Log.e(TAG, "voice detection failed: " + error.getType()
                + ", " + error.getMessage(), error.getCause());
    }
});