[Fix]解决语音合成crash问题

原因:线程安全导致资源相关的String数组部分元素被置为null,而语音合成SDK遍历该String数组时没有判断元素是否为null,直接调用AssetManager.open()触发空指针异常而SDK只捕获了IO异常,导致Crash
This commit is contained in:
chenfufeng
2022-03-21 18:53:33 +08:00
parent 8b0c919ef6
commit 2e384907c1

View File

@@ -18,13 +18,13 @@ import com.aispeech.export.config.AuthConfig;
import com.aispeech.export.config.EchoConfig;
import com.aispeech.export.engines.AILocalTTSEngine;
import com.aispeech.export.intent.AILocalTTSIntent;
import com.aispeech.export.listeners.AILocalTTSListener;
import com.aispeech.export.listeners.AITTSListener;
import com.aispeech.lite.AuthType;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.cloud.commons.BuildConfig;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
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;
@@ -59,27 +59,29 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
private boolean mInitReady = true;
private Context mContext;
public synchronized void release() {
public void release() {
CallerLogger.INSTANCE.d(TAG, "release");
if (mCmdMap != null && !mCmdMap.isEmpty() && mVoiceClient != null) {
for (String cmd : mCmdMap.keySet()) {
try {
mVoiceClient.unRegisterCustomWakeupCmd(cmd);
} catch (Exception e) {
e.printStackTrace();
ThreadUtils.runOnUiThread(() -> {
if (mCmdMap != null && !mCmdMap.isEmpty() && mVoiceClient != null) {
for (String cmd : mCmdMap.keySet()) {
try {
mVoiceClient.unRegisterCustomWakeupCmd(cmd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
mQAndAMap.clear();
mVoiceClient.release();
if (mEngine != null) {
mEngine.destroy();
mEngine = null;
}
mHasAuth = false;
mSpeakVoiceMap.clear();
mCacheUnWakeupCommands.clear();
mContext = null;
mQAndAMap.clear();
mVoiceClient.release();
if (mEngine != null) {
mEngine.destroy();
mEngine = null;
}
mHasAuth = false;
mSpeakVoiceMap.clear();
mCacheUnWakeupCommands.clear();
mContext = null;
});
}
private VoiceClient mVoiceClient;
@@ -147,8 +149,10 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
@Override
public void success() {
CallerLogger.INSTANCE.d(TAG, "授权成功");
mHasAuth = true;
initTtsEngine();
ThreadUtils.runOnUiThread(() -> {
mHasAuth = true;
initTtsEngine();
});
}
@Override
@@ -251,7 +255,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
if (!mCmdMap.containsKey(cmd)) {
return;
}
CallerLogger.INSTANCE.d(TAG, "received command : " + cmd);
CallerLogger.INSTANCE.d(TAG, "received command : " + cmd);
Iterator<IMogoTTSCallback> iterator = null;
try {
@@ -447,7 +451,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
mVoiceClient.registerCustomWakeupCmd(cmd, cmdWords);
mCacheUnWakeupCommands.remove(cmd);
}
CallerLogger.INSTANCE.i(TAG, "cache un wakeup command2. " + cmd);
CallerLogger.INSTANCE.i(TAG, "cache un wakeup command2. " + cmd);
mCacheUnWakeupCommands.put(cmd, cmdWords);
}
@@ -463,7 +467,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
mVoiceClient.registerCustomWakeupCmd(cmd, cmdWords);
mCacheUnWakeupCommands.remove(cmd);
}
CallerLogger.INSTANCE.i(TAG, "cache un wakeup command. " + cmd);
CallerLogger.INSTANCE.i(TAG, "cache un wakeup command. " + cmd);
mCacheUnWakeupCommands.put(cmd, cmdWords);
}
@@ -514,7 +518,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
* @param status window_start_cancel 0 - 结束, 1 - 显示, 2 - 未激活调试进入
*/
public static void startAssistant(Context context, int status) {
CallerLogger.INSTANCE.w(TAG, "startAssistant status = " + status);
CallerLogger.INSTANCE.w(TAG, "startAssistant status = " + status);
final Intent intent = new Intent();
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);