From bc346db22efed7f2378eb16ed91f7aaf05982799 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Wed, 4 Sep 2013 21:41:35 +0100 Subject: [PATCH] VoiceSettings.java: Support setting an espeak_punctuation_characters preference. --- .../espeak/test/VoiceSettingsTest.java | 33 +++++++++++++++++++ .../com/reecedunn/espeak/VoiceSettings.java | 5 +++ 2 files changed, 38 insertions(+) diff --git a/android/eSpeakTests/src/com/reecedunn/espeak/test/VoiceSettingsTest.java b/android/eSpeakTests/src/com/reecedunn/espeak/test/VoiceSettingsTest.java index 312071b3..13b510e9 100644 --- a/android/eSpeakTests/src/com/reecedunn/espeak/test/VoiceSettingsTest.java +++ b/android/eSpeakTests/src/com/reecedunn/espeak/test/VoiceSettingsTest.java @@ -57,6 +57,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } // Old Settings @@ -77,6 +78,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testDefaultGenderFemale() @@ -95,6 +97,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth) @@ -112,6 +115,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testDefaultRate() @@ -139,6 +143,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testDefaultPitch() @@ -170,6 +175,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth) @@ -187,6 +193,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testEspeakRate() @@ -215,6 +222,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testEspeakPitch() @@ -242,6 +250,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(settingValue)); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testEspeakPitchRange() @@ -269,6 +278,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(settingValue)); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testEspeakVolume() @@ -296,6 +306,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(settingValue)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testEspeakPunctuationLevel() @@ -308,6 +319,25 @@ public class VoiceSettingsTest extends TextToSpeechTestCase espeakPunctuationLevelTest(-1, SpeechSynthesis.PUNCT_NONE, synth); // clamped to minimum value } + public void testEspeakPunctuationCharacters() + { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + SharedPreferences.Editor editor = prefs.edit(); + editor.clear(); + editor.putString("espeak_punctuation_characters", ".?!"); + editor.commit(); + + SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); + VoiceSettings settings = new VoiceSettings(prefs, synth); + assertThat(settings.getVoiceVariant().toString(), is("male")); + assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); + assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); + assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); + assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); + assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(".?!")); + } + // Mixed (Old and New) Settings public void testEspeakVariantWithDefaultGenderFemale() @@ -327,6 +357,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testEspeakRateWithDefaultRate() @@ -346,6 +377,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } public void testEspeakPitchWithDefaultPitch() @@ -365,5 +397,6 @@ public class VoiceSettingsTest extends TextToSpeechTestCase assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE)); + assertThat(settings.getPunctuationCharacters(), is(nullValue())); } } diff --git a/android/src/com/reecedunn/espeak/VoiceSettings.java b/android/src/com/reecedunn/espeak/VoiceSettings.java index eaeb9312..f70092d1 100644 --- a/android/src/com/reecedunn/espeak/VoiceSettings.java +++ b/android/src/com/reecedunn/espeak/VoiceSettings.java @@ -31,6 +31,7 @@ public class VoiceSettings { public static final String PREF_PITCH_RANGE = "espeak_pitch_range"; public static final String PREF_VOLUME = "espeak_volume"; public static final String PREF_PUNCTUATION_LEVEL = "espeak_punctuation_level"; + public static final String PREF_PUNCTUATION_CHARACTERS = "espeak_punctuation_characters"; public VoiceSettings(SharedPreferences preferences, SpeechSynthesis engine) { mPreferences = preferences; @@ -107,6 +108,10 @@ public class VoiceSettings { return level; } + public String getPunctuationCharacters() { + return mPreferences.getString(PREF_PUNCTUATION_CHARACTERS, null); + } + private int getPreferenceValue(String preference, int defaultValue) { String prefString = mPreferences.getString(preference, null); if (prefString == null) {