wait continue
This commit is contained in:
@@ -8,6 +8,10 @@ import android.text.TextUtils;
|
||||
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.auto.platform.voice.VoiceClient;
|
||||
import com.zhidao.voicesdk.MogoVoiceManager;
|
||||
import com.zhidao.voicesdk.MogoVoiceManagerImpl;
|
||||
import com.zhidao.voicesdk.callback.OnConnStatusListener;
|
||||
import com.zhidao.voicesdk.callback.OnTtsListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -22,13 +26,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* <p>
|
||||
* 语音助手通信助手
|
||||
*/
|
||||
public class AIAssist implements VoiceClient.VoiceCmdCallBack {
|
||||
public class AIAssist implements VoiceClient.VoiceCmdCallBack , OnTtsListener {
|
||||
|
||||
private static final String TAG = "AIAssist";
|
||||
private static volatile AIAssist sInstance;
|
||||
private String mLastQAndASpeakText;
|
||||
|
||||
private boolean mHasFlush = false;
|
||||
private boolean mInitReady = false;
|
||||
|
||||
public static AIAssist getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
@@ -56,6 +61,7 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack {
|
||||
}
|
||||
|
||||
private final VoiceClient mVoiceClient;
|
||||
private MogoVoiceManager mogoVoiceManager;
|
||||
// 免唤醒指令
|
||||
private Map< String, List< IMogoVoiceCmdCallBack > > mCmdMap = new HashMap<>();
|
||||
// 问答指令
|
||||
@@ -70,7 +76,7 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack {
|
||||
mVoiceClient = new VoiceClient( context.getApplicationContext() );
|
||||
mVoiceClient.setCallBack( this );
|
||||
initFlushStatus( context );
|
||||
|
||||
initSpeech( context );
|
||||
Logger.w( TAG, "voice is ready = %s", mHasFlush );
|
||||
}
|
||||
|
||||
@@ -78,6 +84,24 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack {
|
||||
mHasFlush = isVoiceServiceReady( context );
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private void initSpeech( Context context ){
|
||||
mogoVoiceManager = MogoVoiceManagerImpl.getInstance();
|
||||
mogoVoiceManager.init(context, new OnConnStatusListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mInitReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否语音注册成功
|
||||
* @return
|
||||
@@ -185,7 +209,6 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 语音播报
|
||||
*
|
||||
@@ -402,4 +425,36 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void speakTTSAndDuck(String text ){
|
||||
speakTTSAndDuck(text,null);
|
||||
}
|
||||
|
||||
public void speakTTSAndDuck( String text, IMogoVoiceCmdCallBack callBack ){
|
||||
try {
|
||||
if( mInitReady ){
|
||||
mSpeakVoiceMap.put( text, callBack );
|
||||
mogoVoiceManager.toSpeak( text, -3, this);
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTtsStart(String ext) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTtsFinish(String speakText) {
|
||||
IMogoVoiceCmdCallBack callBack = mSpeakVoiceMap.remove( speakText );
|
||||
if ( callBack != null ) {
|
||||
callBack.onSpeakEnd( speakText );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTtsError(String ext) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user