Voice Prompt Delay for all modes (#8706)
This commit is contained in:
parent
a0686639ff
commit
5b89e87687
7 changed files with 59 additions and 48 deletions
|
@ -2090,7 +2090,15 @@ public class OsmandSettings {
|
|||
12/*AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE*/).makeProfile();
|
||||
|
||||
// For now this can be changed only in TestVoiceActivity
|
||||
public final OsmandPreference<Integer> BT_SCO_DELAY = new IntPreference("bt_sco_delay", 1500).makeGlobal().cache();
|
||||
public final OsmandPreference<Integer>[] VOICE_PROMPT_DELAY = new IntPreference[5];
|
||||
|
||||
{
|
||||
// On most devices sound output works pomptly so usually no voice prompt delay needed
|
||||
VOICE_PROMPT_DELAY[3] = new IntPreference("voice_prompt_delay_3", 0).makeGlobal().cache(); /*AudioManager.STREAM_MUSIC*/
|
||||
VOICE_PROMPT_DELAY[5] = new IntPreference("voice_prompt_delay_5", 0).makeGlobal().cache(); /*AudioManager.STREAM_NOTIFICATION*/
|
||||
// 1500 ms delay works for most configurations to establish a BT SCO link
|
||||
VOICE_PROMPT_DELAY[0] = new IntPreference("voice_prompt_delay_0", 1500).makeGlobal().cache(); /*AudioManager.STREAM_VOICE_CALL*/
|
||||
}
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<Boolean> MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeProfile();
|
||||
|
|
|
@ -147,7 +147,8 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
|
|||
v += "\n \u25CF BT SCO: The current app profile is not set to use 'Phone call audio'.";
|
||||
}
|
||||
|
||||
v += "\n \u25CF Phone call audio delay: " + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() + "\u00A0ms";
|
||||
v += "\n \u25CF Voice prompt delay for selected output: " + ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY
|
||||
[((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get()].get() + "\u00A0ms";
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -230,7 +231,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
|
|||
|
||||
addButton(ll, "Voice system info:", builder(p));
|
||||
addButton(ll, "\u25BA (11.1) (Tap to refresh)\n" + getVoiceSystemInfo(), builder(p).attention(""));
|
||||
addButton(ll, "\u25BA (11.2) Tap to change Phone call audio delay (if car stereo cuts off prompts). Default is 1500\u00A0ms.", builder(p).attention(""));
|
||||
addButton(ll, "\u25BA (11.2) Tap to change voice prompt delay (if car stereo cuts off prompts). Default is 1500\u00A0ms for Phone call audio, or else 0\u00A0ms.", builder(p).attention(""));
|
||||
ll.forceLayout();
|
||||
}
|
||||
|
||||
|
@ -282,23 +283,20 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
|
|||
Toast.makeText(TestVoiceActivity.this, "Info refreshed.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (description.startsWith("\u25BA (11.2)")) {
|
||||
if (((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get() == 0) {
|
||||
if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1000) {
|
||||
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1500);
|
||||
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1500) {
|
||||
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2000);
|
||||
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2000) {
|
||||
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2500);
|
||||
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2500) {
|
||||
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(3000);
|
||||
int ams = ((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get();
|
||||
if (((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].get() == 1000) {
|
||||
((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].set(1500);
|
||||
} else if (((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].get() == 1500) {
|
||||
((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].set(2000);
|
||||
} else if (((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].get() == 2000) {
|
||||
((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].set(2500);
|
||||
} else if (((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].get() == 2500) {
|
||||
((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].set(3000);
|
||||
} else {
|
||||
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1000);
|
||||
((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].set(1000);
|
||||
}
|
||||
infoButton.setText("\u25BA (11.1) (Tap to refresh)\n" + getVoiceSystemInfo());
|
||||
Toast.makeText(TestVoiceActivity.this, "BT SCO init delay changed to " + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() + "\u00A0ms.", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(TestVoiceActivity.this, "Setting only available when using 'Phone call audio'.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
Toast.makeText(TestVoiceActivity.this, "Voice prompt delay changed to " + ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams].get() + "\u00A0ms.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -192,7 +192,7 @@ public class VoiceRouter {
|
|||
}
|
||||
}
|
||||
|
||||
private double btScoDelayDistance = 0;
|
||||
private double voicePromptDelayDistance = 0;
|
||||
|
||||
public boolean isDistanceLess(float currentSpeed, double dist, double etalon, float defSpeed) {
|
||||
if (defSpeed <= 0) {
|
||||
|
@ -202,12 +202,13 @@ public class VoiceRouter {
|
|||
currentSpeed = DEFAULT_SPEED;
|
||||
}
|
||||
|
||||
// Trigger close prompts earlier if delayed for BT SCO connection establishment
|
||||
if ((settings.AUDIO_MANAGER_STREAM.getModeValue(router.getAppMode()) == 0) && !AbstractPrologCommandPlayer.btScoStatus) {
|
||||
btScoDelayDistance = currentSpeed * (double) settings.BT_SCO_DELAY.get() / 1000;
|
||||
// Trigger close prompts earlier to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
|
||||
int ams = settings.AUDIO_MANAGER_STREAM.getModeValue(router.getAppMode());
|
||||
if (((ams == 0) && !AbstractPrologCommandPlayer.btScoStatus) || (ams > 0)) {
|
||||
voicePromptDelayDistance = currentSpeed * (double) settings.VOICE_PROMPT_DELAY[ams].get() / 1000;
|
||||
}
|
||||
|
||||
if ((dist < etalon + btScoDelayDistance) || ((dist - btScoDelayDistance) / currentSpeed) < (etalon / defSpeed)) {
|
||||
if ((dist < etalon + voicePromptDelayDistance) || ((dist - voicePromptDelayDistance) / currentSpeed) < (etalon / defSpeed)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -520,9 +521,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 - (int) btScoDelayDistance, nextNextInfo.directionInfo);
|
||||
playMakeTurnIn(currentSegment, next, dist - (int) voicePromptDelayDistance, nextNextInfo.directionInfo);
|
||||
} else {
|
||||
playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, null);
|
||||
playMakeTurnIn(currentSegment, next, dist - (int) voicePromptDelayDistance, null);
|
||||
}
|
||||
playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
|
||||
}
|
||||
|
|
|
@ -322,9 +322,6 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
|||
|
||||
public static boolean btScoStatus = false;
|
||||
|
||||
// BT_SCO_DELAY now in Settings. 1500 ms works for most configurations.
|
||||
//public static final int BT_SCO_DELAY = 1500;
|
||||
|
||||
// This only needed for init debugging in TestVoiceActivity:
|
||||
public static String btScoInit = "-";
|
||||
|
||||
|
|
|
@ -55,15 +55,17 @@ public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl {
|
|||
// If we have not already started to play audio, start.
|
||||
if (mediaPlayer == null) {
|
||||
requestAudioFocus();
|
||||
// Delay first prompt of each batch to allow BT SCO connection being established
|
||||
if (ctx != null && ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode()) == 0) {
|
||||
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
|
||||
if (ctx != null) {
|
||||
int vpd = ctx.getSettings().VOICE_PROMPT_DELAY[ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode())].get();
|
||||
if (vpd > 0) {
|
||||
try {
|
||||
log.debug("Delaying MediaCommandPlayer for BT SCO");
|
||||
Thread.sleep(ctx.getSettings().BT_SCO_DELAY.get());
|
||||
Thread.sleep(vpd);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
playQueue();
|
||||
return lst;
|
||||
}
|
||||
|
|
|
@ -87,15 +87,17 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
|||
// If we have not already started to play audio, start.
|
||||
if (mediaPlayer == null) {
|
||||
requestAudioFocus();
|
||||
// Delay first prompt of each batch to allow BT SCO connection being established
|
||||
if (ctx != null && ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode()) == 0) {
|
||||
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
|
||||
if (ctx != null) {
|
||||
int vpd = ctx.getSettings().VOICE_PROMPT_DELAY[ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode())].get();
|
||||
if (vpd > 0) {
|
||||
try {
|
||||
log.debug("Delaying MediaCommandPlayer for BT SCO");
|
||||
Thread.sleep(ctx.getSettings().BT_SCO_DELAY.get());
|
||||
Thread.sleep(vpd);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
playQueue();
|
||||
return lst;
|
||||
}
|
||||
|
|
|
@ -123,14 +123,17 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
||||
.build());
|
||||
}
|
||||
// Delay first prompt of each batch to allow BT SCO connection being established
|
||||
if (ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode()) == 0) {
|
||||
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
|
||||
if (ctx != null) {
|
||||
int vpd = ctx.getSettings().VOICE_PROMPT_DELAY[ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode())].get();
|
||||
if (vpd > 0) {
|
||||
ttsRequests++;
|
||||
if (android.os.Build.VERSION.SDK_INT < 21) {
|
||||
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
|
||||
mTts.playSilence(ctx.getSettings().BT_SCO_DELAY.get(), TextToSpeech.QUEUE_ADD, params);
|
||||
mTts.playSilence(vpd, TextToSpeech.QUEUE_ADD, params);
|
||||
} else {
|
||||
mTts.playSilentUtterance(ctx.getSettings().BT_SCO_DELAY.get(), TextToSpeech.QUEUE_ADD, ""+System.currentTimeMillis());
|
||||
mTts.playSilentUtterance(vpd, TextToSpeech.QUEUE_ADD, ""+System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue