This commit is contained in:
wangcongtao
2020-04-14 17:08:24 +08:00
parent 7ed495aa9d
commit 2b415e499f
6 changed files with 96 additions and 13 deletions

View File

@@ -0,0 +1,80 @@
package com.mogo.utils.tts;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import java.util.Locale;
/**
* @author congtaowang
* @since 2020-04-14
* <p>
* 描述
*/
public class AndroidTTSPlayer extends UtteranceProgressListener implements TTSPlayer, TextToSpeech.OnInitListener {
private TextToSpeech mTtsEngine;
private Context mContext;
private boolean mIsSuccess = false;
private Bundle mParams;
/**
* {@link TextToSpeech.Engine#KEY_PARAM_STREAM},
* {@link TextToSpeech.Engine#KEY_PARAM_VOLUME},
* {@link TextToSpeech.Engine#KEY_PARAM_PAN}.
*
* @param context
*/
public AndroidTTSPlayer( Context context ) {
mContext = context.getApplicationContext();
mTtsEngine = new TextToSpeech( mContext, this );
mParams = new Bundle();
mParams.putInt( TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_ALARM );
mParams.putInt( TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_ALARM );
}
@Override
public void stop() {
if ( mTtsEngine != null ) {
mTtsEngine.stop();
}
}
@Override
public void speakTTS( String text ) {
// mTtsEngine.speak()
}
@Override
public void onInit( int status ) {
if ( status == TextToSpeech.SUCCESS ) {
int result = mTtsEngine.setLanguage( Locale.CHINA );
mTtsEngine.setPitch( 1.0f );// 设置音调,值越大声音越尖(女生),值越小则变成男声,1.0是常规
mTtsEngine.setSpeechRate( 1.0f );
mTtsEngine.setOnUtteranceProgressListener( this );
if ( result != TextToSpeech.LANG_MISSING_DATA || result != TextToSpeech.LANG_NOT_SUPPORTED ) {
//系统支持中文播报
mIsSuccess = true;
}
}
}
@Override
public void onStart( String utteranceId ) {
}
@Override
public void onDone( String utteranceId ) {
}
@Override
public void onError( String utteranceId ) {
}
}

View File

@@ -0,0 +1,14 @@
package com.mogo.utils.tts;
/**
* @author congtaowang
* @since 2020-04-14
* <p>
* 描述
*/
public interface TTSPlayer {
void stop();
void speakTTS( String text );
}

View File

@@ -633,8 +633,6 @@ public class AMapNaviViewWrapper implements IMogoMapView,
if ( checkAMapView() ) {
mMapView.setCarOverlayVisible( false );
showMyLocation( true );
NaviClient.getInstance( getContext() ).startAimlessMode();
}
}

View File

@@ -59,7 +59,7 @@ public class NaviClient implements IMogoNavi {
private NaviClient( Context context ) {
mAMapNavi = AMapNavi.getInstance( context );
mAMapNavi.setEmulatorNaviSpeed( 120 );
mAMapNavi.setUseInnerVoice( true, true );
mAMapNavi.setUseInnerVoice( false, true );
mAMapNaviListener = new NaviListenerAdapter( context, mAMapNavi, this );
mAimlessModeListener = new AimlessModeListenerAdapter() {
};
@@ -142,8 +142,6 @@ public class NaviClient implements IMogoNavi {
if ( mAMapNaviListener != null ) {
mAMapNaviListener.stopNavi();
}
// 开启巡航 巡航时返回电子眼和特殊道路设施信息
// mAMapNavi.startAimlessMode( AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED );
}
@@ -152,9 +150,6 @@ public class NaviClient implements IMogoNavi {
if ( mAMapNaviListener.isStopped() ) {
return;
}
// 关闭巡航
//mAMapNavi.stopAimlessMode();
stopAimlessMode();
mIsRealNavi = isRealNavi;
boolean isNaving = isNaviing();

View File

@@ -95,7 +95,6 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
@Override
public void onInitNaviSuccess() {
MogoNaviListenerHandler.getInstance().onInitNaviSuccess();
mAMapNavi.startAimlessMode( AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED );
}
@Override
@@ -163,9 +162,6 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
if ( type != NaviType.CRUISE ) {
setStopped( false );
setNaviing( true );
if ( mAMapNavi != null ) {
mAMapNavi.startSpeak();
}
MogoNaviListenerHandler.getInstance().onStartNavi();
AMapMessageManager.getInstance().postNaviStarted();
}

View File

@@ -112,7 +112,7 @@ public class WebSocketManager {
mNavi.setUseExtraGPSData( true );
mService.execute( () -> {
try {
mClient.reconnectBlocking();
mClient.connectBlocking();
Logger.d( TAG, "connectBlocking done." );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );