Browse Source

VoiceSettings.java: Support reading the espeak_volume preference.

master
Reece H. Dunn 12 years ago
parent
commit
0086ec61c3

+ 37
- 0
android/eSpeakTests/src/com/reecedunn/espeak/test/VoiceSettingsTest.java View File

assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


// Old Settings // Old Settings
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void testDefaultGenderFemale() public void testDefaultGenderFemale()
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth) public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
assertThat(settings.getRate(), is(settingValue)); assertThat(settings.getRate(), is(settingValue));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void testDefaultRate() public void testDefaultRate()
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(settingValue)); assertThat(settings.getPitch(), is(settingValue));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void testDefaultPitch() public void testDefaultPitch()
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth) public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
assertThat(settings.getRate(), is(settingValue)); assertThat(settings.getRate(), is(settingValue));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void testEspeakRate() public void testEspeakRate()
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(settingValue)); assertThat(settings.getPitch(), is(settingValue));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void testEspeakPitch() public void testEspeakPitch()
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(settingValue)); assertThat(settings.getPitchRange(), is(settingValue));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void testEspeakPitchRange() public void testEspeakPitchRange()
espeakPitchRangeTest( -5, 0, synth); // clamped to minimum value espeakPitchRangeTest( -5, 0, synth); // clamped to minimum value
} }


public void espeakVolumeTest(int prefValue, int settingValue, SpeechSynthesis synth)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = prefs.edit();
editor.clear();
editor.putString("espeak_volume", 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(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(settingValue));
}

public void testEspeakVolume()
{
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
espeakVolumeTest(210, 200, synth); // clamped to maximum value
espeakVolumeTest(150, 150, synth);
espeakVolumeTest(100, 100, synth); // default value
espeakVolumeTest( 50, 50, synth);
espeakVolumeTest( -5, 0, synth); // clamped to minimum value
}

// Mixed (Old and New) Settings // Mixed (Old and New) Settings


public void testEspeakVariantWithDefaultGenderFemale() public void testEspeakVariantWithDefaultGenderFemale()
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }


public void testEspeakRateWithDefaultRate() public void testEspeakRateWithDefaultRate()
assertThat(settings.getRate(), is(200)); assertThat(settings.getRate(), is(200));
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue())); assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
} }
} }

+ 11
- 0
android/src/com/reecedunn/espeak/VoiceSettings.java View File

public static final String PREF_DEFAULT_PITCH = "default_pitch"; public static final String PREF_DEFAULT_PITCH = "default_pitch";
public static final String PREF_PITCH = "espeak_pitch"; public static final String PREF_PITCH = "espeak_pitch";
public static final String PREF_PITCH_RANGE = "espeak_pitch_range"; public static final String PREF_PITCH_RANGE = "espeak_pitch_range";
public static final String PREF_VOLUME = "espeak_volume";


public VoiceSettings(SharedPreferences preferences, SpeechSynthesis engine) { public VoiceSettings(SharedPreferences preferences, SpeechSynthesis engine) {
mPreferences = preferences; mPreferences = preferences;
return range; return range;
} }


public int getVolume() {
int min = mEngine.Volume.getMinValue();
int max = mEngine.Volume.getMaxValue();

int range = getPreferenceValue(PREF_VOLUME, mEngine.Volume.getDefaultValue());
if (range > max) range = max;
if (range < min) range = min;
return range;
}

private int getPreferenceValue(String preference, int defaultValue) { private int getPreferenceValue(String preference, int defaultValue) {
String prefString = mPreferences.getString(preference, null); String prefString = mPreferences.getString(preference, null);
if (prefString == null) { if (prefString == null) {

Loading…
Cancel
Save