VoiceSettings.java: Support reading the default_pitch and espeak_pitch preferences.

This commit is contained in:
Reece H. Dunn
2013-09-04 17:17:11 +01:00
parent 54ccfc39b4
commit f47729453f
2 changed files with 73 additions and 0 deletions
@@ -53,6 +53,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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()));
}
// Old Settings
@@ -69,6 +70,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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()));
}
public void testDefaultGenderFemale()
@@ -83,6 +85,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
VoiceSettings settings = new VoiceSettings(prefs, synth);
assertThat(settings.getVoiceVariant().toString(), is("female"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
}
public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
@@ -96,6 +99,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
VoiceSettings settings = new VoiceSettings(prefs, synth);
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(settingValue));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
}
public void testDefaultRate()
@@ -108,6 +112,31 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
defaultRateTest( 25, 80, synth); // clamped to minimum value
}
public void defaultPitchTest(int prefValue, int settingValue, SpeechSynthesis synth)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = prefs.edit();
editor.clear();
editor.putString("default_pitch", 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(settingValue));
}
public void testDefaultPitch()
{
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
defaultPitchTest(250, 100, synth); // clamped to maximum value
defaultPitchTest(200, 100, synth);
defaultPitchTest(100, 50, synth); // default value
defaultPitchTest( 50, 25, synth);
defaultPitchTest( 0, 0, synth);
defaultPitchTest( -5, 0, synth); // clamped to minimum value
}
// New Settings
public void testEspeakVariant()
@@ -122,6 +151,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
VoiceSettings settings = new VoiceSettings(prefs, synth);
assertThat(settings.getVoiceVariant().toString(), is("klatt2-old"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
}
public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
@@ -135,6 +165,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
VoiceSettings settings = new VoiceSettings(prefs, synth);
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(settingValue));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
}
public void testEspeakRate()
@@ -148,6 +179,30 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
espeakRateTest( 70, 80, synth); // clamped to minimum value
}
public void espeakPitchTest(int prefValue, int settingValue, SpeechSynthesis synth)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = prefs.edit();
editor.clear();
editor.putString("espeak_pitch", 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(settingValue));
}
public void testEspeakPitch()
{
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
espeakPitchTest(110, 100, synth); // clamped to maximum value
espeakPitchTest(100, 100, synth);
espeakPitchTest( 50, 50, synth); // default value
espeakPitchTest( 10, 10, synth);
espeakPitchTest( -5, 0, synth); // clamped to minimum value
}
// Mixed (Old and New) Settings
public void testEspeakVariantWithDefaultGenderFemale()
@@ -163,6 +218,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
VoiceSettings settings = new VoiceSettings(prefs, synth);
assertThat(settings.getVoiceVariant().toString(), is("klatt4"));
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
}
public void testEspeakRateWithDefaultRate()
@@ -178,5 +234,6 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
VoiceSettings settings = new VoiceSettings(prefs, synth);
assertThat(settings.getVoiceVariant().toString(), is("male"));
assertThat(settings.getRate(), is(200));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
}
}