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.

TextToSpeechTestCase.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 android.speech.tts.TextToSpeech;
  18. import android.speech.tts.TextToSpeech.OnInitListener;
  19. import android.test.AndroidTestCase;
  20. import android.util.Log;
  21. import java.util.Locale;
  22. import static org.hamcrest.MatcherAssert.assertThat;
  23. import static org.hamcrest.Matchers.*;
  24. public class TextToSpeechTestCase extends AndroidTestCase
  25. {
  26. private TextToSpeech mEngine = null;
  27. private boolean mInitialised = false;
  28. private int mStatus = TextToSpeech.ERROR;
  29. private OnInitListener mInitCallback = new OnInitListener()
  30. {
  31. @Override
  32. public void onInit(int status)
  33. {
  34. mStatus = status;
  35. mInitialised = true;
  36. }
  37. };
  38. @Override
  39. public void setUp() throws Exception
  40. {
  41. try
  42. {
  43. // Wait until the text-to-speech engine is initialised (max: 20 seconds):
  44. mEngine = new TextToSpeech(getContext(), mInitCallback);
  45. for (int count = 0; !mInitialised && count < (4 * 20); ++count)
  46. {
  47. Thread.sleep(250);
  48. }
  49. assertThat(mInitialised, is(true));
  50. assertThat(mStatus, is(TextToSpeech.SUCCESS));
  51. assertThat(mEngine.getDefaultEngine(), is("com.reecedunn.espeak"));
  52. // Ensure that the voice data is installed (max: 20 seconds):
  53. Locale en = new Locale("en");
  54. int available = mEngine.isLanguageAvailable(en);
  55. for (int count = 0; available != TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE && count < (4 * 20); ++count)
  56. {
  57. Thread.sleep(250);
  58. available = mEngine.isLanguageAvailable(en);
  59. Log.d("TextToSpeechTestCase", "setUp: available = " + available);
  60. }
  61. assertThat(available, is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
  62. }
  63. catch (Exception e)
  64. {
  65. tearDown();
  66. throw e;
  67. }
  68. }
  69. @Override
  70. public void tearDown()
  71. {
  72. if (mEngine != null)
  73. {
  74. mEngine.shutdown();
  75. mEngine = null;
  76. }
  77. }
  78. public TextToSpeech getEngine()
  79. {
  80. return mEngine;
  81. }
  82. }