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.

Voice.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2012-2013 Reece H. Dunn
  3. * Copyright (C) 2011 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.reecedunn.espeak;
  18. import java.util.Locale;
  19. import java.util.MissingResourceException;
  20. import android.speech.tts.TextToSpeech;
  21. public class Voice {
  22. public final String name;
  23. public final String identifier;
  24. public final int gender;
  25. public final int age;
  26. public final Locale locale;
  27. public Voice(String name, String identifier, int gender, int age, Locale locale) {
  28. this.name = name;
  29. this.identifier = identifier;
  30. this.gender = gender;
  31. this.age = age;
  32. this.locale = locale;
  33. }
  34. /**
  35. * Attempts a partial match against a query locale.
  36. *
  37. * @param query The locale to match.
  38. * @return A text-to-speech availability code. One of:
  39. * <ul>
  40. * <li>{@link TextToSpeech#LANG_NOT_SUPPORTED}
  41. * <li>{@link TextToSpeech#LANG_AVAILABLE}
  42. * <li>{@link TextToSpeech#LANG_COUNTRY_AVAILABLE}
  43. * <li>{@link TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE}
  44. * </ul>
  45. */
  46. public int match(Locale query) {
  47. if (!locale.getISO3Language().equals(query.getISO3Language())) {
  48. return TextToSpeech.LANG_NOT_SUPPORTED;
  49. }
  50. try {
  51. if (!locale.getISO3Country().equals(query.getISO3Country())) {
  52. return TextToSpeech.LANG_AVAILABLE;
  53. }
  54. } catch (MissingResourceException e) {
  55. return TextToSpeech.LANG_AVAILABLE;
  56. }
  57. if (!locale.getVariant().equals(query.getVariant())) {
  58. return TextToSpeech.LANG_COUNTRY_AVAILABLE;
  59. }
  60. return TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE;
  61. }
  62. @Override
  63. public String toString() {
  64. String ret = locale.getISO3Language();
  65. if (locale.getISO3Country() != null && !locale.getISO3Country().isEmpty()) {
  66. ret += '-';
  67. ret += locale.getISO3Country();
  68. }
  69. if (locale.getVariant() != null && !locale.getVariant().isEmpty()) {
  70. ret += '-';
  71. ret += locale.getVariant();
  72. }
  73. return ret;
  74. }
  75. }