diff --git a/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java b/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java index 68dac7476f..97e4475d5c 100644 --- a/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java +++ b/tts/tts-pad/src/main/java/com/mogo/tts/pad/PadTTS.java @@ -29,7 +29,6 @@ import com.mogo.eagle.core.utilcode.util.ThreadUtils; import com.mogo.eagle.core.utilcode.util.ToastUtils; import com.mogo.tts.base.IMogoTTS; import com.mogo.tts.base.IMogoTTSCallback; -import com.mogo.tts.base.MogoTTSConstants; import com.mogo.tts.base.PreemptType; import com.zhidao.auto.platform.voice.VoiceClient; import com.zhidao.voicesdk.MogoVoiceManager; @@ -118,6 +117,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList private String[] mBackResBinArray = new String[]{TTS_BACK_RES_ZHILING, TTS_BACK_RES_GUODGM}; // 单独的语音播放 private boolean mHasAuth; + private int retryCount; private void initFlushStatus() { if (!mHasFlush) { @@ -145,44 +145,51 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList // DUILiteSDK.openLog();//开启日志,需要在sdk init 之前调用 // } - DUILiteSDK.init(mContext, new DUILiteConfig.Builder() - .setApiKey("113cc31f6385113cc31f6385618c86f5") - .setProductId("278586132") - .setProductKey("1fe5930844b488a8d32d9ef7717be7dc") - .setProductSecret("f601ecc407986b548ac8ab2a9144162e") - .setAuthConfig(onlineBuilder.create())//授权配置 - // .setRecorderConfig(recorderConfig)//设置录音配置 - // .setUploadConfig(uploadConfig)//设置日志上传配置 - // .setTtsCacheDir("/sdcard/speech/cache") //设置tts cache文件存放目录 - .setEchoConfig(echoConfig) - .create(), new DUILiteSDK.InitListener() { - @Override - public void success() { - CallerLogger.INSTANCE.d(TAG, "授权成功"); - ThreadUtils.runOnUiThread(() -> { - mHasAuth = true; - initTtsEngine(); - }); - } - - @Override - public void error(String errorCode, final String errorInfo) { - CallerLogger.INSTANCE.e(TAG, "error code : " + errorCode + " , error info :" + errorInfo); - // throw new IllegalStateException("授权失败,请检查授权配置"); - } - }); - - boolean isAuthorized = DUILiteSDK.isAuthorized(mContext);//查询授权状态,DUILiteSDK.init之后随时可以调 - CallerLogger.INSTANCE.d(TAG, "DUILite SDK is isAuthorized ? " + isAuthorized); - - String core_version = DUILiteSDK.getCoreVersion();//获取内核版本号 - CallerLogger.INSTANCE.d(TAG, "core version is: " + core_version); + initDUILiteSDK(onlineBuilder, echoConfig); } catch (Exception e) { e.printStackTrace(); ToastUtils.showShort("PadTTS 模块初始化异常"); } } + private void initDUILiteSDK(AuthConfig.Builder onlineBuilder, EchoConfig echoConfig) { + DUILiteSDK.init(mContext, new DUILiteConfig.Builder() + .setApiKey("113cc31f6385113cc31f6385618c86f5") + .setProductId("278586132") + .setProductKey("1fe5930844b488a8d32d9ef7717be7dc") + .setProductSecret("f601ecc407986b548ac8ab2a9144162e") + .setAuthConfig(onlineBuilder.create())//授权配置 + // .setRecorderConfig(recorderConfig)//设置录音配置 + // .setUploadConfig(uploadConfig)//设置日志上传配置 + // .setTtsCacheDir("/sdcard/speech/cache") //设置tts cache文件存放目录 + .setEchoConfig(echoConfig) + .create(), new DUILiteSDK.InitListener() { + @Override + public void success() { + CallerLogger.INSTANCE.d(TAG, "授权成功"); + ThreadUtils.runOnUiThread(() -> { + mHasAuth = true; + initTtsEngine(); + }); + } + + @Override + public void error(String errorCode, final String errorInfo) { + CallerLogger.INSTANCE.e(TAG, "error code : " + errorCode + " , error info :" + errorInfo); + if (retryCount++ < 3) { + initDUILiteSDK(onlineBuilder, echoConfig); + } + // throw new IllegalStateException("授权失败,请检查授权配置"); + } + }); + +// boolean isAuthorized = DUILiteSDK.isAuthorized(mContext);//查询授权状态,DUILiteSDK.init之后随时可以调 +// CallerLogger.INSTANCE.d(TAG, "DUILite SDK is isAuthorized ? " + isAuthorized); +// +// String core_version = DUILiteSDK.getCoreVersion();//获取内核版本号 +// CallerLogger.INSTANCE.d(TAG, "core version is: " + core_version); + } + private void initTtsEngine() { CallerLogger.INSTANCE.d(TAG, "initTtsEngine"); if (mEngine != null) { @@ -427,7 +434,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList @MainThread public void speakTTSVoiceWithLevel(String text, int ttsLevel, IMogoTTSCallback callBack) { - if (mHasFlush && mEngine != null) { + if (mHasAuth && mEngine != null) { mSpeakVoiceMap.put(text, callBack); } speakTTSVoiceWithLevel(text, ttsLevel);