更改联想PAD启动小智语音的时机
This commit is contained in:
@@ -2,6 +2,8 @@ package com.mogo.tts.pad;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
@@ -11,6 +13,7 @@ import com.mogo.tts.base.MogoTTSConstants;
|
||||
import com.mogo.tts.base.PreemptType;
|
||||
import com.mogo.utils.AppUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.permissions.PermissionsDialogUtils;
|
||||
import com.zhidao.auto.platform.voice.VoiceClient;
|
||||
import com.zhidao.voicesdk.MogoVoiceManager;
|
||||
import com.zhidao.voicesdk.MogoVoiceManagerImpl;
|
||||
@@ -34,7 +37,7 @@ public
|
||||
@Route( path = MogoTTSConstants.API_PATH )
|
||||
class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
|
||||
private static final String TAG = "ZhiTTS";
|
||||
private static final String TAG = "PadTTS";
|
||||
private String mLastQAndASpeakText;
|
||||
|
||||
private boolean mHasFlush = false;
|
||||
@@ -48,6 +51,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
try {
|
||||
mVoiceClient.unRegisterCustomWakeupCmd( cmd );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,6 +83,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
* 初始化
|
||||
*/
|
||||
private void initSpeech( Context context ) {
|
||||
Logger.d(TAG, "initSpeech");
|
||||
mogoVoiceManager = MogoVoiceManagerImpl.getInstance();
|
||||
mogoVoiceManager.init( context, new OnConnStatusListener() {
|
||||
@Override
|
||||
@@ -115,7 +120,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
List< IMogoTTSCallback > cmdCallBacks = mCmdMap.get( cmd );
|
||||
iterator = new ArrayList<>( cmdCallBacks ).iterator();
|
||||
} catch ( Exception e ) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
while ( iterator != null && iterator.hasNext() ) {
|
||||
IMogoTTSCallback callBack = iterator.next();
|
||||
@@ -192,6 +197,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
mVoiceClient.speakDefault( text );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +213,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
mVoiceClient.speakDefault( text );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,6 +248,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
mVoiceClient.speakTypeText( text, preemptType );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,6 +328,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
try {
|
||||
mVoiceClient.unRegisterCustomWakeupCmd( cmd );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mCacheUnWakeupCommands.remove( cmd );
|
||||
}
|
||||
@@ -340,6 +349,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
try {
|
||||
mVoiceClient.unRegisterCustomWakeupCmd( cmd );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mCacheUnWakeupCommands.remove( cmd );
|
||||
}
|
||||
@@ -355,6 +365,8 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
* @param status window_start_cancel 0 - 结束, 1 - 显示, 2 - 未激活调试进入
|
||||
*/
|
||||
public static void startAssistant( Context context, int status ) {
|
||||
Logger.w(TAG, "startAssistant status = %d", status);
|
||||
|
||||
final Intent intent = new Intent();
|
||||
intent.setFlags( Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
|
||||
intent.setAction( "pvetec.intent.action.txz.switch" );
|
||||
@@ -378,6 +390,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
|
||||
private boolean isVoiceServiceReady( Context context ) {
|
||||
if ( AppUtils.isProcessRunning( context, AppUtils.getPackageUid( context, "com.zhidao.speech" ) )) {
|
||||
Logger.d( TAG, "pad txz is voiceServiceReady" );
|
||||
return true;
|
||||
} else if ( AppUtils.isProcessRunning( context, AppUtils.getPackageUid( context, "com.txznet.txz" ) )
|
||||
&& AppUtils.isProcessRunning( context, AppUtils.getPackageUid( context, "com.txznet.adapter" ) ) ) {
|
||||
@@ -398,6 +411,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
mogoVoiceManager.toSpeak( text, -3, this );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +420,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
mSpeakVoiceMap.remove( text );
|
||||
mogoVoiceManager.shutUp( ttsId );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,8 +471,15 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
mVoiceClient = new VoiceClient( mContext );
|
||||
mVoiceClient.setCallBack( this );
|
||||
initFlushStatus();
|
||||
initSpeech( context );
|
||||
Logger.w( TAG, "voice is ready = %s", mHasFlush );
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// 检查是否有悬浮窗权限
|
||||
if (Settings.canDrawOverlays(context)) {
|
||||
initSpeech(context);
|
||||
}
|
||||
} else {
|
||||
initSpeech(context);
|
||||
}
|
||||
Logger.w(TAG, "voice is mHasFlush = %s mInitReady= %s", mHasFlush, mInitReady);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,6 +490,7 @@ class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
|
||||
|
||||
@Override
|
||||
public void startAIAssist( Context context, int status ) {
|
||||
Logger.w(TAG, "startAIAssist status = %d", status);
|
||||
final Intent intent = new Intent();
|
||||
intent.setFlags( Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
|
||||
intent.setAction( "pvetec.intent.action.txz.switch" );
|
||||
|
||||
Reference in New Issue
Block a user