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 17 package com.svox.pico; 18 19 import java.io.File; 20 21 import android.app.Activity; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.os.Environment; 25 import android.speech.tts.TextToSpeech; 26 27 import java.util.ArrayList; 28 import java.util.HashMap; 29 30 /* 31 * Checks if the voice data for the SVOX Pico Engine is present on the 32 * sd card. 33 */ 34 public 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 PICO_LINGWARE_PATH = 39 Environment.getExternalStorageDirectory() + "/svox/"; 40 private final static String PICO_SYSTEM_LINGWARE_PATH = "/system/tts/lang_pico/"; 41 42 private final static String[] dataFiles = { 43 "de-DE_gl0_sg.bin", "de-DE_ta.bin", "en-GB_kh0_sg.bin", "en-GB_ta.bin", 44 "en-US_lh0_sg.bin", "en-US_ta.bin", "es-ES_ta.bin", "es-ES_zl0_sg.bin", 45 "fr-FR_nk0_sg.bin", "fr-FR_ta.bin", "it-IT_cm0_sg.bin", "it-IT_ta.bin" 46 }; 47 48 private final static String[] dataFilesInfo = { 49 "deu-DEU", "deu-DEU", "eng-GBR", "eng-GBR", "eng-USA", "eng-USA", 50 "spa-ESP", "spa-ESP", "fra-FRA", "fra-FRA", "ita-ITA", "ita-ITA" 51 }; 52 53 private final static String[] supportedLanguages = { 54 "deu-DEU", "eng-GBR", "eng-USA", "spa-ESP", "fra-FRA", "ita-ITA" 55 }; 56 57 @Override onCreate(Bundle savedInstanceState)58 protected void onCreate(Bundle savedInstanceState) { 59 super.onCreate(savedInstanceState); 60 61 int result = TextToSpeech.Engine.CHECK_VOICE_DATA_PASS; 62 boolean foundMatch = false; 63 64 ArrayList<String> available = new ArrayList<String>(); 65 ArrayList<String> unavailable = new ArrayList<String>(); 66 67 HashMap<String, Boolean> languageCountry = new HashMap<String, Boolean>(); 68 69 Bundle bundle = getIntent().getExtras(); 70 if (bundle != null){ 71 ArrayList<String> langCountryVars = bundle.getStringArrayList( 72 TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR); 73 if (langCountryVars != null){ 74 for (int i = 0; i < langCountryVars.size(); i++){ 75 if (langCountryVars.get(i).length() > 0){ 76 languageCountry.put(langCountryVars.get(i), true); 77 } 78 } 79 } 80 } 81 82 // Check for files 83 for (int i = 0; i < supportedLanguages.length; i++){ 84 if ((languageCountry.size() < 1) || 85 (languageCountry.containsKey(supportedLanguages[i]))){ 86 if (!fileExists(dataFiles[2 * i]) || 87 !fileExists(dataFiles[(2 * i) + 1])){ 88 result = TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_DATA; 89 unavailable.add(supportedLanguages[i]); 90 } else { 91 available.add(supportedLanguages[i]); 92 foundMatch = true; 93 } 94 } 95 } 96 97 if ((languageCountry.size() > 0) && !foundMatch){ 98 result = TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL; 99 } 100 101 // Put the root directory for the sd card data + the data filenames 102 Intent returnData = new Intent(); 103 returnData.putExtra(TextToSpeech.Engine.EXTRA_VOICE_DATA_ROOT_DIRECTORY, PICO_LINGWARE_PATH); 104 returnData.putExtra(TextToSpeech.Engine.EXTRA_VOICE_DATA_FILES, dataFiles); 105 returnData.putExtra(TextToSpeech.Engine.EXTRA_VOICE_DATA_FILES_INFO, dataFilesInfo); 106 107 returnData.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES, available); 108 returnData.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES, unavailable); 109 setResult(result, returnData); 110 finish(); 111 } 112 fileExists(String filename)113 private boolean fileExists(String filename){ 114 File tempFile = new File(PICO_LINGWARE_PATH + filename); 115 File tempFileSys = new File(PICO_SYSTEM_LINGWARE_PATH + filename); 116 if ((!tempFile.exists()) && (!tempFileSys.exists())) { 117 return false; 118 } 119 return true; 120 } 121 122 } 123