Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-07-03 16:24:13 +02:00
commit aa50076749
3 changed files with 28 additions and 10 deletions

View file

@ -171,6 +171,8 @@ public class VoiceRouter {
}
}
private double btScoDelayDistance = 0;
public boolean isDistanceLess(float currentSpeed, double dist, double etalon, float defSpeed){
if(defSpeed <= 0) {
defSpeed = DEFAULT_SPEED;
@ -178,7 +180,13 @@ public class VoiceRouter {
if(currentSpeed <= 0) {
currentSpeed = DEFAULT_SPEED;
}
if(dist < etalon || ((dist / currentSpeed) < (etalon / defSpeed))){
// Trigger close prompts earlier to allow for BT SCO connection delay
if (settings.AUDIO_STREAM_GUIDANCE.get() == 0) {
btScoDelayDistance = currentSpeed * (double) AbstractPrologCommandPlayer.BT_SCO_DELAY / 1000;
}
if((dist < etalon + btScoDelayDistance) || ((dist / currentSpeed) < ((etalon + btScoDelayDistance) / defSpeed))){
return true;
}
return false;
@ -480,9 +488,9 @@ public class VoiceRouter {
if (repeat || dist >= TURN_IN_DISTANCE_END) {
if ((isDistanceLess(speed, nextNextInfo.distanceTo, TURN_DISTANCE, 0f) || nextNextInfo.distanceTo < TURN_IN_DISTANCE_END) &&
nextNextInfo != null) {
playMakeTurnIn(currentSegment, next, dist, nextNextInfo.directionInfo);
playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, nextNextInfo.directionInfo);
} else {
playMakeTurnIn(currentSegment, next, dist, null);
playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, null);
}
playAndArriveAtDestination(repeat, nextInfo, currentSegment);
}

View file

@ -283,7 +283,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
}
// If AudioManager.STREAM_VOICE_CALL try using BT SCO:
if (ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) {
startBtSco();
startBtSco(ctx);
}
}
@ -299,7 +299,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
protected void abandonAudioFocus() {
log.debug("abandonAudioFocus");
if ((ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) || (btScoStatus == true)) {
stopBtSco();
stopBtSco(ctx);
}
if (mAudioFocusHelper != null) {
mAudioFocusHelper.abandonFocus(ctx, streamType);
@ -311,11 +311,11 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
public static final int BT_SCO_DELAY = 1500;
private boolean startBtSco() {
private boolean startBtSco(Context context) {
// Establish a low quality Synchronous Connection-Oriented link to BT to e.g. interrupt a car stereo
// http://stackoverflow.com/questions/2144694/routing-audio-to-bluetooth-headset-non-a2dp-on-android
try {
AudioManager mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
//if (mAudioManager == null || !mAudioManager.isBluetoothScoAvailableOffCall()) {
if (mAudioManager == null) {
return false;
@ -333,9 +333,9 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
return btScoStatus;
}
private boolean stopBtSco() {
private boolean stopBtSco(Context context) {
btScoStatus = false;
AudioManager mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (mAudioManager == null) {
return false;
}

View file

@ -108,6 +108,16 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
if (ttsRequests++ == 0)
requestAudioFocus();
log.debug("ttsRequests="+ttsRequests);
// Delay prompts to allow BT SCO connection being established
if (ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) {
ttsRequests++;
if (android.os.Build.VERSION.SDK_INT <= 21) {
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
mTts.playSilence(BT_SCO_DELAY, TextToSpeech.QUEUE_ADD, params);
} else {
mTts.playSilentUtterance(BT_SCO_DELAY, TextToSpeech.QUEUE_ADD, ""+System.currentTimeMillis());
}
}
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
mTts.speak(bld.toString(), TextToSpeech.QUEUE_ADD, params);
// Audio focus will be released when onUtteranceCompleted() completed is called by the TTS engine.