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.

TextToSpeechTest.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2012-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 java.util.Locale;
  18. import android.speech.tts.TextToSpeech;
  19. import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode;
  20. import static org.hamcrest.MatcherAssert.assertThat;
  21. import static org.hamcrest.Matchers.*;
  22. public class TextToSpeechTest extends TextToSpeechTestCase
  23. {
  24. public void testUnsupportedLanguage()
  25. {
  26. assertThat(getEngine(), is(notNullValue()));
  27. Locale initialLocale = getLanguage(getEngine());
  28. assertThat(getEngine().isLanguageAvailable(new Locale("cel")), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
  29. assertThat(getLanguage(getEngine()).getLanguage(), is(initialLocale.getLanguage()));
  30. assertThat(getLanguage(getEngine()).getCountry(), is(initialLocale.getCountry()));
  31. assertThat(getLanguage(getEngine()).getVariant(), is(initialLocale.getVariant()));
  32. }
  33. public void testLanguages()
  34. {
  35. assertThat(getEngine(), is(notNullValue()));
  36. for (VoiceData.Voice data : VoiceData.voices)
  37. {
  38. String context = null;
  39. try
  40. {
  41. // Skip the voice if the language code is not supported by Android:
  42. if (data.javaLanguage.equals("")) continue;
  43. final Locale iana1 = new Locale(data.ianaLanguage, data.ianaCountry, data.variant);
  44. final Locale iana2 = new Locale(data.ianaLanguage, data.ianaCountry, "test");
  45. final Locale iana3 = new Locale(data.ianaLanguage, "VU", data.variant);
  46. final Locale java1 = new Locale(data.javaLanguage, data.javaCountry, data.variant);
  47. final Locale java2 = new Locale(data.javaLanguage, data.javaCountry, "test");
  48. final Locale java3 = new Locale(data.javaLanguage, "VUT", data.variant);
  49. context = "iana1";
  50. assertThat(getEngine().isLanguageAvailable(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
  51. assertThat(getEngine().setLanguage(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
  52. assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
  53. assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
  54. assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));
  55. context = "iana2";
  56. assertThat(getEngine().isLanguageAvailable(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
  57. assertThat(getEngine().setLanguage(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
  58. assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
  59. assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
  60. assertThat(getLanguage(getEngine()).getVariant(), is(""));
  61. context = "iana3";
  62. assertThat(getEngine().isLanguageAvailable(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
  63. assertThat(getEngine().setLanguage(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
  64. assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
  65. assertThat(getLanguage(getEngine()).getCountry(), is(""));
  66. assertThat(getLanguage(getEngine()).getVariant(), is(""));
  67. context = "java1";
  68. assertThat(getEngine().isLanguageAvailable(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
  69. assertThat(getEngine().setLanguage(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
  70. assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
  71. assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
  72. assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));
  73. context = "java2";
  74. assertThat(getEngine().isLanguageAvailable(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
  75. assertThat(getEngine().setLanguage(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
  76. assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
  77. assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
  78. assertThat(getLanguage(getEngine()).getVariant(), is(""));
  79. context = "java3";
  80. assertThat(getEngine().isLanguageAvailable(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
  81. assertThat(getEngine().setLanguage(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
  82. assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
  83. assertThat(getLanguage(getEngine()).getCountry(), is(""));
  84. assertThat(getLanguage(getEngine()).getVariant(), is(""));
  85. }
  86. catch (AssertionError e)
  87. {
  88. throw new VoiceData.Exception(data, context, e);
  89. }
  90. }
  91. }
  92. }