PageRenderTime 27ms CodeModel.GetById 10ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

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