|
|
@@ -18,7 +18,6 @@ package com.reecedunn.espeak.test; |
|
|
|
|
|
|
|
import android.content.SharedPreferences; |
|
|
|
import android.preference.PreferenceManager; |
|
|
|
import android.test.AndroidTestCase; |
|
|
|
|
|
|
|
import com.reecedunn.espeak.SpeechSynthesis; |
|
|
|
import com.reecedunn.espeak.VoiceSettings; |
|
|
@@ -26,8 +25,21 @@ import com.reecedunn.espeak.VoiceSettings; |
|
|
|
import static org.hamcrest.MatcherAssert.assertThat; |
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
|
|
|
|
public class VoiceSettingsTest extends AndroidTestCase |
|
|
|
public class VoiceSettingsTest extends TextToSpeechTestCase |
|
|
|
{ |
|
|
|
private SpeechSynthesis.SynthReadyCallback mCallback = new SpeechSynthesis.SynthReadyCallback() |
|
|
|
{ |
|
|
|
@Override |
|
|
|
public void onSynthDataReady(byte[] audioData) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSynthDataComplete() |
|
|
|
{ |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// No Settings (New Install) |
|
|
|
|
|
|
|
public void testNoPreferences() |
|
|
@@ -37,8 +49,10 @@ public class VoiceSettingsTest extends AndroidTestCase |
|
|
|
editor.clear(); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
VoiceSettings settings = new VoiceSettings(prefs); |
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("male")); |
|
|
|
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); |
|
|
|
} |
|
|
|
|
|
|
|
// Old Settings |
|
|
@@ -51,8 +65,10 @@ public class VoiceSettingsTest extends AndroidTestCase |
|
|
|
editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_MALE)); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
VoiceSettings settings = new VoiceSettings(prefs); |
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("male")); |
|
|
|
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); |
|
|
|
} |
|
|
|
|
|
|
|
public void testDefaultGenderFemale() |
|
|
@@ -63,8 +79,33 @@ public class VoiceSettingsTest extends AndroidTestCase |
|
|
|
editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_FEMALE)); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
VoiceSettings settings = new VoiceSettings(prefs); |
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("female")); |
|
|
|
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); |
|
|
|
} |
|
|
|
|
|
|
|
public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth) |
|
|
|
{ |
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
|
SharedPreferences.Editor editor = prefs.edit(); |
|
|
|
editor.clear(); |
|
|
|
editor.putString("default_rate", Integer.toString(prefValue)); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("male")); |
|
|
|
assertThat(settings.getRate(), is(settingValue)); |
|
|
|
} |
|
|
|
|
|
|
|
public void testDefaultRate() |
|
|
|
{ |
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
defaultRateTest(300, 450, synth); // clamped to maximum value |
|
|
|
defaultRateTest(200, 350, synth); |
|
|
|
defaultRateTest(100, 175, synth); // default value |
|
|
|
defaultRateTest( 50, 87, synth); |
|
|
|
defaultRateTest( 25, 80, synth); // clamped to minimum value |
|
|
|
} |
|
|
|
|
|
|
|
// New Settings |
|
|
@@ -77,8 +118,34 @@ public class VoiceSettingsTest extends AndroidTestCase |
|
|
|
editor.putString("espeak_variant", "klatt2-old"); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
VoiceSettings settings = new VoiceSettings(prefs); |
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("klatt2-old")); |
|
|
|
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); |
|
|
|
} |
|
|
|
|
|
|
|
public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth) |
|
|
|
{ |
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
|
SharedPreferences.Editor editor = prefs.edit(); |
|
|
|
editor.clear(); |
|
|
|
editor.putString("espeak_rate", Integer.toString(prefValue)); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("male")); |
|
|
|
assertThat(settings.getRate(), is(settingValue)); |
|
|
|
} |
|
|
|
|
|
|
|
public void testEspeakRate() |
|
|
|
{ |
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
espeakRateTest(500, 450, synth); // clamped to maximum value |
|
|
|
espeakRateTest(400, 400, synth); |
|
|
|
espeakRateTest(200, 200, synth); |
|
|
|
espeakRateTest(175, 175, synth); // default value |
|
|
|
espeakRateTest(150, 150, synth); |
|
|
|
espeakRateTest( 70, 80, synth); // clamped to minimum value |
|
|
|
} |
|
|
|
|
|
|
|
// Mixed (Old and New) Settings |
|
|
@@ -92,7 +159,24 @@ public class VoiceSettingsTest extends AndroidTestCase |
|
|
|
editor.putString("espeak_variant", "klatt4"); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
VoiceSettings settings = new VoiceSettings(prefs); |
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("klatt4")); |
|
|
|
assertThat(settings.getRate(), is(synth.Rate.getDefaultValue())); |
|
|
|
} |
|
|
|
|
|
|
|
public void testEspeakRateWithDefaultRate() |
|
|
|
{ |
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); |
|
|
|
SharedPreferences.Editor editor = prefs.edit(); |
|
|
|
editor.clear(); |
|
|
|
editor.putString("default_rate", Integer.toString(50)); |
|
|
|
editor.putString("espeak_rate", Integer.toString(200)); |
|
|
|
editor.commit(); |
|
|
|
|
|
|
|
SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); |
|
|
|
VoiceSettings settings = new VoiceSettings(prefs, synth); |
|
|
|
assertThat(settings.getVoiceVariant().toString(), is("male")); |
|
|
|
assertThat(settings.getRate(), is(200)); |
|
|
|
} |
|
|
|
} |