eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VoiceSettingsTest.java 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2013 Reece H. Dunn
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.reecedunn.espeak.test;
  17. import android.content.SharedPreferences;
  18. import android.preference.PreferenceManager;
  19. import android.test.AndroidTestCase;
  20. import com.reecedunn.espeak.SpeechSynthesis;
  21. import com.reecedunn.espeak.VoiceSettings;
  22. import static org.hamcrest.MatcherAssert.assertThat;
  23. import static org.hamcrest.Matchers.*;
  24. public class VoiceSettingsTest extends AndroidTestCase
  25. {
  26. // No Settings (New Install)
  27. public void testNoPreferences()
  28. {
  29. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  30. SharedPreferences.Editor editor = prefs.edit();
  31. editor.clear();
  32. editor.commit();
  33. VoiceSettings settings = new VoiceSettings(prefs);
  34. assertThat(settings.getVoiceVariant().toString(), is("male"));
  35. }
  36. // Old Settings
  37. public void testDefaultGenderMale()
  38. {
  39. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  40. SharedPreferences.Editor editor = prefs.edit();
  41. editor.clear();
  42. editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_MALE));
  43. editor.commit();
  44. VoiceSettings settings = new VoiceSettings(prefs);
  45. assertThat(settings.getVoiceVariant().toString(), is("male"));
  46. }
  47. public void testDefaultGenderFemale()
  48. {
  49. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  50. SharedPreferences.Editor editor = prefs.edit();
  51. editor.clear();
  52. editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_FEMALE));
  53. editor.commit();
  54. VoiceSettings settings = new VoiceSettings(prefs);
  55. assertThat(settings.getVoiceVariant().toString(), is("female"));
  56. }
  57. // New Settings
  58. public void testEspeakVariant()
  59. {
  60. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  61. SharedPreferences.Editor editor = prefs.edit();
  62. editor.clear();
  63. editor.putString("espeak_variant", "klatt2-old");
  64. editor.commit();
  65. VoiceSettings settings = new VoiceSettings(prefs);
  66. assertThat(settings.getVoiceVariant().toString(), is("klatt2-old"));
  67. }
  68. // Mixed (Old and New) Settings
  69. public void testEspeakVariantWithDefaultGenderFemale()
  70. {
  71. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  72. SharedPreferences.Editor editor = prefs.edit();
  73. editor.clear();
  74. editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_FEMALE));
  75. editor.putString("espeak_variant", "klatt4");
  76. editor.commit();
  77. VoiceSettings settings = new VoiceSettings(prefs);
  78. assertThat(settings.getVoiceVariant().toString(), is("klatt4"));
  79. }
  80. }