[feature]
[xiaozhi]
This commit is contained in:
@@ -7,6 +7,8 @@ object AvatarManager {
|
||||
private var isShowing = false
|
||||
private val mControllerStatusCallbackMap = ConcurrentHashMap<String, ZhiRecordWinUi>()
|
||||
|
||||
private var actionCallback:IActionCallback?=null
|
||||
|
||||
fun addDistanceListener(tag: String, listener: ZhiRecordWinUi) {
|
||||
if (mControllerStatusCallbackMap.containsKey(tag)) {
|
||||
return
|
||||
@@ -22,6 +24,19 @@ object AvatarManager {
|
||||
mControllerStatusCallbackMap.remove(tag)
|
||||
}
|
||||
|
||||
fun setActionCallback(actionCallback:IActionCallback){
|
||||
this.actionCallback = actionCallback
|
||||
}
|
||||
|
||||
fun wakeupXiaoZhi(){
|
||||
this.actionCallback?.wakeupXiaoZhi()
|
||||
}
|
||||
|
||||
fun enableXiaoZhi(enable:Boolean){
|
||||
this.actionCallback?.enableXiaoZhi(enable)
|
||||
}
|
||||
|
||||
|
||||
fun isShowing():Boolean{
|
||||
return isShowing
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mogo.tts.base.zhi;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/12
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
interface IActionCallback {
|
||||
// 手动唤醒小智
|
||||
void wakeupXiaoZhi();
|
||||
// 临时暂停启用小智
|
||||
void enableXiaoZhi(boolean enable);
|
||||
}
|
||||
@@ -47,7 +47,6 @@ dependencies {
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
|
||||
api rootProject.ext.dependencies.aiassist
|
||||
implementation rootProject.ext.dependencies.aiassistReplace
|
||||
implementation rootProject.ext.dependencies.androidxrecyclerview
|
||||
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
@@ -59,8 +58,15 @@ dependencies {
|
||||
}
|
||||
|
||||
// implementation project(":xiaozhisdk")
|
||||
implementation 'com.zhidao.speech.adapter:speechadapter:1.0.0-SNAPSHOT'
|
||||
implementation 'com.mogo.xiaozhi.sdk:xiaozhisdk:1.0.0-SNAPSHOT'
|
||||
// implementation project(':speechadapter')
|
||||
// implementation project(':mogoVoiceSdk')
|
||||
// implementation project(':mogospeechsdk')
|
||||
|
||||
implementation 'com.zhidao.mogoVoicesdk:voicesdk:1.0.1-SNAPSHOT'
|
||||
implementation 'com.zhidao.speech.adapter:speechadapter:1.0.1-SNAPSHOT'
|
||||
implementation 'com.zhidao.mogo.speech.sdk:mogospeech:1.0.1-SNAPSHOT'
|
||||
implementation 'com.mogo.xiaozhi.sdk:xiaozhisdk:1.0.1-SNAPSHOT'
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -70,14 +70,16 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service android:name="com.zhidao.mogo.speech.sdk.ZDSpeechService"
|
||||
android:exported="true"
|
||||
android:enabled="true">
|
||||
<service
|
||||
android:name="com.mogo.xiaozhi.sdk.service.ProcessService"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.zhidao.speech.adapter.service"/>
|
||||
<action android:name="com.mogo.xiaozhi.sdk.service.process" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
|
||||
<meta-data
|
||||
android:name="XIAOZHI_API_KEY"
|
||||
android:value="113cc31f6385113cc31f6385618c86f5" />
|
||||
|
||||
@@ -33,13 +33,6 @@ public class ZhiAvatarWindow implements RecordWinUi {
|
||||
private static final String TAG = ZhiAvatarWindow.class.getSimpleName();
|
||||
|
||||
|
||||
private ImageView leftImageView;
|
||||
private TextView mNormalChatTextView;
|
||||
|
||||
|
||||
private boolean flagWeather = false;
|
||||
private boolean isLeftImageShowingWeather = false;
|
||||
|
||||
public ZhiAvatarWindow() {
|
||||
}
|
||||
|
||||
@@ -127,7 +120,6 @@ public class ZhiAvatarWindow implements RecordWinUi {
|
||||
|
||||
if (CallbackWidgetType.CUSTOM.getType() == callbackWidget.getType()) {
|
||||
CustomCallbackWidget customCallbackWidget = (CustomCallbackWidget) callbackWidget;
|
||||
//showCustomWidget(customCallbackWidget);
|
||||
Log.w(TAG, "天气支持");
|
||||
} else if (CallbackWidgetType.LIST.getType() == callbackWidget.getType()) {
|
||||
ListCallbackWidget listCallbackWidget = (ListCallbackWidget) callbackWidget;
|
||||
@@ -148,90 +140,6 @@ public class ZhiAvatarWindow implements RecordWinUi {
|
||||
AvatarManager.INSTANCE.dispatchShowOutputTextEvent(outPutText);
|
||||
}
|
||||
|
||||
private void showIconAnimation(RecordStatus status) {
|
||||
LogUtil.d(TAG, "status = " + status);
|
||||
switch (status) {
|
||||
case STATUS_LISTENING:
|
||||
playAnimation(leftImageView, R.drawable.anim_voice_listening);
|
||||
break;
|
||||
case STATUS_UNDERSTANDING:
|
||||
playAnimation(leftImageView, R.drawable.anim_voice_loading);
|
||||
case STATUS_SPEAKING:
|
||||
playAnimation(leftImageView, R.drawable.anim_voice_speaking);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放动画
|
||||
* 如果当前是天气图片,直接返回;
|
||||
*
|
||||
* @param chatIconView 需要播放动画的 ImageView
|
||||
* @param resourceId 需要播放动画的ImageView 的 Animation Drawable.
|
||||
*/
|
||||
private void playAnimation(final ImageView chatIconView, final int resourceId) {
|
||||
chatIconView.setImageResource(resourceId);
|
||||
if (isLeftImageShowingWeather) {
|
||||
LogUtil.d(TAG, "weather icon, not animation.");
|
||||
return;
|
||||
}
|
||||
|
||||
// stop current animation first.
|
||||
Drawable animDrawable = chatIconView.getDrawable();
|
||||
if (!(animDrawable instanceof AnimationDrawable)) {
|
||||
LogUtil.e(TAG, "chatIconView should have a AnimationDrawable");
|
||||
return;
|
||||
}
|
||||
AnimationDrawable anim = (AnimationDrawable) animDrawable;
|
||||
anim.stop();
|
||||
chatIconView.animate()
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.setDuration(100)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.setListener(new AnimationEndListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
chatIconView.setImageResource(resourceId);
|
||||
chatIconView.setAlpha(0f);
|
||||
chatIconView.setScaleX(0f);
|
||||
chatIconView.setScaleY(0f);
|
||||
chatIconView.animate()
|
||||
.alpha(1f)
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.setDuration(100)
|
||||
.setListener(new AnimationEndListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
AnimationDrawable anim = (AnimationDrawable) chatIconView.getDrawable();
|
||||
anim.start();
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* only onAnimationEnd is required here. other call back is empty.
|
||||
*/
|
||||
abstract static class AnimationEndListener implements Animator.AnimatorListener {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
}
|
||||
}
|
||||
|
||||
private void trackAwakeEvent() {
|
||||
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
String time = dateformat.format(System.currentTimeMillis());
|
||||
|
||||
@@ -3,24 +3,27 @@ package com.mogo.tts.pad;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
|
||||
import com.elegant.utils.storage.SharedPrefsMgr;
|
||||
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.MultiLangTtsEntity;
|
||||
import com.mogo.tts.base.PreemptType;
|
||||
import com.mogo.tts.base.zhi.AvatarManager;
|
||||
import com.mogo.tts.base.zhi.IActionCallback;
|
||||
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.zhidao.auto.platform.voice.VoiceClient;
|
||||
import com.zhidao.mogo.speech.sdk.ActionExecutor;
|
||||
import com.zhidao.speech.adapter.AdapterApp;
|
||||
import com.zhidao.voicesdk.callback.OnTtsListener;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -34,6 +37,8 @@ public class ZhiTTS implements IMogoTTS, OnTtsListener {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private AtomicBoolean initStatus = new AtomicBoolean(false);
|
||||
|
||||
public void release() {
|
||||
CallerLogger.d(TAG, "release");
|
||||
}
|
||||
@@ -42,14 +47,32 @@ public class ZhiTTS implements IMogoTTS, OnTtsListener {
|
||||
@Override
|
||||
public void initTts(String sn) {
|
||||
CallerLogger.d(TAG, "initTts");
|
||||
// TODO: 2023/11/3 后续小智放入到子进程中 小智目前已支持
|
||||
AdapterApp.getInstance().init(mContext);
|
||||
AvatarManager.INSTANCE.setActionCallback(new IActionCallback() {
|
||||
@Override
|
||||
public void wakeupXiaoZhi() {
|
||||
if(initStatus.get()){
|
||||
ActionExecutor.getInstance().action("mos.action.config.trigger", null);
|
||||
}else {
|
||||
ToastUtils.showShort("请稍后在试试吧");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableXiaoZhi(boolean enable) {
|
||||
if(enable){
|
||||
ActionExecutor.getInstance().action("mos.action.config.cancel", null);
|
||||
}
|
||||
AILocalTTS.getInstance().setIsForbidASR(enable);
|
||||
}
|
||||
});
|
||||
ZDCloudDMManager.getInstance().setUIView(ZhiAvatarWindow.class);
|
||||
|
||||
RecorderDMManager.getInstance().registerListener(new DMStatusListener() {
|
||||
@Override
|
||||
public void onInitSuccess() {
|
||||
CallerLogger.d(TAG, "RecorderDMManager---onInitSuccess");
|
||||
initStatus.set(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +98,7 @@ public class ZhiTTS implements IMogoTTS, OnTtsListener {
|
||||
@Override
|
||||
public boolean hasFlush() {
|
||||
CallerLogger.d(TAG, "hasFlush");
|
||||
return true;
|
||||
return initStatus.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user