/documentation/TextToSpeech_Plugin_Engine_Examples/eSpeakEngine/src/com/google/marvin/espeak/CheckVoiceData.java

http://eyes-free.googlecode.com/ · Java · 133 lines · 96 code · 15 blank · 22 comment · 8 complexity · d5fdf54c4d6cf2a988accf69c6621dd4 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 The Android Open Source Project
  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.google.marvin.espeak;
  17. import android.app.Activity;
  18. import android.content.Intent;
  19. import android.os.Bundle;
  20. import android.os.Environment;
  21. import android.speech.tts.TextToSpeech;
  22. import java.io.File;
  23. import java.util.ArrayList;
  24. /*
  25. * Checks if the voice data for the SVOX Pico Engine is present on the
  26. * sd card.
  27. */
  28. public class CheckVoiceData extends Activity {
  29. // The following constants are the same path constants as the ones defined
  30. // in external/svox/pico/tts/com_svox_picottsengine.cpp
  31. private final static String ESPEAK_DATA_PATH = Environment.getExternalStorageDirectory()
  32. + "/espeak-data/";
  33. private final static String[] baseDataFiles = {
  34. "af_dict", "config", "cs_dict", "cy_dict", "de_dict", "el_dict", "en_dict", "eo_dict",
  35. "es_dict", "fi_dict", "fr_dict", "grc_dict", "hbs_dict", "hi_dict", "hu_dict",
  36. "id_dict", "is_dict", "it_dict", "jbo_dict", "ku_dict", "la_dict", "mk_dict",
  37. "nl_dict", "no_dict", "phondata", "phonindex", "phontab", "pl_dict", "pt_dict",
  38. "ro_dict", "ru_dict", "sk_dict", "sv_dict", "sw_dict", "ta_dict", "tr_dict", "vi_dict",
  39. "zh_dict", "zhy_dict", "mbrola/dummyfile", "mbrola_ph/af1_phtrans",
  40. "mbrola_ph/ca1_phtrans", "mbrola_ph/cr1_phtrans", "mbrola_ph/cs_phtrans",
  41. "mbrola_ph/de2_phtrans", "mbrola_ph/de4_phtrans", "mbrola_ph/de6_phtrans",
  42. "mbrola_ph/en1_phtrans", "mbrola_ph/es_phtrans", "mbrola_ph/es4_phtrans",
  43. "mbrola_ph/fr1_phtrans", "mbrola_ph/gr2_phtrans", "mbrola_ph/grc-de6_phtrans",
  44. "mbrola_ph/hu1_phtrans", "mbrola_ph/id1_phtrans", "mbrola_ph/in1_phtrans",
  45. "mbrola_ph/it3_phtrans", "mbrola_ph/la1_phtrans", "mbrola_ph/nl_phtrans",
  46. "mbrola_ph/pl1_phtrans", "mbrola_ph/pt_phtrans", "mbrola_ph/ptbr_phtrans",
  47. "mbrola_ph/ptbr4_phtrans", "mbrola_ph/ro1_phtrans", "mbrola_ph/sv_phtrans",
  48. "mbrola_ph/sv2_phtrans", "mbrola_ph/us_phtrans", "mbrola_ph/us3_phtrans",
  49. "soundicons/dummyfile", "voices/af", "voices/bs", "voices/cs", "voices/cy",
  50. "voices/de", "voices/default", "voices/el", "voices/eo", "voices/es", "voices/es-la",
  51. "voices/fi", "voices/fr", "voices/fr-be", "voices/grc", "voices/hi", "voices/hr",
  52. "voices/hu", "voices/id", "voices/is", "voices/it", "voices/jbo", "voices/ku",
  53. "voices/la", "voices/mk", "voices/nl", "voices/no", "voices/pl", "voices/pt",
  54. "voices/pt-pt", "voices/ro", "voices/ru", "voices/sk", "voices/sr", "voices/sv",
  55. "voices/sw", "voices/ta", "voices/tr", "voices/vi", "voices/zh", "voices/zhy",
  56. "voices/!v/croak", "voices/!v/f1", "voices/!v/f2", "voices/!v/f3", "voices/!v/f4",
  57. "voices/!v/m1", "voices/!v/m2", "voices/!v/m3", "voices/!v/m4", "voices/!v/m5",
  58. "voices/!v/m6", "voices/!v/whisper", "voices/en/en", "voices/en/en-n",
  59. "voices/en/en-r", "voices/en/en-rp", "voices/en/en-sc", "voices/en/en-wi",
  60. "voices/en/en-wm", "voices/mb/mb-af1", "voices/mb/mb-af1-en", "voices/mb/mb-br1",
  61. "voices/mb/mb-br3", "voices/mb/mb-br4", "voices/mb/mb-cr1", "voices/mb/mb-cz2",
  62. "voices/mb/mb-de2", "voices/mb/mb-de4", "voices/mb/mb-de4-en", "voices/mb/mb-de5",
  63. "voices/mb/mb-de5-en", "voices/mb/mb-de6", "voices/mb/mb-de6-grc", "voices/mb/mb-de7",
  64. "voices/mb/mb-en1", "voices/mb/mb-es1", "voices/mb/mb-es2", "voices/mb/mb-fr1",
  65. "voices/mb/mb-fr1-en", "voices/mb/mb-fr4", "voices/mb/mb-fr4-en", "voices/mb/mb-gr2",
  66. "voices/mb/mb-gr2-en", "voices/mb/mb-hu1", "voices/mb/mb-hu1-en", "voices/mb/mb-id1",
  67. "voices/mb/mb-it3", "voices/mb/mb-it4", "voices/mb/mb-la1", "voices/mb/mb-nl2",
  68. "voices/mb/mb-nl2-en", "voices/mb/mb-pl1", "voices/mb/mb-pl1-en", "voices/mb/mb-ro1",
  69. "voices/mb/mb-ro1-en", "voices/mb/mb-sw1", "voices/mb/mb-sw1-en", "voices/mb/mb-sw2",
  70. "voices/mb/mb-sw2-en", "voices/mb/mb-us1", "voices/mb/mb-us2", "voices/mb/mb-us3"
  71. };
  72. private final static String[] supportedLanguages = {
  73. "afr", "bos", "zho", "hrv", "ces", "nld", "eng", "eng-USA", "eng-GBR", "epo", "fin",
  74. "fra", "deu", "ell", "hin", "hun", "isl", "ind", "ita", "kur", "lat", "mkd", "nor",
  75. "pol", "por", "ron", "rus", "srp", "slk", "spa", "spa-MEX", "swa", "swe", "tam", "tur",
  76. "vie", "cym"
  77. };
  78. @Override
  79. protected void onCreate(Bundle savedInstanceState) {
  80. super.onCreate(savedInstanceState);
  81. int result = TextToSpeech.Engine.CHECK_VOICE_DATA_PASS;
  82. Intent returnData = new Intent();
  83. returnData.putExtra(TextToSpeech.Engine.EXTRA_VOICE_DATA_ROOT_DIRECTORY, ESPEAK_DATA_PATH);
  84. returnData.putExtra(TextToSpeech.Engine.EXTRA_VOICE_DATA_FILES, baseDataFiles);
  85. returnData.putExtra(TextToSpeech.Engine.EXTRA_VOICE_DATA_FILES_INFO, baseDataFiles);
  86. ArrayList<String> available = new ArrayList<String>();
  87. ArrayList<String> unavailable = new ArrayList<String>();
  88. // TODO (clchen): Check each language INDIVIDUALLY
  89. boolean passedAllChecks = true;
  90. for (int i = 0; i < baseDataFiles.length; i++) {
  91. if (!fileExists(baseDataFiles[i])) {
  92. passedAllChecks = false;
  93. break;
  94. }
  95. }
  96. if (passedAllChecks) {
  97. for (int i = 0; i < supportedLanguages.length; i++) {
  98. available.add(supportedLanguages[i]);
  99. }
  100. } else {
  101. for (int i = 0; i < supportedLanguages.length; i++) {
  102. unavailable.add(supportedLanguages[i]);
  103. }
  104. }
  105. returnData.putStringArrayListExtra("availableVoices", available);
  106. returnData.putStringArrayListExtra("unavailableVoices", unavailable);
  107. setResult(result, returnData);
  108. finish();
  109. }
  110. private boolean fileExists(String filename) {
  111. File tempFile = new File(ESPEAK_DATA_PATH + filename);
  112. File tempFileSys = new File(ESPEAK_DATA_PATH + filename);
  113. if ((!tempFile.exists()) && (!tempFileSys.exists())) {
  114. return false;
  115. }
  116. return true;
  117. }
  118. }