正在查看: Petal Maps v4.7.0.310001 应用的 b.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Petal Maps v4.7.0.310001 应用的 b.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.huawei.hiassistant.voice.abilityconnector.tts;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Parcelable;
import android.text.TextUtils;
import com.huawei.hiai.pdk.interfaces.tts.ParamsConstants;
import com.huawei.hiai.tts.constants.BaseConstants;
import com.huawei.hiai.tts.sdk.MethodIdConstants;
import com.huawei.hiai.tts.sdk.TTSAPIMulService;
import com.huawei.hiai.tts.sdk.TtsCallback;
import com.huawei.hiai.tts.sdk.bean.VoiceResResult;
import com.huawei.hiassistant.platform.base.VoiceKitSdkContext;
import com.huawei.hiassistant.platform.base.bean.util.GsonUtils;
import com.huawei.hiassistant.platform.base.northinterface.Constants;
import com.huawei.hiassistant.platform.base.northinterface.recognize.RecognizerIntent;
import com.huawei.hiassistant.platform.base.report.OperationReportUtils;
import com.huawei.hiassistant.platform.base.report.fault.TtsFaultReporter;
import com.huawei.hiassistant.platform.base.util.AbilityConnectorThread;
import com.huawei.hiassistant.platform.base.util.DeviceUtil;
import com.huawei.hiassistant.platform.base.util.KitLog;
import com.huawei.hiassistant.platform.base.util.PluginUtil;
import com.huawei.hiassistant.platform.base.util.PropertyUtil;
import com.huawei.hiassistant.platform.base.util.SecureIntentUtil;
import com.huawei.hiassistant.platform.base.util.WhiteboxCipher;
import com.huawei.hiassistant.platform.base.util.voice.CheckFeatureUtil;
import com.huawei.hiassistant.voice.abilityconnector.tts.BaseTtsAbility;
import com.huawei.hiassistant.voice.abilityconnector.tts.TtsListenerInterface;
import com.huawei.hiassistant.voice.abilityconnector.tts.b;
import com.huawei.hiassistant.voice.common.util.CommonDataUtil;
import com.huawei.hms.ml.language.common.utils.Constant;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class b extends BaseTtsAbility {
public Context a;
public AudioManager b;
public BaseTtsAbility.a c;
public TtsListenerInterface d;
public Handler e;
public HandlerThread f;
public TTSAPIMulService g;
public d h;
public Intent i;
public c k;
public String o;
public boolean r;
public int j = CommonDataUtil.getToneColor();
public AtomicBoolean l = new AtomicBoolean(false);
public AtomicBoolean m = new AtomicBoolean(false);
public boolean n = false;
public boolean p = true;
public Intent q = null;
public class a extends Handler {
public a(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message message) {
int i = message.what;
KitLog.info("LocalTtsAbility", "handleMessage msg.what = " + i);
if (i != 17) {
return;
}
b.this.a0();
if (b.this.k != null) {
b.this.k.r();
}
}
}
public static class C0030b {
public String a;
public C0030b(String str) {
this.a = str;
}
public String a() {
return this.a;
}
}
public class d extends TtsCallback {
public d(b bVar, a aVar) {
this();
}
public final void b(int i, Bundle bundle) {
KitLog.debug("LocalTtsAbility", "eventType is {}", Integer.valueOf(i));
if (bundle != null) {
bundle.setClassLoader(getClass().getClassLoader());
int secureBundleInt = SecureIntentUtil.getSecureBundleInt(bundle, MethodIdConstants.BUNDLE_KEY_METHOD_ID, -1);
KitLog.debug("LocalTtsAbility", "onEvent, methodId = {}", Integer.valueOf(secureBundleInt));
b.this.x(secureBundleInt, i, bundle);
}
}
@Override
public void onError(String str, String str2) {
b bVar = b.this;
bVar.onError(bVar.d, str, str2, b.this.b, b.this.c);
}
@Override
public void onEvent(final int i, final Bundle bundle) {
AbilityConnectorThread.TtsCallback.THREAD.post(new Runnable() {
@Override
public final void run() {
b.d.this.b(i, bundle);
}
});
}
@Override
public void onFinish(String str) {
b bVar = b.this;
bVar.onTtsDataFinish(str, bVar.d);
}
@Override
public void onFormatChange(String str, Bundle bundle) {
b bVar = b.this;
bVar.onFormatChange(str, bundle, bVar.d);
}
@Override
public void onProgress(String str, byte[] bArr, int i) {
byte[] bArr2 = bArr != null ? (byte[]) bArr.clone() : null;
b bVar = b.this;
bVar.onTtsDataProgress(str, bArr2, i, bVar.d);
}
@Override
public void onSpeechFinish(String str) {
KitLog.debug("LocalTtsAbility", "enter onSpeechFinish", new Object[0]);
if (b.this.k != null) {
if (!b.this.k.q() && b.this.e != null) {
b.this.e.obtainMessage(17).sendToTarget();
return;
}
b.this.k.c();
}
b bVar = b.this;
bVar.onSpeechFinish(str, bVar.d, b.this.b, b.this.c);
}
@Override
public void onSpeechProgressChanged(String str, int i) {
b bVar = b.this;
bVar.onSpeechProgressChanged(str, i, bVar.d);
}
@Override
public void onSpeechStart(String str) {
if (b.this.k != null && !b.this.k.l()) {
b.this.k.i(true);
}
int i = b.this.j;
KitLog.debug("LocalTtsAbility", "toneColor : {} utteranceId : {}", Integer.valueOf(i), str);
b bVar = b.this;
bVar.onSpeechStart(str, i, bVar.d);
}
public d() {
}
}
public b(Context context, TtsListenerInterface ttsListenerInterface) {
a aVar = null;
this.r = false;
KitLog.debug("LocalTtsAbility", "Enter LocalTtsAbility", new Object[0]);
if (context == null) {
KitLog.warn("LocalTtsAbility", "need context not null! ");
return;
}
this.a = context;
this.d = ttsListenerInterface;
this.h = new d(this, aVar);
L();
this.r = J();
}
public static void I(StringBuilder sb, TtsListenerInterface ttsListenerInterface) {
ttsListenerInterface.onDownloadTtsToneEngine(0, sb.toString());
}
private Intent s(Intent intent, String str, int i) {
Intent intent2 = new Intent();
intent2.putExtra("session", GsonUtils.toJson(CommonDataUtil.getSessionInstanceWithInitialData()));
String secureIntentString = SecureIntentUtil.getSecureIntentString(intent, BaseConstants.INTENT_TEXTTYPE);
KitLog.info("LocalTtsAbility", "currentStreamType is " + i + "; and textType is " + secureIntentString);
intent2.putExtra("streamType", i);
if (!TextUtils.isEmpty(secureIntentString)) {
intent2.putExtra(BaseConstants.INTENT_TEXTTYPE, secureIntentString);
}
String language = getLanguage(intent);
if (this.p) {
TtsFaultReporter.getInstance().getFaultRecord().setSpeakLanguage(language);
}
if (TextUtils.isEmpty(language)) {
KitLog.warn("LocalTtsAbility", "language is empty");
} else {
KitLog.info("LocalTtsAbility", "language is " + language);
intent2.putExtra("language", language);
}
if (intent.hasExtra("audioDeviceType")) {
int secureIntentInt = SecureIntentUtil.getSecureIntentInt(intent, "audioDeviceType", -1);
KitLog.info("LocalTtsAbility", "audioDeviceType:" + secureIntentInt);
if (secureIntentInt != -1) {
intent2.putExtra("audioDeviceType", secureIntentInt);
}
}
intent2.putExtra("utteranceId", str);
Intent intent3 = this.q;
if (intent3 != null) {
intent2.putExtras(intent3);
}
int secureIntentInt2 = SecureIntentUtil.getSecureIntentInt(intent, Constants.Tts.TONE_COLOR, -1);
KitLog.info("LocalTtsAbility", "toneColor:" + secureIntentInt2);
if (secureIntentInt2 != -1) {
intent2.putExtra("speaker", secureIntentInt2);
} else {
intent2.putExtra("speaker", this.j);
}
SecureIntentUtil.transferStringExtra(intent, intent2, "style");
SecureIntentUtil.transferIntExtra(intent, intent2, "speed");
SecureIntentUtil.transferIntExtra(intent, intent2, "volume");
SecureIntentUtil.transferIntExtra(intent, intent2, "pitch");
SecureIntentUtil.transferBooleanExtra(intent, intent2, "supportNewSampleRate", false);
if (getSecondSpeaker() != -1) {
intent2.putExtra("secondSpeaker", getSecondSpeaker());
}
if (!intent2.hasExtra("supportNewSampleRate") && isSupportNewSampleRate()) {
intent2.putExtra("supportNewSampleRate", isSupportNewSampleRate());
}
A(intent2, intent);
SecureIntentUtil.transferIntExtra(intent, intent2, "streamState");
int secureIntentInt3 = SecureIntentUtil.getSecureIntentInt(intent, "usage", getUsage());
if (secureIntentInt3 != Integer.MAX_VALUE) {
intent2.putExtra("usage", secureIntentInt3);
}
return intent2;
}
public final void A(Intent intent, Intent intent2) {
if (this.r) {
SecureIntentUtil.transferIntExtra(intent2, intent, "compressRate");
if (!intent.hasExtra("compressRate") && getCompressRate() != -1) {
intent.putExtra("compressRate", getCompressRate());
} else {
if (intent.hasExtra("compressRate")) {
return;
}
intent.putExtra("compressRate", 24);
}
}
}
public final void B(Intent intent, Intent intent2, int i) {
int secureIntentInt = intent.hasExtra(Constants.Tts.TONE_COLOR) ? SecureIntentUtil.getSecureIntentInt(intent, Constants.Tts.TONE_COLOR, Constants.Tts.DEFAULT_TONE_COLOR) : ((Integer) VoiceKitSdkContext.getInstance().get(Constants.Tts.TONE_COLOR, Integer.class).orElse(Integer.valueOf(Constants.Tts.DEFAULT_TONE_COLOR))).intValue();
if (i != 2 || isTtsToneEngineExist(secureIntentInt)) {
intent2.putExtra("speaker", secureIntentInt);
this.j = secureIntentInt;
} else {
intent2.putExtra("speaker", CommonDataUtil.getToneColor());
this.j = CommonDataUtil.getToneColor();
}
boolean secureIntentBoolean = SecureIntentUtil.getSecureIntentBoolean(intent, Constants.Tts.IS_SUPPORT_MULTI_SPEAKER, false);
if (intent.hasExtra(Constants.Tts.IS_SUPPORT_MULTI_SPEAKER) && secureIntentBoolean) {
ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
Bundle bundle = new Bundle();
bundle.putInt("speaker", this.j);
arrayList.add(bundle);
KitLog.info("LocalTtsAbility", "TONE_COLOR_XIAOYI-STYLE_ANTHROPOMORPHIC isEngineExist = " + this.g.isEngineExist(Constants.Tts.RESOURCE_FILE_FEMALE_ANTHROPOMORPHIC));
Bundle bundle2 = new Bundle();
bundle2.putInt("speaker", 0);
bundle2.putString("style", "anthropomorphic");
arrayList.add(bundle2);
intent2.putParcelableArrayListExtra("multiSpeaker", arrayList);
}
}
public final void C(Bundle bundle) {
final String secureBundleString = SecureIntentUtil.getSecureBundleString(bundle, "res_id", "");
ArrayList parcelableArrayList = bundle.getParcelableArrayList(MethodIdConstants.BUNDLE_KEY_RES_RESULT);
if (parcelableArrayList == null || parcelableArrayList.size() <= 0) {
if (TextUtils.isEmpty(secureBundleString)) {
KitLog.debug("LocalTtsAbility", "tts plugin download fail", new Object[0]);
Optional.ofNullable(this.d).ifPresent(new Consumer() {
@Override
public final void accept(Object obj) {
((TtsListenerInterface) obj).onDownloadTtsToneEngine(2, "no resId");
}
});
return;
} else {
KitLog.debug("LocalTtsAbility", "tts plugin download success, resId : {}", secureBundleString);
Optional.ofNullable(this.d).ifPresent(new Consumer() {
@Override
public final void accept(Object obj) {
((TtsListenerInterface) obj).onDownloadTtsToneEngine(0, secureBundleString);
}
});
return;
}
}
final StringBuilder sb = new StringBuilder();
Iterator it = parcelableArrayList.iterator();
while (it.hasNext()) {
VoiceResResult voiceResResult = (VoiceResResult) it.next();
sb.append("resultCode = ");
sb.append(voiceResResult.getResultCode());
sb.append(",resId = ");
sb.append(voiceResResult.getResId());
sb.append(Constant.POINT);
}
KitLog.debug("LocalTtsAbility", "multi tts plugin download result : {}", sb.toString());
Optional.ofNullable(this.d).ifPresent(new Consumer() {
@Override
public final void accept(Object obj) {
b.I(sb, (TtsListenerInterface) obj);
}
});
}
public final boolean J() {
Bundle bundle = new Bundle();
bundle.putStringArray("featureNames", new String[]{ParamsConstants.SUPPORT_COMPRESS_RATE});
boolean z = CheckFeatureUtil.checkFeatures("TTS", bundle).getBoolean(ParamsConstants.SUPPORT_COMPRESS_RATE, false);
KitLog.debug("LocalTtsAbility", "feature supportCompressRate: {}", Boolean.valueOf(z));
return z;
}
public final void L() {
KitLog.debug("LocalTtsAbility", "initHandler", new Object[0]);
HandlerThread handlerThread = new HandlerThread("LocalTtsAbility");
this.f = handlerThread;
handlerThread.start();
Looper looper = this.f.getLooper();
if (looper == null) {
KitLog.warn("LocalTtsAbility", "handlerThread looper is null");
} else {
this.e = new a(looper);
}
}
public final void O(String str, String str2) {
TtsListenerInterface ttsListenerInterface = this.d;
if (ttsListenerInterface != null) {
ttsListenerInterface.onTtsError(2, str, str2);
}
}
public final boolean P(Intent intent) {
return BaseConstants.SSML_TEXT_TYPE.equals(SecureIntentUtil.getSecureIntentString(intent, BaseConstants.INTENT_TEXTTYPE));
}
public final void R() {
if (!this.g.initOnAppStart()) {
KitLog.info("LocalTtsAbility", "initOnAppStart failed");
return;
}
c0();
this.c = new BaseTtsAbility.a();
this.b = (AudioManager) this.a.getSystemService(AudioManager.class);
int doInit = this.g.doInit(T());
this.m.set(true);
this.l.set(doInit == 100);
KitLog.debug("LocalTtsAbility", "initEngine result :{},errorCode {}", Boolean.valueOf(this.l.get()), Integer.valueOf(doInit));
this.d.onInit(1 ^ (this.l.get() ? 1 : 0));
}
public final Intent T() {
Intent intent = new Intent();
if (!PropertyUtil.isGreaterThanEmuiEleven() || DeviceUtil.isOversea()) {
String decrypt4Aes = WhiteboxCipher.decrypt4Aes("0Q9NwvGPgSkj5ITd7qffuA==lYQwEWvdSYM8F_sd9Zl7Sfn7QgjPE15QZvpF-DhJ4Bj05FxDQUPi4UtsAOQX8ao-");
String decrypt4Aes2 = WhiteboxCipher.decrypt4Aes("R210k-nREruLdeeSSJE25A==fCyrmN5_Gn0y3SzxTjuUhaD0sFoQEssbPaSZp8NlKFnSekChng5NGJr6sANQROif");
if (TextUtils.isEmpty(decrypt4Aes)) {
decrypt4Aes = (String) VoiceKitSdkContext.getInstance().get(RecognizerIntent.EXT_AUTH_AK, String.class).orElse("");
}
intent.putExtra(BaseConstants.INTENT_AK, decrypt4Aes);
if (TextUtils.isEmpty(decrypt4Aes2)) {
decrypt4Aes2 = (String) VoiceKitSdkContext.getInstance().get(RecognizerIntent.EXT_AUTH_SK, String.class).orElse("");
}
intent.putExtra("sk", decrypt4Aes2);
} else {
String decrypt4Aes3 = WhiteboxCipher.decrypt4Aes("MVoRwwG8BDEzFdlatPp7Ow==gDxLTq3x1LpDF9t3BrVZCOoZgupVapVGQEjOKadTpfQ35-v5RB3o0CVopguQ7n-z");
String decrypt4Aes4 = WhiteboxCipher.decrypt4Aes("I7kTC399wkVtOGYT1T7_mA==BugPf_w-3QEbfInn1KC52a3ouICn4w7LeLbEyOt9UyXaUH0Fa7iSw0EkBJ9ctGlF");
String str = (String) VoiceKitSdkContext.getInstance().get(RecognizerIntent.EXT_AUTH_AK, String.class).orElse("");
String str2 = (String) VoiceKitSdkContext.getInstance().get(RecognizerIntent.EXT_AUTH_SK, String.class).orElse("");
if (!TextUtils.isEmpty(str)) {
decrypt4Aes3 = str;
}
intent.putExtra(BaseConstants.INTENT_AK, decrypt4Aes3);
if (!TextUtils.isEmpty(str2)) {
decrypt4Aes4 = str2;
}
intent.putExtra("sk", decrypt4Aes4);
}
int r = r(this.i);
intent.putExtra("ttsMode", r);
String language = getLanguage(this.i);
y(r, language);
if (TextUtils.isEmpty(language)) {
KitLog.debug("LocalTtsAbility", "language is empty", new Object[0]);
} else {
KitLog.info("LocalTtsAbility", "language is " + language);
intent.putExtra("language", language);
}
intent.putExtra("deviceId", DeviceUtil.getCompatUdid());
B(this.i, intent, r);
intent.putExtra("osVersion", Build.VERSION.RELEASE);
intent.putExtra("romVersion", Build.DISPLAY);
intent.putExtra("deviceName", DeviceUtil.getDeviceModel());
String deviceCategory = getDeviceCategory();
if (TextUtils.isEmpty(deviceCategory)) {
intent.putExtra("deviceType", getDeviceType());
} else {
intent.putExtra("deviceCategory", deviceCategory);
}
if (r != 2) {
String asUrl = getAsUrl(this.a);
if (TextUtils.isEmpty(asUrl)) {
KitLog.warn("LocalTtsAbility", "asUrl is empty");
} else {
intent.putExtra("asUrl", asUrl);
}
}
intent.putExtra("appName", this.a.getPackageName());
Intent intent2 = this.q;
if (intent2 != null) {
intent.putExtras(intent2);
}
return intent;
}
public final void W() {
c cVar = this.k;
if (cVar != null) {
cVar.c();
}
}
public final boolean Y() {
if (!isSupportMultiInstance()) {
KitLog.info("LocalTtsAbility", "app no support multi");
return false;
}
if (PluginUtil.getHiAiPluginVersionCode(this.a, "tts") < 1000032234) {
KitLog.info("LocalTtsAbility", "tts no support multi");
return false;
}
KitLog.debug("LocalTtsAbility", "support multi", new Object[0]);
return true;
}
public final void a0() {
TTSAPIMulService tTSAPIMulService = this.g;
if (tTSAPIMulService == null) {
KitLog.warn("LocalTtsAbility", "[stop]ttsService not exist!");
} else if (this.n) {
tTSAPIMulService.doSpeakStop(this.q);
} else {
tTSAPIMulService.doSpeakStop();
}
}
public final void c0() {
TTSAPIMulService tTSAPIMulService = this.g;
if (tTSAPIMulService == null) {
KitLog.warn("LocalTtsAbility", "[release]ttsService not exist!");
} else if (this.n) {
tTSAPIMulService.doRelease(this.q);
} else {
tTSAPIMulService.doRelease();
}
}
@Override
public void cancel() {
KitLog.info("LocalTtsAbility", "enter cancel");
c cVar = this.k;
if (cVar != null) {
cVar.t();
} else {
a0();
abandonAudioFocus(this.b, this.c);
}
W();
}
@Override
public void destroy() {
KitLog.debug("LocalTtsAbility", "enter destroy", new Object[0]);
this.l.set(false);
c cVar = this.k;
if (cVar != null) {
cVar.u();
}
TTSAPIMulService tTSAPIMulService = this.g;
if (tTSAPIMulService != null) {
if (tTSAPIMulService.isBind()) {
c0();
this.g.destroy();
} else {
KitLog.error("LocalTtsAbility", "tts service has destroyed");
}
}
abandonAudioFocus(this.b, this.c);
this.c = null;
HandlerThread handlerThread = this.f;
if (handlerThread != null) {
handlerThread.quit();
}
}
@Override
public void downloadTtsToneEngine(int[] iArr) {
KitLog.info("LocalTtsAbility", "downloadTtsToneEngine");
if (iArr == null) {
KitLog.warn("LocalTtsAbility", "toneTypes null");
return;
}
if (this.g == null) {
KitLog.warn("LocalTtsAbility", "ttsService is null");
return;
}
if (iArr.length == 1) {
KitLog.debug("LocalTtsAbility", "only download one Tts Tone Engine : {}", Integer.valueOf(iArr[0]));
this.g.downloadTargetEngine(v(iArr[0]));
} else {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < iArr.length; i++) {
KitLog.debug("LocalTtsAbility", "downloadTtsToneEngine : {}", Integer.valueOf(iArr[i]));
arrayList.add(v(iArr[i]));
}
this.g.downloadTargetEngines(arrayList);
}
}
public final boolean e0() {
TTSAPIMulService tTSAPIMulService = this.g;
if (tTSAPIMulService != null) {
return this.n ? tTSAPIMulService.isSpeaking(this.q) : tTSAPIMulService.isSpeaking();
}
KitLog.warn("LocalTtsAbility", "[isSpeaking]ttsService not exist!");
return false;
}
@Override
public void initEngine(Intent intent) {
super.initEngine(intent);
KitLog.debug("LocalTtsAbility", "enter initEngine", new Object[0]);
this.i = intent;
if (this.d == null) {
KitLog.error("LocalTtsAbility", "BaseTtsListener can't be null");
return;
}
this.n = Y();
this.o = SecureIntentUtil.getSecureIntentString(this.i, "packageName");
String secureIntentString = SecureIntentUtil.getSecureIntentString(this.i, ParamsConstants.INTENT_TASK_NAME);
if (!TextUtils.isEmpty(secureIntentString) && !TextUtils.isEmpty(this.o) && this.n) {
Intent intent2 = new Intent();
this.q = intent2;
intent2.putExtra(ParamsConstants.INTENT_TASK_NAME, secureIntentString);
this.q.putExtra("packageName", this.o);
}
this.m.set(false);
TTSAPIMulService tTSAPIMulService = new TTSAPIMulService(this.a, this.h, -1);
this.g = tTSAPIMulService;
if (tTSAPIMulService.isBind()) {
R();
} else {
this.g.bindTtsService();
}
}
@Override
public boolean isInitFinish() {
return this.m.get();
}
@Override
public boolean isInitSuccess() {
return this.l.get();
}
@Override
public boolean isSpeaking() {
KitLog.debug("LocalTtsAbility", "enter isSpeaking", new Object[0]);
if (this.l.get()) {
c cVar = this.k;
return cVar != null ? cVar.s() : e0();
}
KitLog.warn("LocalTtsAbility", "not init");
return false;
}
@Override
public boolean isTtsBind() {
TTSAPIMulService tTSAPIMulService = this.g;
if (tTSAPIMulService != null) {
return tTSAPIMulService.isBind();
}
KitLog.warn("LocalTtsAbility", "ttsService is null");
return false;
}
@Override
public boolean isTtsToneEngineExist(int i) {
KitLog.debug("LocalTtsAbility", "enter isTtsToneEngineExist", new Object[0]);
if (i == Constants.Tts.DEFAULT_TONE_COLOR) {
KitLog.info("LocalTtsAbility", "toneColor is preset no need check exist");
return true;
}
boolean isEngineExist = this.g != null ? this.g.isEngineExist(v(i)) : false;
KitLog.debug("LocalTtsAbility", "{} isTtsToneEngineExist : {}", Integer.valueOf(i), Boolean.valueOf(isEngineExist));
return isEngineExist;
}
@Override
public void prepare() {
KitLog.debug("LocalTtsAbility", "enter prepare", new Object[0]);
TTSAPIMulService tTSAPIMulService = this.g;
if (tTSAPIMulService != null) {
tTSAPIMulService.prepare(this.q);
}
}
public final int r(Intent intent) {
int i = !DeviceUtil.isOversea() ? 1 : 0;
if (intent != null && intent.getExtras() != null) {
i = intent.getExtras().getInt("ttsMode", i);
}
KitLog.info("LocalTtsAbility", "localTtsMode is " + i);
return i;
}
@Override
public void J() {
if (this.g != null) {
KitLog.info("LocalTtsAbility", "ttsService, TTS_PLUGIN_ON_BIND_DISCONNECTED unBind");
this.m.set(false);
this.l.set(false);
this.g.bindTtsService();
}
}
public final c t(String str, Intent intent, String str2) {
KitLog.debug("LocalTtsAbility", "parseSpeakTask", new Object[0]);
if (P(intent)) {
return u(str, str2);
}
c cVar = new c(this, null);
cVar.g(str);
return cVar;
}
@Override
public void textToSpeak(String str, final String str2, Intent intent) {
KitLog.debug("LocalTtsAbility", "enter textToSpeak text :{} utteranceId {}", str, str2);
if (this.p) {
OperationReportUtils.getInstance().getTtsRecord().setOda("1");
}
if (this.g == null || !this.l.get()) {
KitLog.warn("LocalTtsAbility", "ttsService is null");
Optional.ofNullable(this.d).ifPresent(new Consumer() {
@Override
public final void accept(Object obj) {
((TtsListenerInterface) obj).onTtsError(2, "tts is not available", str2);
}
});
return;
}
if (intent.hasExtra(Constants.Tts.IS_SAVE_TTS_DATA)) {
this.g.setIsSaveTtsData(SecureIntentUtil.getSecureIntentBoolean(intent, Constants.Tts.IS_SAVE_TTS_DATA, false));
}
int secureIntentInt = this.p ? SecureIntentUtil.getSecureIntentInt(intent, "streamType", getStreamType()) : SecureIntentUtil.getSecureIntentInt(intent, "streamType", 3);
Intent s = s(intent, str2, secureIntentInt);
if (this.p) {
OperationReportUtils.getInstance().getTtsRecord().setToneColor(this.j).setTts("local");
}
if (PropertyUtil.isGreaterThanEmuiEleven()) {
requestAudioFocus(this.b, this.c, secureIntentInt);
int doSpeak = this.g.doSpeak(str, s);
KitLog.debug("LocalTtsAbility", "doSpeak result :{}", Boolean.valueOf(doSpeak == 100));
z(doSpeak, "speak fail", str2);
return;
}
c cVar = this.k;
if (cVar == null || cVar.q()) {
this.k = t(str, intent, str2);
}
c cVar2 = this.k;
if (cVar2 != null) {
cVar2.h(str2);
this.k.d(SecureIntentUtil.getSecureIntentInt(intent, "streamType", secureIntentInt));
this.k.e(s);
this.k.r();
}
}
public final c u(String str, String str2) {
ByteArrayInputStream byteArrayInputStream;
c cVar;
c cVar2 = null;
try {
byteArrayInputStream = new ByteArrayInputStream(str.getBytes("UTF-8"));
try {
XmlPullParser newPullParser = XmlPullParserFactory.newInstance().newPullParser();
newPullParser.setInput(byteArrayInputStream, "UTF-8");
cVar = null;
for (int eventType = newPullParser.getEventType(); eventType != 1; eventType = newPullParser.next()) {
try {
String name = newPullParser.getName();
if (eventType == 2) {
cVar = w(name, newPullParser, cVar).orElse(null);
} else if (eventType == 4) {
String text = newPullParser.getText();
if (cVar != null && !TextUtils.isEmpty(text)) {
cVar.g(text);
}
}
} catch (Throwable th) {
th = th;
cVar2 = cVar;
try {
byteArrayInputStream.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
throw th;
}
}
} catch (Throwable th3) {
th = th3;
}
} catch (UnsupportedEncodingException unused) {
} catch (IOException unused2) {
} catch (XmlPullParserException unused3) {
}
try {
byteArrayInputStream.close();
return cVar;
} catch (UnsupportedEncodingException unused4) {
cVar2 = cVar;
KitLog.error("LocalTtsAbility", "[parseSsmlSpeakTask] UnsupportedEncodingException!");
O("UnsupportedEncodingException", str2);
return cVar2;
} catch (IOException unused5) {
cVar2 = cVar;
KitLog.error("LocalTtsAbility", "[parseSsmlSpeakTask] IOException!");
O("IOException", str2);
return cVar2;
} catch (XmlPullParserException unused6) {
cVar2 = cVar;
KitLog.error("LocalTtsAbility", "[parseSsmlSpeakTask] XmlPullParserException!");
O("XmlPullParserException", str2);
return cVar2;
}
}
public final String v(int i) {
if (!Constants.Tts.ANTHROPOMORPHIC_LIST.contains(Integer.valueOf(i))) {
return "tts_china_" + i + "_resid_group";
}
return "tts_china_" + ((i / 10) % 10) + "_anthropomorphic_resid_group";
}
public final Optional<c> w(String str, XmlPullParser xmlPullParser, c cVar) {
a aVar = null;
if ("speak".equals(str)) {
return Optional.of(new c(this, aVar));
}
if ("audio".equals(str)) {
String attributeValue = xmlPullParser.getAttributeValue(null, "src");
KitLog.debug("LocalTtsAbility", "[parseSsmlSpeakTask] src: {}", attributeValue);
if (cVar == null || attributeValue == null) {
KitLog.warn("LocalTtsAbility", "[parseSsmlSpeakTask] speakTask or src is null!");
return Optional.empty();
}
String trim = attributeValue.trim();
if (!TextUtils.isEmpty(trim)) {
cVar.g(new C0030b(trim));
}
} else {
KitLog.warn("LocalTtsAbility", "[parseSsmlSpeakTask] tagName is error!");
}
return Optional.ofNullable(cVar);
}
public final void x(int i, int i2, Bundle bundle) {
if (i != 1000) {
if (i != 1008) {
return;
}
if (i2 == 1 || i2 == -2) {
KitLog.info("LocalTtsAbility", "download success");
C(bundle);
return;
} else if (i2 == 100) {
KitLog.info("LocalTtsAbility", "start download");
Optional.ofNullable(this.d).ifPresent(new Consumer() {
@Override
public final void accept(Object obj) {
((TtsListenerInterface) obj).onDownloadTtsToneEngine(1, "start download");
}
});
return;
} else {
KitLog.error("LocalTtsAbility", "download error");
Optional.ofNullable(this.d).ifPresent(new Consumer() {
@Override
public final void accept(Object obj) {
((TtsListenerInterface) obj).onDownloadTtsToneEngine(2, "fail");
}
});
return;
}
}
if (i2 == 10) {
KitLog.info("LocalTtsAbility", "doEventWithMethodId, bindTtsService success.");
R();
return;
}
if (i2 == 13) {
KitLog.info("LocalTtsAbility", "tts plugin download start");
return;
}
if (i2 == 12) {
KitLog.info("LocalTtsAbility", "doEventWithMethodId, TTS_PLUGIN_ON_BIND_DISCONNECTED.");
return;
}
KitLog.info("LocalTtsAbility", "doEventWithMethodId, bindTtsService failed, error code = " + i2);
TtsListenerInterface ttsListenerInterface = this.d;
if (ttsListenerInterface != null) {
ttsListenerInterface.onInit(1);
}
}
public final void y(int i, String str) {
if (this.p) {
TtsFaultReporter.getInstance().getFaultRecord().setEngineType(i);
TtsFaultReporter.getInstance().getFaultRecord().setInitLanguage(str);
}
}
public final void z(int i, String str, String str2) {
TtsListenerInterface ttsListenerInterface;
if (this.p || (ttsListenerInterface = this.d) == null || i == 100) {
return;
}
ttsListenerInterface.onTtsError(2, str, str2);
}
public class c {
public final Queue<Object> a;
public MediaPlayer b;
public boolean c;
public boolean d;
public boolean e;
public int f;
public String g;
public Intent h;
public class a implements MediaPlayer.OnPreparedListener {
public a() {
}
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
KitLog.debug("LocalTtsAbility", "onPrepared", new Object[0]);
c.this.b.start();
c.this.c = true;
if (c.this.d) {
return;
}
c.this.d = true;
if (b.this.d != null) {
b.this.d.onTtsStart(c.this.g, b.this.j);
}
}
}
public class C0031b implements MediaPlayer.OnCompletionListener {
public C0031b() {
}
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
KitLog.debug("LocalTtsAbility", "onCompletion", new Object[0]);
c.this.c = false;
c.this.b.release();
c.this.b = null;
c.this.r();
}
}
public class C0032c implements MediaPlayer.OnErrorListener {
public C0032c() {
}
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
KitLog.debug("LocalTtsAbility", "onError what: {}, extra: {}", Integer.valueOf(i), Integer.valueOf(i2));
b.this.W();
b bVar = b.this;
bVar.abandonAudioFocus(bVar.b, b.this.c);
if (b.this.d == null) {
return true;
}
b.this.d.onTtsError(2, "MediaPlayer play error", c.this.g);
return true;
}
}
public c() {
this.a = new LinkedList();
}
public void c() {
this.a.clear();
this.c = false;
this.d = false;
}
public void d(int i) {
this.f = i;
}
public void e(Intent intent) {
this.h = intent;
}
public final void f(C0030b c0030b) {
MediaPlayer mediaPlayer = new MediaPlayer();
this.b = mediaPlayer;
mediaPlayer.setAudioStreamType(this.f);
try {
this.b.setDataSource(c0030b.a());
this.b.prepareAsync();
this.b.setOnPreparedListener(new a());
this.b.setOnCompletionListener(new C0031b());
this.b.setOnErrorListener(new C0032c());
} catch (IOException unused) {
KitLog.error("LocalTtsAbility", "[playAudio] IOException!");
} catch (IllegalArgumentException unused2) {
KitLog.error("LocalTtsAbility", "[playAudio] IllegalArgumentException!");
}
}
public void g(Object obj) {
try {
this.a.offer(obj);
} catch (IllegalArgumentException unused) {
KitLog.error("LocalTtsAbility", "IllegalArgumentException!");
}
}
public void h(String str) {
this.g = str;
}
public void i(boolean z) {
this.d = z;
}
public final String k(String str) {
if (!TextUtils.isEmpty(str)) {
if (str.contains("WLAN")) {
str = str.replace("WLAN", "w lan");
} else if (str.contains("SIM")) {
str = str.replace("SIM", "sim");
} else {
KitLog.debug("LocalTtsAbility", "text not contains special content,so no need process it.", new Object[0]);
}
}
String p = p(str);
KitLog.debug("LocalTtsAbility", "after process,Text:{}", p);
return p;
}
public boolean l() {
return this.d;
}
public final String p(String str) {
return !TextUtils.isEmpty(str) ? str.replaceAll("(\\[p\\d+\\])|(\\[n\\d\\])", Constant.COMMA) : str;
}
public boolean q() {
return this.a.isEmpty();
}
public void r() {
Object poll = this.a.poll();
if (poll == null) {
if (this.e) {
KitLog.warn("LocalTtsAbility", "[doSpeak] speakTask is stopped!");
return;
}
KitLog.info("LocalTtsAbility", "[doSpeak] speakTask is empty!");
c();
b bVar = b.this;
bVar.onSpeechFinish(this.g, bVar.d, b.this.b, b.this.c);
return;
}
this.e = false;
b bVar2 = b.this;
bVar2.requestAudioFocus(bVar2.b, b.this.c, this.f);
if (!(poll instanceof String)) {
if (!(poll instanceof C0030b)) {
KitLog.warn("LocalTtsAbility", "unsupported Tag!");
return;
} else {
KitLog.debug("LocalTtsAbility", "Speak audio", new Object[0]);
f((C0030b) poll);
return;
}
}
if (b.this.g == null) {
KitLog.warn("LocalTtsAbility", "[doSpeak] ttsService not exist!");
b.this.d.onTtsError(1, "TTS service is null", this.g);
} else {
int doSpeak = b.this.g.doSpeak(k((String) poll), this.h);
KitLog.debug("LocalTtsAbility", "doSpeak result :{}", Boolean.valueOf(doSpeak == 100));
b.this.z(doSpeak, "speak fail", this.g);
}
}
public boolean s() {
return this.c || b.this.e0();
}
public void t() {
KitLog.debug("LocalTtsAbility", "SpeakTask stop", new Object[0]);
this.e = true;
MediaPlayer mediaPlayer = this.b;
if (mediaPlayer != null && this.c) {
mediaPlayer.stop();
}
b.this.a0();
b bVar = b.this;
bVar.abandonAudioFocus(bVar.b, b.this.c);
}
public String toString() {
StringBuilder sb = new StringBuilder(0);
for (Object obj : this.a) {
if (obj instanceof String) {
sb.append((String) obj);
sb.append(Constant.BLANK_SPACE);
} else if (obj instanceof C0030b) {
sb.append(((C0030b) obj).a());
sb.append(Constant.BLANK_SPACE);
} else {
KitLog.warn("LocalTtsAbility", "other type");
}
}
return "SpeakTask{speakDetail=" + sb.toString() + ", streamType=" + this.f + '}';
}
public void u() {
KitLog.debug("LocalTtsAbility", "SpeakTask destroy", new Object[0]);
MediaPlayer mediaPlayer = this.b;
if (mediaPlayer != null) {
if (this.c) {
mediaPlayer.stop();
}
this.b.release();
this.b = null;
}
b bVar = b.this;
bVar.abandonAudioFocus(bVar.b, b.this.c);
}
public c(b bVar, a aVar) {
this();
}
}
@Override
public void initEngine(Intent intent, boolean z) {
this.p = z;
initEngine(intent);
}
}