Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #303 from rilling/Group4Motivation
Browse files Browse the repository at this point in the history
Feature for providing motivational voice announcement to the user.
  • Loading branch information
SivaNagireddy97 authored Nov 27, 2023
2 parents f6ee7bb + fd4bad0 commit f22dbcc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f22dbcc

Please sign in to comment.