From f77a3d5f6b7da7b38fcd3b65c6595cc45a8dbcac Mon Sep 17 00:00:00 2001 From: sonora Date: Mon, 4 Jul 2016 10:00:14 +0200 Subject: [PATCH] add silence only to first BT SCO prompt of each batch --- .../net/osmand/plus/routing/VoiceRouter.java | 2 +- .../voice/AbstractPrologCommandPlayer.java | 2 +- .../plus/voice/TTSCommandPlayerImpl.java | 25 ++++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 451e653a35..bf1f46bbec 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -182,7 +182,7 @@ public class VoiceRouter { } // Trigger close prompts earlier to allow for BT SCO connection delay - if (settings.AUDIO_STREAM_GUIDANCE.get() == 0) { + if ((settings.AUDIO_STREAM_GUIDANCE.get() == 0) && !AbstractPrologCommandPlayer.btScoStatus) { btScoDelayDistance = currentSpeed * (double) AbstractPrologCommandPlayer.BT_SCO_DELAY / 1000; } diff --git a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java index 3fa2e29570..0bd10f4e25 100644 --- a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java @@ -307,7 +307,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat } } - private static boolean btScoStatus = false; + public static boolean btScoStatus = false; public static final int BT_SCO_DELAY = 1500; diff --git a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java index 78b912dc86..5b7e1b046f 100644 --- a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java @@ -92,7 +92,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { * and the call back to onUtteranceCompletedListener(). This allows us to * optimize use of requesting and abandoning audio focus. */ - private int ttsRequests; + private static int ttsRequests; private float cSpeechRate = 1; // Called from the calculating route thread. @@ -105,19 +105,20 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { } sendAlertToPebble(bld.toString()); if (mTts != null && !vrt.isMute()) { - if (ttsRequests++ == 0) + 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()); + // 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()); + } } } + log.debug("ttsRequests="+ttsRequests); 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. @@ -211,7 +212,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { // The call back is on a binder thread. @Override public synchronized void onUtteranceCompleted(String utteranceId) { - if (--ttsRequests == 0) + if (--ttsRequests <= 0) abandonAudioFocus(); log.debug("ttsRequests="+ttsRequests); }