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.

TtsMatcher.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2014 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 org.hamcrest.Description;
  18. import org.hamcrest.Matcher;
  19. import org.hamcrest.TypeSafeMatcher;
  20. import android.speech.tts.TextToSpeech;
  21. public class TtsMatcher
  22. {
  23. private static String ttsLangCode(final Integer value) {
  24. if (value == null) return "null";
  25. switch (value.intValue()) {
  26. case TextToSpeech.LANG_AVAILABLE: return "TextToSpeech.LANG_AVAILABLE";
  27. case TextToSpeech.LANG_COUNTRY_AVAILABLE: return "TextToSpeech.LANG_COUNTRY_AVAILABLE";
  28. case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE: return "TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE";
  29. case TextToSpeech.LANG_MISSING_DATA: return "TextToSpeech.LANG_MISSING_DATA";
  30. case TextToSpeech.LANG_NOT_SUPPORTED: return "TextToSpeech.LANG_NOT_SUPPORTED";
  31. }
  32. return value.toString();
  33. }
  34. public static Matcher<Integer> isTtsLangCode(final Integer value) {
  35. return new TypeSafeMatcher<Integer>() {
  36. @Override
  37. protected boolean matchesSafely(Integer item) {
  38. return item.equals(value);
  39. }
  40. @Override
  41. public void describeTo(Description description) {
  42. description.appendText("expected constant: ");
  43. description.appendValue(ttsLangCode(value));
  44. }
  45. @Override
  46. public void describeMismatchSafely(final Integer item, final Description description) {
  47. description.appendText("was ");
  48. description.appendValue(ttsLangCode(item));
  49. }
  50. };
  51. }
  52. }