From da6e3e23000a48d128ec519603d53aac1a99598c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Thu, 9 Sep 2021 00:12:16 +0200 Subject: [PATCH 1/3] #58 Add a pause between each paragraph --- .../vitabu/ui/storybook/ChapterFragment.java | 22 ++++++++++--------- .../vitabu/ui/storybook/CoverFragment.java | 22 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java index 0606e67..23513a8 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java @@ -6,7 +6,6 @@ import android.os.Environment; import android.speech.tts.TextToSpeech; import android.speech.tts.UtteranceProgressListener; -import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -58,9 +57,11 @@ public class ChapterFragment extends Fragment implements AudioListener { final static String PICTURES_PATH = FILES_PATH + Environment.DIRECTORY_PICTURES + "/"; final static String MUSIC_PATH = FILES_PATH + Environment.DIRECTORY_MUSIC + "/"; + private final static long PARAGRAPH_PAUSE = 1000; + private StoryBookChapterGson storyBookChapter; - protected String chapterText = ""; + protected String[] chapterText = {}; private RecyclerView chapterRecyclerView; @@ -159,6 +160,7 @@ public void onItemClick(WordGson wordWithAudio, View view, int position) { chapterRecyclerView.setAdapter(wordViewAdapter); } + chapterText = new String[storyBookParagraphGsons.size()]; for (int paragraphIndex = 0; paragraphIndex < storyBookParagraphGsons.size(); paragraphIndex++) { Log.i(getClass().getName(), "storyBookParagraphGson.getOriginalText(): \"" + storyBookParagraphGsons.get(paragraphIndex).getOriginalText() + "\""); @@ -167,10 +169,7 @@ public void onItemClick(WordGson wordWithAudio, View view, int position) { Log.i(getClass().getName(), "wordsInOriginalText.length: " + wordsInOriginalText.length); Log.i(getClass().getName(), "Arrays.toString(wordsInOriginalText): " + Arrays.toString(wordsInOriginalText)); - if (!TextUtils.isEmpty(chapterText)) { - chapterText += "\n\n"; - } - chapterText += originalText; + chapterText[paragraphIndex] = originalText; List wordAudios = storyBookParagraphGsons.get(paragraphIndex).getWords(); Log.i(getClass().getName(), "words: " + wordAudios); @@ -189,7 +188,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); // Add button for initializing Text-to-Speech (TTS) - final String finalChapterText = chapterText; + final String[] finalChapterText = chapterText; FloatingActionButton fab = view.findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override @@ -200,7 +199,7 @@ public void onClick(View view) { }); } - public void playAudio(final String chapterText, final AudioListener audioListener) { + public void playAudio(final String[] chapterText, final AudioListener audioListener) { List storyBookParagraphs = storyBookChapter.getStoryBookParagraphs(); StoryBookParagraphGson storyBookParagraphGson = storyBookParagraphs.get(0); String transcription = storyBookParagraphGson.getOriginalText(); @@ -213,8 +212,11 @@ public void playAudio(final String chapterText, final AudioListener audioListene // Fall back to TTS tts.setOnUtteranceProgressListener(getUtteranceProgressListener(audioListener)); - Log.i(getClass().getName(), "chapterText: \"" + chapterText + "\""); - tts.speak(chapterText.replaceAll("[-*]", ""), TextToSpeech.QUEUE_FLUSH, null, "0"); + Log.i(getClass().getName(), "chapterText: \"" + Arrays.toString(chapterText) + "\""); + for (String paragraph : chapterText) { + tts.speak(paragraph.replaceAll("[-*]", ""), TextToSpeech.QUEUE_ADD, null, "0"); + tts.playSilentUtterance(PARAGRAPH_PAUSE, TextToSpeech.QUEUE_ADD, null); + } } } diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java index b10e76e..4287608 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java @@ -30,7 +30,7 @@ public class CoverFragment extends ChapterFragment { protected TextView titleTextView; private TextView descriptionTextView; - private String description; + private final String[] description = new String[1]; public static CoverFragment newInstance(ReadingLevel readingLevel, String description) { CoverFragment fragment = new CoverFragment(); @@ -54,20 +54,22 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, int[] titleFontSize = getResources().getIntArray(R.array.cover_title_font_size); int[] descriptionFontSize = getResources().getIntArray(R.array.chapter_text_font_size); - chapterText = setWordSpacing(chapterText); + for (int i=0; i { - titleTextView.setText(chapterText); - descriptionTextView.setText(description); + titleTextView.setText(TextUtils.join("", chapterText)); + descriptionTextView.setText(description[0]); }); - audioText = chapterText; + audioText = TextUtils.join("", chapterText); audioTextView = titleTextView; } }; From f70bb565b1d941e21b21be082e03f4e72915c978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Fri, 10 Sep 2021 01:46:46 +0200 Subject: [PATCH 2/3] #58 Rename variables --- .../elimu/vitabu/ui/storybook/ChapterFragment.java | 10 +++++----- .../ai/elimu/vitabu/ui/storybook/CoverFragment.java | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java index 23513a8..78ed9fa 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java @@ -61,7 +61,7 @@ public class ChapterFragment extends Fragment implements AudioListener { private StoryBookChapterGson storyBookChapter; - protected String[] chapterText = {}; + protected String[] chapterParagraph = {}; private RecyclerView chapterRecyclerView; @@ -160,7 +160,7 @@ public void onItemClick(WordGson wordWithAudio, View view, int position) { chapterRecyclerView.setAdapter(wordViewAdapter); } - chapterText = new String[storyBookParagraphGsons.size()]; + chapterParagraph = new String[storyBookParagraphGsons.size()]; for (int paragraphIndex = 0; paragraphIndex < storyBookParagraphGsons.size(); paragraphIndex++) { Log.i(getClass().getName(), "storyBookParagraphGson.getOriginalText(): \"" + storyBookParagraphGsons.get(paragraphIndex).getOriginalText() + "\""); @@ -169,7 +169,7 @@ public void onItemClick(WordGson wordWithAudio, View view, int position) { Log.i(getClass().getName(), "wordsInOriginalText.length: " + wordsInOriginalText.length); Log.i(getClass().getName(), "Arrays.toString(wordsInOriginalText): " + Arrays.toString(wordsInOriginalText)); - chapterText[paragraphIndex] = originalText; + chapterParagraph[paragraphIndex] = originalText; List wordAudios = storyBookParagraphGsons.get(paragraphIndex).getWords(); Log.i(getClass().getName(), "words: " + wordAudios); @@ -188,13 +188,13 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); // Add button for initializing Text-to-Speech (TTS) - final String[] finalChapterText = chapterText; + final String[] chapterText = chapterParagraph; FloatingActionButton fab = view.findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.i(getClass().getName(), "onClick"); - playAudio(finalChapterText, ChapterFragment.this); + playAudio(chapterText, ChapterFragment.this); } }); } diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java index 4287608..a5c3a60 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java @@ -54,19 +54,19 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, int[] titleFontSize = getResources().getIntArray(R.array.cover_title_font_size); int[] descriptionFontSize = getResources().getIntArray(R.array.chapter_text_font_size); - for (int i=0; i { - titleTextView.setText(TextUtils.join("", chapterText)); + titleTextView.setText(TextUtils.join("", chapterParagraph)); descriptionTextView.setText(description[0]); }); - audioText = TextUtils.join("", chapterText); + audioText = TextUtils.join("", chapterParagraph); audioTextView = titleTextView; } }; From 103f3eda4fbefc10766edc3934a43f00ee46b5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Tue, 14 Sep 2021 23:58:24 +0200 Subject: [PATCH 3/3] #58 rename chapterParagraph variable to plural --- .../elimu/vitabu/ui/storybook/ChapterFragment.java | 8 ++++---- .../ai/elimu/vitabu/ui/storybook/CoverFragment.java | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java index 78ed9fa..69a8650 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java @@ -61,7 +61,7 @@ public class ChapterFragment extends Fragment implements AudioListener { private StoryBookChapterGson storyBookChapter; - protected String[] chapterParagraph = {}; + protected String[] chapterParagraphs = {}; private RecyclerView chapterRecyclerView; @@ -160,7 +160,7 @@ public void onItemClick(WordGson wordWithAudio, View view, int position) { chapterRecyclerView.setAdapter(wordViewAdapter); } - chapterParagraph = new String[storyBookParagraphGsons.size()]; + chapterParagraphs = new String[storyBookParagraphGsons.size()]; for (int paragraphIndex = 0; paragraphIndex < storyBookParagraphGsons.size(); paragraphIndex++) { Log.i(getClass().getName(), "storyBookParagraphGson.getOriginalText(): \"" + storyBookParagraphGsons.get(paragraphIndex).getOriginalText() + "\""); @@ -169,7 +169,7 @@ public void onItemClick(WordGson wordWithAudio, View view, int position) { Log.i(getClass().getName(), "wordsInOriginalText.length: " + wordsInOriginalText.length); Log.i(getClass().getName(), "Arrays.toString(wordsInOriginalText): " + Arrays.toString(wordsInOriginalText)); - chapterParagraph[paragraphIndex] = originalText; + chapterParagraphs[paragraphIndex] = originalText; List wordAudios = storyBookParagraphGsons.get(paragraphIndex).getWords(); Log.i(getClass().getName(), "words: " + wordAudios); @@ -188,7 +188,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); // Add button for initializing Text-to-Speech (TTS) - final String[] chapterText = chapterParagraph; + final String[] chapterText = chapterParagraphs; FloatingActionButton fab = view.findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java index a5c3a60..6d179f0 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java @@ -54,19 +54,19 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, int[] titleFontSize = getResources().getIntArray(R.array.cover_title_font_size); int[] descriptionFontSize = getResources().getIntArray(R.array.chapter_text_font_size); - for (int i=0; i { - titleTextView.setText(TextUtils.join("", chapterParagraph)); + titleTextView.setText(TextUtils.join("", chapterParagraphs)); descriptionTextView.setText(description[0]); }); - audioText = TextUtils.join("", chapterParagraph); + audioText = TextUtils.join("", chapterParagraphs); audioTextView = titleTextView; } };