diff --git a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java index 59964ea98..029ad551a 100644 --- a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java +++ b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncement.java @@ -142,6 +142,36 @@ public void start() { } } + public void announceatTheEndOfTrack(){ + synchronized (this) { + if (!ttsReady) { + ttsReady = ttsInitStatus == TextToSpeech.SUCCESS; + if (ttsReady) { + onTtsReady(); + } + } + } + + if (Arrays.asList(AudioManager.MODE_IN_CALL, AudioManager.MODE_IN_COMMUNICATION) + .contains(audioManager.getMode())) { + Log.i(TAG, "Announcement is not allowed at this time."); + return; + } + + if (!ttsReady) { + if (ttsFallback == null) { + Log.w(TAG, "MediaPlayer for ttsFallback was not created."); + } else { + Log.i(TAG, "TTS not ready/available, just generating a tone."); + ttsFallback.seekTo(0); + ttsFallback.start(); + } + return; + } + + Spannable announcement = VoiceAnnouncementUtils.atTheEndAnnounce(); + tts.speak(announcement, TextToSpeech.QUEUE_FLUSH, null, "not used"); + } public void announceMotivation(){ synchronized (this) { if (!ttsReady) { diff --git a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java index 5bd10d7b9..8c1878055 100644 --- a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java +++ b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementManager.java @@ -104,7 +104,6 @@ public void update(@NonNull Context context, @NonNull Track track) { updateNextDuration(); announce = true; } - if (announce) { Random random = new Random(); float p = random.nextFloat(); @@ -120,6 +119,7 @@ public void update(@NonNull Context context, @NonNull Track track) { public void stop() { + voiceAnnouncement.announceatTheEndOfTrack(); if (voiceAnnouncement != null) { voiceAnnouncement.stop(); voiceAnnouncement = null; diff --git a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java index 5a5835c2e..e5a146fbf 100644 --- a/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java +++ b/src/main/java/de/dennisguse/opentracks/services/announcement/VoiceAnnouncementUtils.java @@ -167,6 +167,13 @@ static Spannable getAnnouncement(Context context, TrackStatistics trackStatistic return builder; } + static Spannable atTheEndAnnounce(){ + String ma="Your session as ended.Remember! Consistency is the key to success"; + SpannableStringBuilder motivator = new SpannableStringBuilder(); + return (motivator.append(ma)); + } + + static Spannable getMotivationalAnnouncements(){ MotivationalAnnouncements ma = new MotivationalAnnouncements(); Random random = new Random();