VoiceSettings.java: Support setting an espeak_punctuation_characters preference.

This commit is contained in:
Reece H. Dunn
2013-09-04 21:41:35 +01:00
parent 622e6043ef
commit bc346db22e
2 changed files with 38 additions and 0 deletions
@@ -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()));
}
}
@@ -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) {