[3.2.0][Fix]解决首次安装Tts不播报的问题
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package com.zhjt.mogo_core_function_devatools.tts
|
||||
|
||||
import android.content.Context
|
||||
import com.elegant.utils.storage.SharedPrefsMgr
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.eagle.core.function.api.cloud.IMoGoCloudListener
|
||||
import com.mogo.eagle.core.function.call.cloud.CallerCloudListenerManager
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.zhjt.mogo_core_function_devatools.trace.TraceManager
|
||||
|
||||
@@ -21,16 +21,14 @@ class TtsManager : IMoGoCloudListener {
|
||||
}
|
||||
|
||||
fun initTts(context: Context) {
|
||||
val sn = SharedPrefsMgr.getInstance(context).getString("sn")
|
||||
if (sn.isNullOrEmpty()) {
|
||||
CallerCloudListenerManager.addListener(TraceManager.TAG, this)
|
||||
}
|
||||
CallerCloudListenerManager.addListener(TraceManager.TAG, this)
|
||||
AIAssist.getInstance(context)
|
||||
}
|
||||
|
||||
override fun tokenGot(token: String, sn: String) {
|
||||
ThreadUtils.runOnUiThread {
|
||||
CallerLogger.d(TAG, "网络获取到sn为:${sn},准备重新初始化Tts")
|
||||
ThreadUtils.runOnUiThread({
|
||||
AIAssist.getInstance(AbsMogoApplication.getApp()).initTtsAgain(sn)
|
||||
}
|
||||
}, ThreadUtils.MODE.QUEUE)
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,11 @@ public class AIAssist {
|
||||
* 重新初始化Tts(首次sn获取比较慢,而TTS初始化比较早会拿不到授权)
|
||||
*/
|
||||
public void initTtsAgain(String sn) {
|
||||
CallerLogger.INSTANCE.d(TAG, "网络获取SN后重新初始化Tts!");
|
||||
if (mTTS != null) {
|
||||
mTTS.initTts(sn);
|
||||
} else {
|
||||
CallerLogger.INSTANCE.d(TAG, "TTS对象创建失败!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
|
||||
// 单独的语音播放
|
||||
private boolean mHasAuth;
|
||||
private int retryCount;
|
||||
private volatile boolean isAuthing = false;
|
||||
|
||||
private void initFlushStatus() {
|
||||
if (!mHasFlush) {
|
||||
@@ -130,8 +131,10 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
|
||||
|
||||
@Override
|
||||
public void initTts(String sn) {
|
||||
if (!mHasAuth && sn != null && !sn.isEmpty()) {
|
||||
if (!mHasAuth && sn != null && !sn.isEmpty() && !isAuthing) {
|
||||
initTtsConfig(sn);
|
||||
} else {
|
||||
CallerLogger.INSTANCE.d(TAG, "不满足Tts初始化条件!" + mHasAuth + "," + sn + "," + isAuthing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +166,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
|
||||
}
|
||||
|
||||
private void initDUILiteSDK(AuthConfig.Builder onlineBuilder, EchoConfig echoConfig) {
|
||||
isAuthing = true;
|
||||
DUILiteSDK.init(mContext, new DUILiteConfig.Builder()
|
||||
.setApiKey("113cc31f6385113cc31f6385618c86f5")
|
||||
.setProductId("278586132")
|
||||
@@ -177,6 +181,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
|
||||
@Override
|
||||
public void success() {
|
||||
CallerLogger.INSTANCE.d(TAG, "授权成功");
|
||||
isAuthing = false;
|
||||
ThreadUtils.runOnUiThread(() -> {
|
||||
mHasAuth = true;
|
||||
initTtsEngine();
|
||||
@@ -186,6 +191,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
|
||||
@Override
|
||||
public void error(String errorCode, final String errorInfo) {
|
||||
CallerLogger.INSTANCE.e(TAG, "error code : " + errorCode + " , error info :" + errorInfo);
|
||||
isAuthing = false;
|
||||
if (retryCount++ < 3) {
|
||||
initDUILiteSDK(onlineBuilder, echoConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user