diff --git a/res/values/strings.xml b/res/values/strings.xml index 2fedceb8ea7..9e28761a6d5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1737,6 +1737,14 @@ found in the list of installed applications. Language Sets the language-specific voice for the spoken text + + Listen to an example + + Play a short demonstration of speech synthesis + + This is an example of speech synthesis. + + Your settings have changed. This is an example of how they sound. Power Control diff --git a/res/xml/tts_settings.xml b/res/xml/tts_settings.xml index 991c1f106dd..5a7aaa2205e 100644 --- a/res/xml/tts_settings.xml +++ b/res/xml/tts_settings.xml @@ -17,6 +17,12 @@ + + resolveInfos = pm.queryIntentActivities(intent, 0); + // query only the package that matches that of the default engine + for (int i = 0; i < resolveInfos.size(); i++) { + ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo; + if (mDefaultEng.equals(currentActivityInfo.packageName)) { + intent.setClassName(mDefaultEng, currentActivityInfo.name); + this.startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK); + } + } + } + + + /** + * Called when the TTS engine is initialized. + */ + public void onInit(int status) { + if (status == TextToSpeech.TTS_SUCCESS) { + Log.v(TAG, "TTS engine for settings screen initialized."); + mEnableDemo = true; + } else { + Log.v(TAG, "TTS engine for settings screen failed to initialize successfully."); + mEnableDemo = false; + } + mPlayExample.setEnabled(mEnableDemo); + } + + + /** + * Called when voice data integrity check returns + */ + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == VOICE_DATA_INTEGRITY_CHECK) { + if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { + Log.v(TAG, "Voice data check passed"); + if (mTts == null) { + mTts = new TextToSpeech(this, this); + } + } else { + Log.v(TAG, "Voice data check failed"); + + } + } + } + + public boolean onPreferenceChange(Preference preference, Object objValue) { if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) { // "Use Defaults" @@ -131,7 +228,7 @@ public class TextToSpeechSettings extends PreferenceActivity implements } catch (NumberFormatException e) { Log.e(TAG, "could not persist default TTS pitch setting", e); } - }else if (KEY_TTS_DEFAULT_LANG.equals(preference.getKey())) { + } else if (KEY_TTS_DEFAULT_LANG.equals(preference.getKey())) { // Default language String value = (String) objValue; Settings.Secure.putString(getContentResolver(), @@ -142,4 +239,16 @@ public class TextToSpeechSettings extends PreferenceActivity implements return true; } + + public boolean onPreferenceClick(Preference preference) { + if (preference == mPlayExample) { + if (mTts != null) { + mTts.speak(getResources().getString(R.string.tts_demo), + TextToSpeech.TTS_QUEUE_FLUSH, null); + } + return true; + } + return false; + } + }