mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-12 16:58:52 +00:00
VoiceSettings.java: Support reading the espeak_pitch_range preference.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user