Browse Source

Expose the Punctuation Level setting.

master
Reece H. Dunn 12 years ago
parent
commit
622e6043ef

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

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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


// Old Settings // Old Settings
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testDefaultGenderFemale() public void testDefaultGenderFemale()
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth) public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testDefaultRate() public void testDefaultRate()
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testDefaultPitch() public void testDefaultPitch()
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth) public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testEspeakRate() public void testEspeakRate()
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testEspeakPitch() public void testEspeakPitch()
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testEspeakPitchRange() public void testEspeakPitchRange()
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(settingValue)); assertThat(settings.getVolume(), is(settingValue));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


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


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

public void testEspeakPunctuationLevel()
{
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
espeakPunctuationLevelTest( 3, SpeechSynthesis.PUNCT_SOME, synth); // clamped to maximum value
espeakPunctuationLevelTest( 2, SpeechSynthesis.PUNCT_SOME, synth);
espeakPunctuationLevelTest( 1, SpeechSynthesis.PUNCT_ALL, synth);
espeakPunctuationLevelTest( 0, SpeechSynthesis.PUNCT_NONE, synth);
espeakPunctuationLevelTest(-1, SpeechSynthesis.PUNCT_NONE, synth); // clamped to minimum value
}

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


public void testEspeakVariantWithDefaultGenderFemale() public void testEspeakVariantWithDefaultGenderFemale()
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testEspeakRateWithDefaultRate() public void testEspeakRateWithDefaultRate()
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())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }


public void testEspeakPitchWithDefaultPitch() public void testEspeakPitchWithDefaultPitch()
assertThat(settings.getPitch(), is(75)); assertThat(settings.getPitch(), is(75));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue())); assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue())); assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
} }
} }

+ 7
- 1
android/res/values/donottranslate.xml View File

Description: The name of the application. Description: The name of the application.
--> -->
<string name="app_name" translatable="false">eSpeak</string> <string name="app_name" translatable="false">eSpeak</string>
<string-array name="default_variant_values"> <string-array name="default_variant_values">
<item>male</item> <item>male</item>
<item>m1</item> <item>m1</item>
<item>female-old</item> <item>female-old</item>
</string-array> </string-array>


<string-array name="punctuation_level_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>

</resources> </resources>

+ 10
- 0
android/res/values/strings.xml View File

<string name="resetToDefault">Set to default</string> <string name="resetToDefault">Set to default</string>
<string name="espeak_pitch_range">Pitch variation</string> <string name="espeak_pitch_range">Pitch variation</string>
<string name="espeak_variant">Voice variant</string> <string name="espeak_variant">Voice variant</string>
<string name="espeak_punctuation_level">Punctuation level</string>
<!--
Source: Punctuation level preference labels.
Description: Labels for possible punctuation level values.
-->
<string-array name="punctuation_level_entries">
<item>None</item>
<item>All</item>
<item>Some</item>
</string-array>
</resources> </resources>

+ 8
- 0
android/res/xml/preferences.xml View File

android:summary="%s" android:summary="%s"
android:title="@string/espeak_variant" /> android:title="@string/espeak_variant" />


<ListPreference
android:defaultValue="0"
android:entries="@array/punctuation_level_entries"
android:entryValues="@array/punctuation_level_values"
android:key="espeak_punctuation_level"
android:summary="%s"
android:title="@string/espeak_punctuation_level" />

</PreferenceScreen> </PreferenceScreen>

+ 1
- 0
android/src/com/reecedunn/espeak/TtsService.java View File

mEngine.Pitch.setValue(settings.getPitch(), request.getPitch()); mEngine.Pitch.setValue(settings.getPitch(), request.getPitch());
mEngine.PitchRange.setValue(settings.getPitchRange()); mEngine.PitchRange.setValue(settings.getPitchRange());
mEngine.Volume.setValue(settings.getVolume()); mEngine.Volume.setValue(settings.getVolume());
mEngine.Punctuation.setValue(settings.getPunctuationLevel());
mEngine.synthesize(text, text.startsWith("<speak")); mEngine.synthesize(text, text.startsWith("<speak"));
} }



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

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 static final String PREF_VOLUME = "espeak_volume";
public static final String PREF_PUNCTUATION_LEVEL = "espeak_punctuation_level";


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


public int getPunctuationLevel() {
int min = mEngine.Punctuation.getMinValue();
int max = mEngine.Punctuation.getMaxValue();

int level = getPreferenceValue(PREF_PUNCTUATION_LEVEL, mEngine.Punctuation.getDefaultValue());
if (level > max) level = max;
if (level < min) level = min;
return level;
}

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