This commit is contained in:
wangcongtao
2020-04-22 15:15:41 +08:00
parent cc118fddb4
commit 9e478e4a21
11 changed files with 279 additions and 157 deletions

View File

@@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
* <p>
* 语音助手通信助手
*/
public class AIAssist implements VoiceClient.VoiceCmdCallBack , OnTtsListener {
public class AIAssist implements VoiceClient.VoiceCmdCallBack, OnTtsListener {
private static final String TAG = "AIAssist";
private static volatile AIAssist sInstance;
@@ -87,9 +87,9 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack , OnTtsListener {
/**
* 初始化
*/
private void initSpeech( Context context ){
private void initSpeech( Context context ) {
mogoVoiceManager = MogoVoiceManagerImpl.getInstance();
mogoVoiceManager.init(context, new OnConnStatusListener() {
mogoVoiceManager.init( context, new OnConnStatusListener() {
@Override
public void onSuccess() {
mInitReady = true;
@@ -99,11 +99,12 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack , OnTtsListener {
public void onFailed() {
}
});
} );
}
/**
* 是否语音注册成功
*
* @return
*/
public boolean hasFlush() {
@@ -425,36 +426,59 @@ public class AIAssist implements VoiceClient.VoiceCmdCallBack , OnTtsListener {
return false;
}
public void speakTTSAndDuck(String text ){
speakTTSAndDuck(text,null);
public void speakTTSAndDuck( String text ) {
speakTTSAndDuck( text, null );
}
public void speakTTSAndDuck( String text, IMogoVoiceCmdCallBack callBack ){
public void speakTTSAndDuck( String text, IMogoVoiceCmdCallBack callBack ) {
try {
if( mInitReady ){
if ( mInitReady ) {
mSpeakVoiceMap.put( text, callBack );
mogoVoiceManager.toSpeak( text, -3, this);
mogoVoiceManager.toSpeak( text, -3, this );
}
} catch ( Exception e ) {
}
}
@Override
public void onTtsStart(String ext) {
public void shutUp( String ttsId, String text ) {
try {
mSpeakVoiceMap.remove( text );
mogoVoiceManager.shutUp( ttsId );
} catch( Exception e ){
}
}
@Override
public void onTtsFinish(String speakText) {
IMogoVoiceCmdCallBack callBack = mSpeakVoiceMap.remove( speakText );
if ( callBack != null ) {
callBack.onSpeakEnd( speakText );
public void clearTTSCallback(String text){
try {
mSpeakVoiceMap.remove( text );
} catch ( Exception e ) {
e.printStackTrace();
}
}
@Override
public void onTtsError(String ext) {
public void onTtsStart( String ttsId, String text ) {
IMogoVoiceCmdCallBack callBack = mSpeakVoiceMap.get( text );
if ( callBack != null ) {
callBack.onTTSStart( ttsId, text );
}
}
@Override
public void onTtsFinish( String ttsId, String text ) {
IMogoVoiceCmdCallBack callBack = mSpeakVoiceMap.remove( text );
if ( callBack != null ) {
callBack.onTTSEnd( ttsId, text );
}
}
@Override
public void onTtsError( String ttsId, String text ) {
IMogoVoiceCmdCallBack callBack = mSpeakVoiceMap.remove( text );
if ( callBack != null ) {
callBack.onTTSError( ttsId, text );
}
}
}

View File

@@ -1,6 +1,34 @@
package com.mogo.commons.voice;
public interface IMogoVoiceCmdCallBack {
/**
* 新SDK接口
*
* @param ttsId
* @param tts
*/
default void onTTSStart( String ttsId, String tts ) {
}
/**
* 新SDK接口
*
* @param ttsId
* @param tts
*/
default void onTTSEnd( String ttsId, String tts ) {
}
/**
* 新SDK接口
*
* @param ttsId
* @param tts
*/
default void onTTSError( String ttsId, String tts ) {
}
/**
* 免唤醒命令响应回调
*