diff options
| author | campbeb <bpcampbell@gmail.com> | 2013-05-12 16:27:12 -1000 |
|---|---|---|
| committer | campbeb <bpcampbell@gmail.com> | 2013-05-20 22:57:28 -1000 |
| commit | 14da20f40a327e71842bcb32c3ff8123bf6058b9 (patch) | |
| tree | f981e0ce623a009e2fec9a0f8a4f5af1ceaec6af /main | |
| parent | 42a3f52232d6e85aecf65671d5e3452860f7b155 (diff) | |
| download | cgeo-14da20f40a327e71842bcb32c3ff8123bf6058b9.zip cgeo-14da20f40a327e71842bcb32c3ff8123bf6058b9.tar.gz cgeo-14da20f40a327e71842bcb32c3ff8123bf6058b9.tar.bz2 | |
Fix #2716 - Adjust compass speech rate based on distance
Speech has a minimum and maximum time delay. In between these values
it changes based on how much distance to the object has changed.
Values may need to be adjusted for optimum use.
Diffstat (limited to 'main')
| -rw-r--r-- | main/src/cgeo/geocaching/speech/SpeechService.java | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/speech/SpeechService.java b/main/src/cgeo/geocaching/speech/SpeechService.java index 0a367f8..7226014 100644 --- a/main/src/cgeo/geocaching/speech/SpeechService.java +++ b/main/src/cgeo/geocaching/speech/SpeechService.java @@ -22,7 +22,8 @@ import java.util.Locale; */ public class SpeechService extends Service implements OnInitListener { - private static final int SPEECH_PAUSE_SECONDS = 30; + private static final int SPEECH_MINPAUSE_SECONDS = 5; + private static final int SPEECH_MAXPAUSE_SECONDS = 30; private static final String EXTRA_TARGET_COORDS = "target"; private static Activity startingActivity; private static boolean isRunning = false; @@ -62,6 +63,7 @@ public class SpeechService extends Service implements OnInitListener { * remember when we talked the last time */ private long lastSpeechTime = 0; + private float lastSpeechDistance = 0.0f; private Geopoint target; @Override @@ -76,17 +78,44 @@ public class SpeechService extends Service implements OnInitListener { } // avoid any calculation, if the delay since the last output is not long enough - long now = System.currentTimeMillis(); - if (now - lastSpeechTime <= SPEECH_PAUSE_SECONDS * 1000) { + final long now = System.currentTimeMillis(); + if (now - lastSpeechTime <= SPEECH_MINPAUSE_SECONDS * 1000) { return; } + // to speak, we want max pause to have elapsed or distance to geopoint to have changed by a given amount + final float distance = position.distanceTo(target); + if (now - lastSpeechTime <= SPEECH_MAXPAUSE_SECONDS * 1000) { + if (Math.abs(lastSpeechDistance - distance) < getDeltaForDistance(distance)) { + return; + } + } + final String text = TextFactory.getText(position, target, direction); if (StringUtils.isNotEmpty(text)) { + lastSpeechTime = System.currentTimeMillis(); + lastSpeechDistance = distance; speak(text); } } + /** + * Return distance required to be moved based on overall distance.<br> + * + * @param distance + * in km + * @return delta in km + */ + private static float getDeltaForDistance(final float distance) { + if (distance > 1.0) { + return 0.2f; + } else if (distance > 0.05) { + return distance / 5.0f; + } + + return 0f; + } + @Override public void onCreate() { super.onCreate(); @@ -136,7 +165,6 @@ public class SpeechService extends Service implements OnInitListener { if (!initialized) { return; } - lastSpeechTime = System.currentTimeMillis(); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); } |
