PageRenderTime 40ms CodeModel.GetById 2ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 0ms

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

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