From 74e565d85d13782b2a75647b3fd952a2324ca581 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 18 Jun 2009 18:44:52 -0700 Subject: [PATCH] Update the Text-To-Speech settings screen to allow listening to a TTS example after checking that the data required by the TTS engine is properly installed. Removed use of local constants for the the default TTS values, use the values defined in TextToSpeech.Engine instead. --- res/values/strings.xml | 8 + res/xml/tts_settings.xml | 6 + .../settings/TextToSpeechSettings.java | 147 +++++++++++++++--- 3 files changed, 142 insertions(+), 19 deletions(-) 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; + } + }