[6.2.0][Feat]接入小智Tts
This commit is contained in:
@@ -56,6 +56,7 @@ public class AIAssist {
|
||||
// 暂时换成反射,解决死锁问题
|
||||
Class<?> clazz1 = null;
|
||||
Class<?> clazz2 = null;
|
||||
Class<?> clazz3 = null;
|
||||
try {
|
||||
clazz1 = Class.forName("com.mogo.tts.pad.PadTTS");
|
||||
} catch (Exception ignored) {}
|
||||
@@ -64,13 +65,15 @@ public class AIAssist {
|
||||
clazz2 = Class.forName("com.mogo.tts.iflytek.IFlyTekTts");
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
clazz2 = Class.forName("com.mogo.tts.pad.ZhiTTS");
|
||||
clazz3 = Class.forName("com.mogo.tts.pad.ZhiTTS");
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
if (clazz1 != null) {
|
||||
mTTS = (IMogoTTS) clazz1.getConstructor().newInstance();
|
||||
} else if (clazz2 != null) {
|
||||
mTTS = (IMogoTTS) clazz2.getConstructor().newInstance();
|
||||
} else if (clazz3 != null) {
|
||||
mTTS = (IMogoTTS) clazz3.getConstructor().newInstance();
|
||||
}
|
||||
if (mTTS != null) {
|
||||
mTTS.init(context);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.mogo.tts.pad;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
@@ -11,6 +13,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
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.LangTtsEntity;
|
||||
import com.mogo.tts.base.MultiLangTtsEntity;
|
||||
import com.mogo.tts.base.PreemptType;
|
||||
import com.mogo.tts.base.zhi.AvatarManager;
|
||||
@@ -19,8 +22,11 @@ import com.mogo.xiaozhi.sdk.engine.DMStatusListener;
|
||||
import com.mogo.xiaozhi.sdk.engine.RecorderDMManager;
|
||||
import com.mogo.xiaozhi.sdk.engine.tts.AILocalTTS;
|
||||
import com.mogo.xiaozhi.sdk.module.show.ZDCloudDMManager;
|
||||
import com.mogo.xiaozhi.sdk.module.tts.ZDTtsManager;
|
||||
import com.zhidao.mogo.speech.sdk.ActionExecutor;
|
||||
import com.zhidao.mogo.speech.sdk.MOSTtsManager;
|
||||
import com.zhidao.speech.adapter.AdapterApp;
|
||||
import com.zhidao.voicesdk.ITtsListener;
|
||||
import com.zhidao.voicesdk.callback.OnTtsListener;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -112,10 +118,14 @@ public class ZhiTTS implements IMogoTTS, OnTtsListener {
|
||||
|
||||
public void stopSpeakTts(String text) {
|
||||
CallerLogger.d(TAG, "text");
|
||||
// 停止小智语音识别和语音合成
|
||||
ZDTtsManager.getInstance().shutUp(text);
|
||||
}
|
||||
|
||||
public void stopTts() {
|
||||
CallerLogger.d(TAG, "stopTts");
|
||||
// 停止小智语音识别和语音合成
|
||||
ActionExecutor.getInstance().action("mos.action.config.cancel", null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,14 +140,50 @@ public class ZhiTTS implements IMogoTTS, OnTtsListener {
|
||||
@MainThread
|
||||
public void speakTTSVoiceWithLevel(String text, int ttsLevel) {
|
||||
CallerLogger.d(TAG, "speakTTSVoiceWithLevel");
|
||||
ZDTtsManager.getInstance().speak(text, getZhiLevel(ttsLevel));
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public void speakTTSVoiceWithLevel(String text, int ttsLevel, IMogoTTSCallback callBack) {
|
||||
CallerLogger.d(TAG, "speakTTSVoiceWithLevel");
|
||||
ZDTtsManager.getInstance().speak(text, getZhiLevel(ttsLevel), new ITtsListener() {
|
||||
@Override
|
||||
public void onTtsStart(String s, String s1) throws RemoteException {}
|
||||
|
||||
@Override
|
||||
public void onTtsFinish(String s, String s1) throws RemoteException {
|
||||
if (callBack != null) {
|
||||
callBack.onSpeakEnd(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTtsError(String s, String s1) throws RemoteException {
|
||||
if (callBack != null) {
|
||||
callBack.onSpeakError(s, s1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder asBinder() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private int getZhiLevel(int ttsLevel) {
|
||||
if (ttsLevel == 3) {
|
||||
return MOSTtsManager.PRIORITY_XIAOZHI_EMERGENCY;
|
||||
} else if (ttsLevel == 2) {
|
||||
return MOSTtsManager.PRIORITY_EMERGENCY;
|
||||
} else if (ttsLevel == 1) {
|
||||
return MOSTtsManager.PRIORITY_IMPORTANT;
|
||||
} else if (ttsLevel == 0) {
|
||||
return MOSTtsManager.PRIORITY_NORMAL;
|
||||
} else {
|
||||
return MOSTtsManager.PRIORITY_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 语音播报
|
||||
@@ -152,6 +198,12 @@ public class ZhiTTS implements IMogoTTS, OnTtsListener {
|
||||
@Override
|
||||
public void speakMultiLangTTSWithLevel(MultiLangTtsEntity ttsEntity, int level, IMogoTTSCallback callback) {
|
||||
CallerLogger.d(TAG, "speakMultiLangTTSWithLevel");
|
||||
if (ttsEntity != null) {
|
||||
LangTtsEntity langTtsEntity = ttsEntity.ttsNext();
|
||||
if (langTtsEntity != null) {
|
||||
speakTTSVoiceWithLevel(langTtsEntity.getTtsContent(), level, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user