VoiceSettings.java: Support reading the espeak_pitch_range preference.

This commit is contained in:
Reece H. Dunn
2013-09-04 17:39:08 +01:00
parent f47729453f
commit f1588b3770
2 changed files with 46 additions and 0 deletions
@@ -54,6 +54,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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()));
}
// Old Settings
@@ -71,6 +72,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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()));
}
public void testDefaultGenderFemale()
@@ -86,6 +88,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("female"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
@@ -100,6 +103,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(settingValue));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
public void testDefaultRate()
@@ -124,6 +128,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(settingValue));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
public void testDefaultPitch()
@@ -152,6 +157,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("klatt2-old"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
@@ -166,6 +172,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(settingValue));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
public void testEspeakRate()
@@ -191,6 +198,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(settingValue));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
public void testEspeakPitch()
@@ -203,6 +211,31 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
espeakPitchTest( -5, 0, synth); // clamped to minimum value
}
public void espeakPitchRangeTest(int prefValue, int settingValue, SpeechSynthesis synth)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = prefs.edit();
editor.clear();
editor.putString("espeak_pitch_range", Integer.toString(prefValue));
editor.commit();
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(settingValue));
}
public void testEspeakPitchRange()
{
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
espeakPitchRangeTest(110, 100, synth); // clamped to maximum value
espeakPitchRangeTest(100, 100, synth);
espeakPitchRangeTest( 50, 50, synth); // default value
espeakPitchRangeTest( 10, 10, synth);
espeakPitchRangeTest( -5, 0, synth); // clamped to minimum value
}
// Mixed (Old and New) Settings
public void testEspeakVariantWithDefaultGenderFemale()
@@ -219,6 +252,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("klatt4"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
public void testEspeakRateWithDefaultRate()
@@ -235,5 +269,6 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(200));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
}
}
@@ -28,6 +28,7 @@ public class VoiceSettings {
public static final String PREF_RATE = "espeak_rate";
public static final String PREF_DEFAULT_PITCH = "default_pitch";
public static final String PREF_PITCH = "espeak_pitch";
public static final String PREF_PITCH_RANGE = "espeak_pitch_range";
public VoiceSettings(SharedPreferences preferences, SpeechSynthesis engine) {
mPreferences = preferences;
@@ -74,6 +75,16 @@ public class VoiceSettings {
return pitch;
}
public int getPitchRange() {
int min = mEngine.PitchRange.getMinValue();
int max = mEngine.PitchRange.getMaxValue();
int range = getPreferenceValue(PREF_PITCH_RANGE, mEngine.PitchRange.getDefaultValue());
if (range > max) range = max;
if (range < min) range = min;
return range;
}
private int getPreferenceValue(String preference, int defaultValue) {
String prefString = mPreferences.getString(preference, null);
if (prefString == null) {