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

@@ -56,6 +56,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

// Old Settings
@@ -75,6 +76,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

public void testDefaultGenderFemale()
@@ -92,6 +94,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
@@ -108,6 +111,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

public void testDefaultRate()
@@ -134,6 +138,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getPitch(), is(settingValue));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
}

public void testDefaultPitch()
@@ -164,6 +169,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
@@ -180,6 +186,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

public void testEspeakRate()
@@ -207,6 +214,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getPitch(), is(settingValue));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
}

public void testEspeakPitch()
@@ -233,6 +241,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(settingValue));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
}

public void testEspeakPitchRange()
@@ -259,6 +268,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(settingValue));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
}

public void testEspeakVolume()
@@ -271,6 +281,33 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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

public void testEspeakVariantWithDefaultGenderFemale()
@@ -289,6 +326,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

public void testEspeakRateWithDefaultRate()
@@ -307,6 +345,7 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
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(SpeechSynthesis.PUNCT_NONE));
}

public void testEspeakPitchWithDefaultPitch()
@@ -325,5 +364,6 @@ public class VoiceSettingsTest extends TextToSpeechTestCase
assertThat(settings.getPitch(), is(75));
assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
}
}

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

@@ -5,7 +5,7 @@
Description: The name of the application.
-->
<string name="app_name" translatable="false">eSpeak</string>
<string-array name="default_variant_values">
<item>male</item>
<item>m1</item>
@@ -34,4 +34,10 @@
<item>female-old</item>
</string-array>

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

</resources>

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

@@ -111,4 +111,14 @@
<string name="resetToDefault">Set to default</string>
<string name="espeak_pitch_range">Pitch variation</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>

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

@@ -9,4 +9,12 @@
android:summary="%s"
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>

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

@@ -240,6 +240,7 @@ public class TtsService extends TextToSpeechService {
mEngine.Pitch.setValue(settings.getPitch(), request.getPitch());
mEngine.PitchRange.setValue(settings.getPitchRange());
mEngine.Volume.setValue(settings.getVolume());
mEngine.Punctuation.setValue(settings.getPunctuationLevel());
mEngine.synthesize(text, text.startsWith("<speak"));
}


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

@@ -30,6 +30,7 @@ public class VoiceSettings {
public static final String PREF_PITCH = "espeak_pitch";
public static final String PREF_PITCH_RANGE = "espeak_pitch_range";
public static final String PREF_VOLUME = "espeak_volume";
public static final String PREF_PUNCTUATION_LEVEL = "espeak_punctuation_level";

public VoiceSettings(SharedPreferences preferences, SpeechSynthesis engine) {
mPreferences = preferences;
@@ -96,6 +97,16 @@ public class VoiceSettings {
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) {
String prefString = mPreferences.getString(preference, null);
if (prefString == null) {

Loading…
Cancel
Save